ejessyp /
flowerflow
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Configuration file to create router as $di service. |
||
| 4 | */ |
||
| 5 | return [ |
||
| 6 | "services" => [ |
||
| 7 | "router" => [ |
||
| 8 | "shared" => true, |
||
| 9 | "callback" => function () { |
||
| 10 | $router = new \Anax\Route\Router(); |
||
| 11 | $router->setDI($this); |
||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Loading history...
|
|||
| 12 | |||
| 13 | // Load the configuration files |
||
| 14 | $cfg = $this->get("configuration"); |
||
| 15 | $config = $cfg->load("router"); |
||
| 16 | |||
| 17 | // Set DEVELOPMENT/PRODUCTION mode, if defined |
||
| 18 | $mode = $config["config"]["mode"] ?? null; |
||
| 19 | if (isset($mode)) { |
||
| 20 | $router->setMode($mode); |
||
| 21 | } else if (defined("ANAX_PRODUCTION")) { |
||
| 22 | $router->setMode(\Anax\Route\Router::PRODUCTION); |
||
| 23 | } |
||
| 24 | |||
| 25 | // Add routes from configuration file/dir |
||
| 26 | $file = null; |
||
|
0 ignored issues
–
show
|
|||
| 27 | try { |
||
| 28 | $file = $config["file"] ?? null; |
||
| 29 | $items = $config["config"] ?? []; |
||
| 30 | if (!empty($items)) { |
||
| 31 | $router->addRoutes($items); |
||
| 32 | } |
||
| 33 | |||
| 34 | foreach ($config["items"] ?? [] as $routes) { |
||
| 35 | $file = $routes["file"]; |
||
| 36 | $items = $routes["config"] ?? []; |
||
| 37 | $router->addRoutes($items); |
||
| 38 | } |
||
| 39 | } catch (Exception $e) { |
||
| 40 | throw new Exception( |
||
| 41 | "Configuration file: '$file'. " |
||
| 42 | . $e->getMessage() |
||
| 43 | ); |
||
| 44 | } |
||
| 45 | |||
| 46 | return $router; |
||
| 47 | } |
||
| 48 | ], |
||
| 49 | ], |
||
| 50 | ]; |
||
| 51 |