1 | <?php |
||
18 | abstract class AbstractMiddleware implements MiddlewareInterface |
||
19 | { |
||
20 | /** |
||
21 | * @var MiddlewareInterface |
||
22 | */ |
||
23 | private $nextMiddleware; |
||
24 | |||
25 | /** |
||
26 | * @var bool |
||
27 | */ |
||
28 | private $wasExecuted = false; |
||
29 | |||
30 | /** |
||
31 | * @param MiddlewareInterface $nextMiddleware |
||
32 | */ |
||
33 | final public function __construct(MiddlewareInterface $nextMiddleware) |
||
37 | |||
38 | /** |
||
39 | * @todo |
||
40 | */ |
||
41 | final protected function initialize() |
||
45 | |||
46 | /** |
||
47 | * Executes the life-workflow of the middleware: first it is initialized, |
||
48 | * then processed, and at the end the next middleware is executed if it was |
||
49 | * not done previously. |
||
50 | */ |
||
51 | final public function execute() |
||
65 | |||
66 | /** |
||
67 | * Wrapper used by this abstract class to give more flexibility to the |
||
68 | * function `execute`. |
||
69 | * |
||
70 | * Implement it in own child classes to execute the main logic of the |
||
71 | * middleware. |
||
72 | * |
||
73 | * @return void |
||
74 | */ |
||
75 | abstract protected function process(); |
||
76 | |||
77 | /** |
||
78 | * @return MiddlewareInterface |
||
79 | */ |
||
80 | final public function getNextMiddleware() |
||
84 | |||
85 | /** |
||
86 | * @return bool |
||
87 | */ |
||
88 | final public function wasExecuted() |
||
92 | } |
||
93 | |||
94 |