namespace Application; use Bluz\Controller\Controller; use Bluz\Proxy\Layout; /** * @privilege Info * * @return \closure */ return function () { /** * @var Controller $this */ Layout::title('Routers Map'); Layout::setTemplate('dashboard.phtml'); Layout::breadCrumbs([Layout::ahref('Dashboard', ['dashboard', 'index']), Layout::ahref('System', ['system', 'index']), __('Routers Map')]); $routers = array(); foreach (new \GlobIterator(PATH_APPLICATION . '/modules/*/controllers/*.php') as $file) { $module = pathinfo(dirname(dirname($file->getPathname())), PATHINFO_FILENAME); $controller = pathinfo($file->getPathname(), PATHINFO_FILENAME); $controllerInstance = new Controller($module, $controller); $reflection = $controllerInstance->getReflection(); if ($route = $reflection->getRoute()) { if (!isset($routers[$module])) { $routers[$module] = array(); } $routers[$module][$controller] = ['route' => $route, 'params' => $reflection->getParams()]; } } $this->assign('routers', $routers); };
/** * Constructor of Router */ public function __construct() { $this->module = $this->getDefaultModule(); $this->controller = $this->getDefaultController(); $routers = Cache::get('router:routers'); $reverse = Cache::get('router:reverse'); if (!$routers || !$reverse) { $routers = []; $reverse = []; $path = Application::getInstance()->getPath() . '/modules/*/controllers/*.php'; foreach (new \GlobIterator($path) as $file) { /* @var \SplFileInfo $file */ $module = $file->getPathInfo()->getPathInfo()->getBasename(); $controller = $file->getBasename('.php'); $controllerInstance = new Controller($module, $controller); $reflection = $controllerInstance->getReflection(); if ($routes = $reflection->getRoute()) { foreach ($routes as $route => $pattern) { if (!isset($reverse[$module])) { $reverse[$module] = []; } $reverse[$module][$controller] = ['route' => $route, 'params' => $reflection->getParams()]; $rule = [$route => ['pattern' => $pattern, 'module' => $module, 'controller' => $controller, 'params' => $reflection->getParams()]]; // static routers should be first if (strpos($route, '$')) { $routers = array_merge($routers, $rule); } else { $routers = array_merge($rule, $routers); } } } } Cache::set('router:routers', $routers); Cache::set('router:reverse', $reverse); } $this->routers = $routers; $this->reverse = $reverse; }