1 | <?php |
||
22 | class MiddlewareInvoker |
||
23 | { |
||
24 | /** |
||
25 | * @var array |
||
26 | */ |
||
27 | private $excepts = array(); |
||
28 | |||
29 | /** |
||
30 | * @var array |
||
31 | */ |
||
32 | private $only = array(); |
||
33 | |||
34 | /** |
||
35 | * @var MiddlewareInterface |
||
36 | */ |
||
37 | private $middleware; |
||
38 | |||
39 | /** |
||
40 | * Constructor. |
||
41 | * |
||
42 | * @param MiddlewareInterface $middleware |
||
43 | */ |
||
44 | public function __construct(MiddlewareInterface $middleware) |
||
48 | |||
49 | /** |
||
50 | * Do not invoke middleware for specified actions. |
||
51 | * |
||
52 | * @param array $actions |
||
53 | * |
||
54 | * @return $this |
||
55 | */ |
||
56 | public function except(array $actions) |
||
64 | |||
65 | /** |
||
66 | * Invoke middleware only for specified actions. |
||
67 | * |
||
68 | * @param array $actions |
||
69 | * |
||
70 | * @return $this |
||
71 | */ |
||
72 | public function only(array $actions) |
||
80 | |||
81 | /** |
||
82 | * Invoke middleware. |
||
83 | * |
||
84 | * @param Request $request |
||
85 | * @param RequestContext $context |
||
86 | * @param Closure $next |
||
87 | * @param string|null $action |
||
88 | * |
||
89 | * @return Response|null |
||
90 | */ |
||
91 | public function __invoke(Request $request, RequestContext $context, Closure $next, $action = null) |
||
105 | |||
106 | /** |
||
107 | * Check if action in exception. |
||
108 | * |
||
109 | * @param string|null $action |
||
110 | * |
||
111 | * @return bool |
||
112 | */ |
||
113 | private function isExcept($action) |
||
117 | |||
118 | /** |
||
119 | * Check if action in not only execute. |
||
120 | * |
||
121 | * @param string $action |
||
122 | * |
||
123 | * @return bool |
||
124 | */ |
||
125 | private function isNotOnly($action) |
||
129 | } |
||
130 |