/** * execute command * * @param InputInterface $input * @param OutputInterface $output */ public function execute(InputInterface $input, OutputInterface $output) { $options['unlimited'] = true; $RoutesDb = new \System\Core\Models\RoutesDb($this->Db); $site_list = $RoutesDb->listRoutes($options); unset($RoutesDb, $options); if (is_array($site_list) && array_key_exists('total', $site_list) && $site_list['total'] > '0' && array_key_exists('items', $site_list)) { $output->writeln('There are total ' . $site_list['total'] . ' routes in db.'); $output->writeln('------------------------------'); $Table = new \Symfony\Component\Console\Helper\Table($output); $list_route_rows = []; foreach ($site_list['items'] as $row) { if ($row->route_core == '1') { $route_core = 'Yes'; } else { $route_core = 'No'; } $list_route_rows[] = [$row->route_id, $row->route_method . (strtolower($row->route_method) == 'match' ? "\n" . '(' . $row->route_match_method . ')' : ''), $row->route_uri, $row->route_controller, $row->route_bind, $route_core]; unset($route_core); } // endforeach; $Table->setHeaders(['Route ID', 'Method', 'URI', 'Controller', 'Name', 'Is core'])->setRows($list_route_rows); $Table->render(); unset($list_route_rows, $row, $Table); } else { $output->writeln('<error>Unable to list route or there is no route.</error>'); } unset($site_list); }
/** * get the routes from db. the routes in db will be generate to file automatically for future use. */ protected function getRoutes() { // setup international uri and language. $this->i18nUri(); if ($this->Profiler != null) { $this->Profiler->Console->timeload('Initialize the routes.', __FILE__, __LINE__); $this->Profiler->Console->memoryUsage('Initialize the routes.', __FILE__, __LINE__ - 1); } // register autoload for enabled modules. $module = new \System\Libraries\Modules($this->Silexapp); $module->registerAutoload(); unset($module); $Silexapp = $this->Silexapp; $this->Silexapp->register(new \Silex\Provider\ServiceControllerServiceProvider()); // built-in routes. --------------------------------------------- $Silexapp['SystemCoreControllersErrorE403.Controller'] = function () use($Silexapp) { $controller = new \System\Core\Controllers\Error\E403($Silexapp); return $controller; }; $Silexapp->match('/Error/E403', 'SystemCoreControllersErrorE403.Controller:indexAction')->bind('error_403'); $Silexapp->match('/Error/E403/siteDisabled', 'SystemCoreControllersErrorE403.Controller:siteDisabledAction')->bind('error_403_sitedisabled'); $Silexapp['SystemCoreControllersErrorE404.Controller'] = function () use($Silexapp) { $controller = new \System\Core\Controllers\Error\E404($Silexapp); return $controller; }; $Silexapp->match('/Error/E404', 'SystemCoreControllersErrorE404.Controller:indexAction')->bind('error_404'); // end built-in routes. ----------------------------------------- // check current site enabled. $SitesDb = new \System\Core\Models\SitesDb($this->Silexapp['Db']); if (!$SitesDb->isSiteEnabled(true)) { $request = new \Symfony\Component\HttpFoundation\Request(); $subrequest = $request->create('/Error/E403/siteDisabled'); $response = $Silexapp->handle($subrequest, \Symfony\Component\HttpKernel\HttpKernelInterface::MASTER_REQUEST, false); $response->send(); unset($request, $response, $Silexapp, $subrequest); exit; } unset($SitesDb); // routes in db. $routedb = new \System\Core\Models\RoutesDb($this->Silexapp['Db']); $route_file = $routedb->getRoutesFile(); if ($route_file != null) { include $route_file; } unset($route_file, $routedb, $Silexapp); // handle errors $this->handleErrors(); if ($this->Profiler != null) { $this->Profiler->Console->timeload('Finished the routes.', __FILE__, __LINE__); $this->Profiler->Console->memoryUsage('Finished the routes.', __FILE__, __LINE__ - 1); } }