1 | <?php |
||
16 | trait Controller { |
||
17 | /** |
||
18 | * Call methods necessary for module page rendering |
||
19 | * |
||
20 | * @param \cs\Request $Request |
||
21 | * |
||
22 | * @throws \cs\ExitException |
||
23 | */ |
||
24 | 6 | protected function controller_router ($Request) { |
|
25 | 6 | $suffix = ''; |
|
26 | 6 | if ($Request->cli_path) { |
|
27 | $suffix = '\\cli'; |
||
28 | 6 | } elseif ($Request->admin_path) { |
|
29 | $suffix = '\\admin'; |
||
30 | 6 | } elseif ($Request->api_path) { |
|
31 | 4 | $suffix = '\\api'; |
|
32 | } |
||
33 | 6 | $controller_class = class_exists("cs\\custom\\modules\\$Request->current_module$suffix\\Controller") |
|
34 | ? "cs\\custom\\modules\\$Request->current_module$suffix\\Controller" |
||
35 | 6 | : "cs\\modules\\$Request->current_module$suffix\\Controller"; |
|
36 | 6 | foreach ($this->controller_path as $index => $path) { |
|
37 | /** |
||
38 | * Starting from index 2 we need to maintain underscore-separated string that includes all paths from index 1 and till current |
||
39 | */ |
||
40 | 6 | if ($index > 1) { |
|
41 | $path = implode('_', array_slice($this->controller_path, 1, $index)); |
||
42 | } |
||
43 | 6 | $next_exists = isset($this->controller_path[$index + 1]); |
|
44 | 6 | $this->controller_router_handler($Request, $controller_class, $path, !$next_exists); |
|
45 | } |
||
46 | 6 | } |
|
47 | /** |
||
48 | * Call methods that corresponds for specific paths in URL |
||
49 | * |
||
50 | * @param \cs\Request $Request |
||
51 | * @param string $controller_class |
||
52 | * @param string $method_name |
||
53 | * @param bool $required |
||
54 | * |
||
55 | * @throws \cs\ExitException |
||
56 | */ |
||
57 | 6 | protected function controller_router_handler ($Request, $controller_class, $method_name, $required = true) { |
|
61 | /** |
||
62 | * @param \cs\Request $Request |
||
63 | * @param string $controller_class |
||
64 | * @param string $method_name |
||
65 | * @param bool $required |
||
66 | * |
||
67 | * @throws \cs\ExitException |
||
68 | */ |
||
69 | 6 | protected function controller_router_handler_internal ($Request, $controller_class, $method_name, $required) { |
|
86 | /** |
||
87 | * @param string $working_directory |
||
88 | * @param string $controller_class |
||
89 | * @param string $method_name |
||
90 | * |
||
91 | * @return string[] |
||
92 | */ |
||
93 | protected function controller_router_available_methods ($working_directory, $controller_class, $method_name) { |
||
117 | /** |
||
118 | * @param array $structure |
||
119 | * @param string $prefix |
||
120 | * |
||
121 | * @return string[] |
||
122 | */ |
||
123 | protected function controller_router_available_methods_to_flat_structure ($structure, $prefix = '') { |
||
136 | /** |
||
137 | * @param string $controller_class |
||
138 | * @param string $method_name |
||
139 | * @param \cs\Request $Request |
||
140 | * @param Response $Response |
||
141 | * |
||
142 | * @return bool |
||
143 | */ |
||
144 | 6 | protected function controller_router_handler_internal_execute ($controller_class, $method_name, $Request, $Response) { |
|
154 | } |
||
155 |