1 | <?php |
||
12 | class App { |
||
|
|||
13 | |||
14 | /** |
||
15 | * controller |
||
16 | * @var mixed |
||
17 | */ |
||
18 | private $controller = null; |
||
19 | |||
20 | /** |
||
21 | * action method |
||
22 | * @var string |
||
23 | */ |
||
24 | private $method = null; |
||
25 | |||
26 | /** |
||
27 | * passed arguments |
||
28 | * @var array |
||
29 | */ |
||
30 | private $args = array(); |
||
31 | |||
32 | /** |
||
33 | * request |
||
34 | * @var Request |
||
35 | */ |
||
36 | public $request = null; |
||
37 | |||
38 | /** |
||
39 | * response |
||
40 | * @var Response |
||
41 | */ |
||
42 | public $response = null; |
||
43 | |||
44 | /** |
||
45 | * application constructor |
||
46 | * |
||
47 | * @access public |
||
48 | */ |
||
49 | public function __construct(){ |
||
56 | |||
57 | public function run(){ |
||
102 | |||
103 | /** |
||
104 | * instantiate controller object and trigger it's action method |
||
105 | * |
||
106 | * @param string $controller |
||
107 | * @param string $method |
||
108 | * @param array $args |
||
109 | * @return Response |
||
110 | */ |
||
111 | private function invoke($controller, $method = "index", $args = []){ |
||
133 | |||
134 | /** |
||
135 | * detect if controller is valid |
||
136 | * |
||
137 | * any request to error controller will be considered as invalid, |
||
138 | * because error pages will be rendered(even with ajax) from inside the application |
||
139 | * |
||
140 | * @param string $controller |
||
141 | * @return boolean |
||
142 | */ |
||
143 | private static function isControllerValid($controller){ |
||
155 | |||
156 | /** |
||
157 | * detect if action method is valid |
||
158 | * |
||
159 | * make a request to 'index' method will be considered as invalid, |
||
160 | * the constructor will take care of index methods. |
||
161 | * |
||
162 | * @param string $controller |
||
163 | * @param string $method |
||
164 | * @return boolean |
||
165 | */ |
||
166 | private static function isMethodValid($controller, $method){ |
||
178 | |||
179 | /** |
||
180 | * detect if arguments are valid(number and alphanumeric) |
||
181 | * |
||
182 | * You can enhance, or modify this method, or don't use it at all. |
||
183 | * |
||
184 | * @param string $controller |
||
185 | * @param string $method |
||
186 | * @param array $args |
||
187 | * @return boolean |
||
188 | * @see http://stackoverflow.com/questions/346777/how-to-dynamically-check-number-of-arguments-of-a-function-in-php?lq=1 |
||
189 | */ |
||
190 | private static function areArgsValid($controller, $method, $args){ |
||
201 | |||
202 | /** |
||
203 | * Split the URL for the current request. |
||
204 | * |
||
205 | */ |
||
206 | public function splitUrl(){ |
||
223 | |||
224 | /** |
||
225 | * Shows not found error page |
||
226 | * |
||
227 | */ |
||
228 | private function notFound(){ |
||
231 | |||
232 | } |
||
233 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.