17
17
final class MiddlewareFactory implements MiddlewareFactoryInterface
18
18
{
19
19
public const separator = '@ ' ;
20
+
21
+ private ContainerInterface $ container ;
22
+ private ResponseFactoryInterface $ responseFactory ;
23
+ private ?PipelineFactoryInterface $ pipelineFactory ;
24
+
20
25
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
24
29
) {
30
+ $ this ->container = $ container ;
31
+ $ this ->$ responseFactory = $ responseFactory ;
32
+ $ this ->pipelineFactory = $ pipelineFactory ?? new PipelineFactory ;
25
33
}
26
34
27
35
/**
@@ -36,7 +44,7 @@ public static function fromContainer(ContainerInterface $container): self
36
44
$ container , $ container ->get (ResponseFactoryInterface::class),
37
45
$ container ->has (PipelineFactoryInterface::class) ?
38
46
$ container ->get (PipelineFactoryInterface::class)
39
- : new PipelineFactory ()
47
+ : new PipelineFactory
40
48
);
41
49
}
42
50
@@ -62,13 +70,13 @@ public function make($any): MiddlewareInterface
62
70
return new Decorator \RequestHandlerDecorator ($ this ->container ->get ($ any ));
63
71
}
64
72
65
- if (str_contains ($ any , self ::separator)) {
73
+ if (\strpos ($ any , self ::separator) !== false ) {
66
74
list ($ serviceID , $ method ) = explode (self ::separator, $ any , 2 );
67
75
if ($ this ->container ->has ($ serviceID )) {
68
76
if (!method_exists ($ service = $ this ->getService ($ serviceID ), $ method )) {
69
77
goto end;
70
78
}
71
- $ any = [$ this -> getService ( $ serviceID ) , $ method ];
79
+ $ any = [$ service , $ method ];
72
80
goto callback;
73
81
}
74
82
}
@@ -101,7 +109,7 @@ public function make($any): MiddlewareInterface
101
109
} elseif (is_array ($ any )) {
102
110
callback:
103
111
$ method = new ReflectionMethod ($ any [0 ], $ any [1 ]);
104
- } elseif (str_contains ($ any , ':: ' ) !== false ) {
112
+ } elseif (\strpos ($ any , ':: ' ) !== false ) {
105
113
$ method = new ReflectionMethod ($ any );
106
114
} else {
107
115
str_callback:
0 commit comments