1 | <?php |
||
5 | class Loader |
||
6 | { |
||
7 | /** |
||
8 | * Application Object |
||
9 | * |
||
10 | * @var \System\Application |
||
11 | */ |
||
12 | private $app; |
||
13 | |||
14 | /** |
||
15 | * Controllers container |
||
16 | * |
||
17 | * @var array |
||
18 | */ |
||
19 | private $controllers = []; |
||
20 | |||
21 | /** |
||
22 | * Models container |
||
23 | * |
||
24 | * @var array |
||
25 | */ |
||
26 | private $models = []; |
||
27 | |||
28 | /** |
||
29 | * Models container |
||
30 | * |
||
31 | * @var array |
||
32 | */ |
||
33 | private $middlewares = []; |
||
34 | |||
35 | /** |
||
36 | * Constructor |
||
37 | * |
||
38 | * @param \System\Application $app |
||
39 | */ |
||
40 | public function __construct(Application $app) |
||
44 | |||
45 | /** |
||
46 | * Call the given controller with the given method |
||
47 | * and pass the given arguments to the controller method |
||
48 | * |
||
49 | * @param string $controller |
||
50 | * @param string $method |
||
51 | * @param array $arguments |
||
52 | * @return mixed |
||
53 | */ |
||
54 | public function action(string $controller, string $method, array $arguments) |
||
60 | |||
61 | /** |
||
62 | * Call the given controller |
||
63 | * |
||
64 | * @param string $controller |
||
65 | * @return object |
||
66 | */ |
||
67 | public function controller(string $controller) |
||
76 | |||
77 | /** |
||
78 | * Determine if the given class|controller exists |
||
79 | * in the controllers container |
||
80 | * |
||
81 | * @param string $controller |
||
82 | * @return bool |
||
83 | */ |
||
84 | private function hasController($controller) |
||
88 | |||
89 | /** |
||
90 | * Create new object for the given controller and store it |
||
91 | * in controllers container |
||
92 | * |
||
93 | * @param string $controller |
||
94 | * @return void |
||
95 | */ |
||
96 | private function addController($controller) |
||
102 | |||
103 | /** |
||
104 | * Get the controller object |
||
105 | * |
||
106 | * @param string $controller |
||
107 | * @return object |
||
108 | */ |
||
109 | private function getController($controller) |
||
113 | |||
114 | |||
115 | /** |
||
116 | * Get the full class name for the given controller |
||
117 | * |
||
118 | * @param string $controller |
||
119 | * @return string |
||
120 | */ |
||
121 | private function getControllerName($controller) |
||
127 | |||
128 | /** |
||
129 | * Call the given model |
||
130 | * |
||
131 | * @param string $model |
||
132 | * @return object |
||
133 | */ |
||
134 | public function model(string $model) |
||
143 | |||
144 | /** |
||
145 | * Determine if the given class|model exists |
||
146 | * in the models container |
||
147 | * |
||
148 | * @param string $model |
||
149 | * @return bool |
||
150 | */ |
||
151 | private function hasModel($model) |
||
155 | |||
156 | /** |
||
157 | * Create new object for the given model and store it |
||
158 | * in models container |
||
159 | * |
||
160 | * @param string $model |
||
161 | * @return void |
||
162 | */ |
||
163 | private function addModel($model) |
||
169 | |||
170 | /** |
||
171 | * Get the model object |
||
172 | * |
||
173 | * @param string $model |
||
174 | * @return object |
||
175 | */ |
||
176 | private function getModel($model) |
||
180 | |||
181 | /** |
||
182 | * Get the full class name for the given model |
||
183 | * |
||
184 | * @param string $model |
||
185 | * @return string |
||
186 | */ |
||
187 | private function getModelName($model) |
||
193 | |||
194 | /** |
||
195 | * Call the given middleware |
||
196 | * |
||
197 | * @param string $middleware |
||
198 | * @return object |
||
199 | */ |
||
200 | public function middleware(string $middleware) |
||
209 | |||
210 | /** |
||
211 | * Determine if the given class|middleware exists |
||
212 | * in the middlewares container |
||
213 | * |
||
214 | * @param string $middleware |
||
215 | * @return bool |
||
216 | */ |
||
217 | private function hasMiddleware($middleware) |
||
221 | |||
222 | /** |
||
223 | * Create new object for the given middleware and store it |
||
224 | * in middlewares container |
||
225 | * |
||
226 | * @param string $middleware |
||
227 | * @return void |
||
228 | */ |
||
229 | private function addMiddleware($middleware) |
||
235 | |||
236 | /** |
||
237 | * Get the middleware object |
||
238 | * |
||
239 | * @param string $middleware |
||
240 | * @return object |
||
241 | */ |
||
242 | private function getMiddleware($middleware) |
||
246 | |||
247 | /** |
||
248 | * Get the full class name for the given middleware |
||
249 | * |
||
250 | * @param string $middleware |
||
251 | * @return string |
||
252 | */ |
||
253 | private function getMiddlewareName($middleware) |
||
259 | } |
||
260 |