1 | <?php |
||
19 | class Middleware |
||
20 | { |
||
21 | |||
22 | protected static $excMsg = ' is not a valid onion layer.'; |
||
23 | protected $layers; |
||
24 | |||
25 | /** |
||
26 | * instanciate |
||
27 | * |
||
28 | * @param array $layers |
||
29 | */ |
||
30 | 7 | public function __construct(array $layers = []) |
|
34 | |||
35 | /** |
||
36 | * Add layer(s) or Middleware |
||
37 | * |
||
38 | * @param mixed $layers |
||
39 | * @return Middleware |
||
40 | */ |
||
41 | 2 | public function layer($layers) |
|
56 | |||
57 | /** |
||
58 | * Run middleware around core function and pass an |
||
59 | * object through it |
||
60 | * |
||
61 | * @param Container $container |
||
62 | * @param Closure $core |
||
63 | * @return mixed |
||
64 | */ |
||
65 | 1 | public function peel(Container $container, Closure $core) |
|
76 | |||
77 | /** |
||
78 | * Get the layers of this onion, |
||
79 | * can be used to merge with another onion |
||
80 | * |
||
81 | * @return array |
||
82 | */ |
||
83 | 2 | public function toArray(): array |
|
87 | |||
88 | /** |
||
89 | * The inner function of the onion. |
||
90 | * this will be wrapped on layers |
||
91 | * |
||
92 | * @param Closure $core the core function |
||
93 | * @return Closure |
||
94 | */ |
||
95 | 1 | protected function createCoreFunction(Closure $core): Closure |
|
101 | |||
102 | /** |
||
103 | * Get an onion layer function. |
||
104 | * we get the object from a previous layer and pass it inwards |
||
105 | * |
||
106 | * @param Closure $nextLayer |
||
107 | * @param MiddlewareInterface $layer |
||
108 | * @return Closure |
||
109 | */ |
||
110 | 1 | protected function createLayer(Closure $nextLayer, MiddlewareInterface $layer): Closure |
|
116 | } |
||
117 |