1 | <?php |
||
14 | class Router |
||
15 | { |
||
16 | public $routeColletion; |
||
17 | private $prefix = ''; |
||
18 | private static $instance = null; |
||
19 | private $middlewares = []; |
||
20 | |||
21 | private function __construct() |
||
25 | |||
26 | public static function getInstance() |
||
34 | |||
35 | /** |
||
36 | * @param $prefixParam |
||
37 | * @param $callable |
||
38 | * |
||
39 | * @throws \ErrorException |
||
40 | */ |
||
41 | public function prefix($prefixParam, $callable) |
||
52 | |||
53 | /** |
||
54 | * @param $path |
||
55 | * @param $controller |
||
56 | * @param array $params |
||
57 | */ |
||
58 | public function add($path, $controller, $params = []) |
||
62 | |||
63 | /** |
||
64 | * @param $path |
||
65 | * @param $controller |
||
66 | * @param array $params |
||
67 | */ |
||
68 | public function get($path, $controller, $params = []) |
||
72 | |||
73 | /** |
||
74 | * @param $path |
||
75 | * @param $controller |
||
76 | * @param array $params |
||
77 | */ |
||
78 | public function post($path, $controller, $params = []) |
||
82 | |||
83 | /** |
||
84 | * @param $path |
||
85 | * @param $controller |
||
86 | * @param array $params |
||
87 | */ |
||
88 | public function put($path, $controller, $params = []) |
||
92 | |||
93 | /** |
||
94 | * @param $httpMethod |
||
95 | * @param $path |
||
96 | * @param $controller |
||
97 | * @param array $params |
||
98 | */ |
||
99 | private function setMethod($httpMethod, $path, $controller, $params = []) |
||
122 | |||
123 | /** |
||
124 | * @return array |
||
125 | */ |
||
126 | public static function getParams() |
||
150 | |||
151 | private static function includeRoutes() |
||
159 | |||
160 | /** |
||
161 | * @return bool |
||
162 | */ |
||
163 | public static function init() |
||
173 | |||
174 | /** |
||
175 | * Return router collection. |
||
176 | * |
||
177 | * @return RouteCollection |
||
178 | */ |
||
179 | public function getCollection() |
||
183 | |||
184 | /** |
||
185 | * @param $params |
||
186 | * @param $closure |
||
187 | */ |
||
188 | public function group($params, $closure) |
||
195 | } |
||
196 | |||
198 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.