Skip to content

Commit 1a64ae7

Browse files
authored
Update MiddlewareFactory.php
1 parent 4af3876 commit 1a64ae7

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/MiddlewareFactory.php

+15-7
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,19 @@
1717
final class MiddlewareFactory implements MiddlewareFactoryInterface
1818
{
1919
public const separator = '@';
20+
21+
private ContainerInterface $container;
22+
private ResponseFactoryInterface $responseFactory;
23+
private ?PipelineFactoryInterface $pipelineFactory;
24+
2025
public function __construct(
21-
private ContainerInterface $container,
22-
private ResponseFactoryInterface $responseFactory,
23-
private ?PipelineFactoryInterface $pipelineFactory = new PipelineFactory
26+
ContainerInterface $container,
27+
ResponseFactoryInterface $responseFactory,
28+
PipelineFactoryInterface $pipelineFactory = null
2429
) {
30+
$this->container = $container;
31+
$this->$responseFactory = $responseFactory;
32+
$this->pipelineFactory = $pipelineFactory ?? new PipelineFactory;
2533
}
2634

2735
/**
@@ -36,7 +44,7 @@ public static function fromContainer(ContainerInterface $container): self
3644
$container, $container->get(ResponseFactoryInterface::class),
3745
$container->has(PipelineFactoryInterface::class) ?
3846
$container->get(PipelineFactoryInterface::class)
39-
: new PipelineFactory()
47+
: new PipelineFactory
4048
);
4149
}
4250

@@ -62,13 +70,13 @@ public function make($any): MiddlewareInterface
6270
return new Decorator\RequestHandlerDecorator($this->container->get($any));
6371
}
6472

65-
if (str_contains($any, self::separator)) {
73+
if (\strpos($any, self::separator) !== false) {
6674
list($serviceID, $method) = explode(self::separator, $any, 2);
6775
if ($this->container->has($serviceID)) {
6876
if (!method_exists($service = $this->getService($serviceID), $method)) {
6977
goto end;
7078
}
71-
$any = [$this->getService($serviceID), $method];
79+
$any = [$service, $method];
7280
goto callback;
7381
}
7482
}
@@ -101,7 +109,7 @@ public function make($any): MiddlewareInterface
101109
} elseif (is_array($any)) {
102110
callback:
103111
$method = new ReflectionMethod($any[0], $any[1]);
104-
} elseif (str_contains($any, '::') !== false) {
112+
} elseif (\strpos($any, '::') !== false) {
105113
$method = new ReflectionMethod($any);
106114
} else {
107115
str_callback:

0 commit comments

Comments
 (0)