1 | <?php |
||
18 | abstract class AbstractHandler implements DiProviderInterface |
||
19 | { |
||
20 | /** An array of handler-specific options */ |
||
21 | protected $options; |
||
22 | |||
23 | /** A sorted array of handler plugins */ |
||
24 | private $plugins; |
||
25 | |||
26 | /** The service provider to use */ |
||
27 | private $serviceProvider; |
||
28 | |||
29 | /** |
||
30 | * Constructor for the class. |
||
31 | * @param array $options An array of options for the plugin. |
||
32 | */ |
||
33 | 52 | public function __construct($options) |
|
54 | |||
55 | /** |
||
56 | * Performs the actual routing. |
||
57 | * @return mixed Returns the result of the route. |
||
58 | */ |
||
59 | abstract public function performRoute(); |
||
60 | |||
61 | /** |
||
62 | * Retrieve an element from the DI container. |
||
63 | * @param string $key The DI key. |
||
64 | * @param boolean $useCache (optional) An optional indicating whether we |
||
65 | * should use the cached version of the element (true by default). |
||
66 | * @return mixed Returns the DI element mapped to that key. |
||
67 | */ |
||
68 | 1 | public function get($key, $useCache = true) |
|
72 | |||
73 | /** |
||
74 | * Sets an element in the DI container for the specified key. |
||
75 | * @param string $key The DI key. |
||
76 | * @param mixed $element The DI element to store. |
||
77 | * @return Di Returns the Di instance. |
||
78 | */ |
||
79 | 1 | public function set($key, $element) |
|
83 | |||
84 | /** |
||
85 | * Returns the active service provider for this handler. |
||
86 | * @return ServiceProvider The active service provider for this handler. |
||
87 | */ |
||
88 | 20 | public function getServiceProvider() |
|
92 | |||
93 | /** |
||
94 | * Returns the array of plugins registered with this handler. |
||
95 | */ |
||
96 | 17 | public function getPlugins() |
|
100 | |||
101 | /** |
||
102 | * Sets the current list of plugins. |
||
103 | * @param array $plugins The array of plugins. |
||
104 | * @return AbstractHandler Returns $this. |
||
105 | */ |
||
106 | 8 | public function setPlugins($plugins) |
|
128 | |||
129 | // sorts the list of plugins according to their execution order |
||
130 | private function sortPlugins($plugins) |
||
137 | |||
138 | /** |
||
139 | * Invokes the plugin hook against all the listed plugins. |
||
140 | * @param string $hook The hook to invoke. |
||
141 | * @param array $args The arguments to pass to the call. |
||
142 | */ |
||
143 | 17 | public function invokePluginsHook($hook, $args) |
|
151 | |||
152 | /** |
||
153 | * Returns whether a handler should function in a CLI environment. |
||
154 | * @return bool Returns true if the handler should function in a CLI |
||
155 | * environment and false otherwise. |
||
156 | */ |
||
157 | abstract public function isCliHandler(); |
||
158 | |||
159 | /** |
||
160 | * Returns the active response encoder. |
||
161 | * @return EncoderInterface Returns the response encoder. |
||
162 | */ |
||
163 | 1 | public function getEncoder() |
|
167 | |||
168 | /** |
||
169 | * Provides the handler with an opportunity to perform any last minute |
||
170 | * error handling logic. The returned value will be serialized by the |
||
171 | * handler's encoder. |
||
172 | * @param Exception $e The exception that was thrown. |
||
173 | * @return Returns a serializable value that will be encoded and returned |
||
174 | * to the client. |
||
175 | */ |
||
176 | 2 | public function handleException(Exception $e) |
|
180 | |||
181 | /** |
||
182 | * Returns the array of options. |
||
183 | * @return array $options The array of options. |
||
184 | */ |
||
185 | 35 | public function getOptions() |
|
189 | } |
||
190 |