1 | <?php |
||
21 | class Executor |
||
22 | { |
||
23 | protected $controller; |
||
24 | protected $method; |
||
25 | protected $parameters = []; |
||
26 | protected $preDispatch; |
||
27 | protected $postDispatch; |
||
28 | |||
29 | public function __construct(RoutingResult $result = null) |
||
44 | |||
45 | /** |
||
46 | * Sets controller to be fired. |
||
47 | * It can be object or name of class. |
||
48 | * |
||
49 | * @param object|string $controller |
||
50 | * @return Executor |
||
51 | */ |
||
52 | public function setController($controller) |
||
62 | |||
63 | /** |
||
64 | * Returns controller object |
||
65 | * |
||
66 | * @return object |
||
67 | */ |
||
68 | public function getController() |
||
72 | |||
73 | /** |
||
74 | * Sets method to be fired |
||
75 | * |
||
76 | * @param string $method |
||
77 | * @return Executor |
||
78 | */ |
||
79 | public function setMethod($method) |
||
84 | |||
85 | /** |
||
86 | * Sets parameters to be passed to controller |
||
87 | * |
||
88 | * @param array $parameters |
||
89 | * @return Executor |
||
90 | */ |
||
91 | public function setParameters(array $parameters) |
||
96 | |||
97 | /** |
||
98 | * Sets callable to be called before firing controller |
||
99 | * |
||
100 | * @param callable $func |
||
101 | * @return Executor |
||
102 | */ |
||
103 | public function setPreDispatch(callable $func) |
||
108 | |||
109 | /** |
||
110 | * Sets callable to be called after firing controller |
||
111 | * |
||
112 | * @param callable $func |
||
113 | * @return Executor |
||
114 | */ |
||
115 | public function setPostDispatch(callable $func) |
||
120 | |||
121 | /** |
||
122 | * Calls hook if it's callable |
||
123 | * |
||
124 | * @param callable|null $hook Hook to be fired |
||
125 | */ |
||
126 | protected function runHook($hook) |
||
137 | |||
138 | /** |
||
139 | * Runs: |
||
140 | * - preDispatch (if set) |
||
141 | * - method in controller |
||
142 | * - postDispatch (if set) |
||
143 | * |
||
144 | * @return mixed Value returned by controller's method |
||
145 | */ |
||
146 | public function fire() |
||
164 | } |
||
165 |