/**
  * get all available commands and add to cli application.
  */
 private function grabAllAvailableCommands()
 {
     $Modules = new \System\Libraries\Modules($this->Silexapp);
     $Modules->registerAutoload();
     $modules_list = $Modules->getAllAvailableModules();
     unset($Modules);
     // system/Core/Console
     if (is_file(SYSTEM_PATH . DS . 'Core' . DS . 'Console' . DS . 'Commands.php')) {
         $SystemCommands = new \System\Core\Console\Commands();
         $SystemCommands->Silexapp = $this->Silexapp;
         if (method_exists($SystemCommands, 'register')) {
             $registered_commands = $SystemCommands->register();
             if (is_array($registered_commands) && !empty($registered_commands)) {
                 $this->CliApp->addCommands($registered_commands);
             }
             unset($registered_commands);
         }
         unset($SystemCommands);
     }
     // modules/module_name/Console
     if (is_array($modules_list) && array_key_exists('items', $modules_list) && is_array($modules_list['items'])) {
         foreach ($modules_list['items'] as $row) {
             if (is_file(MODULE_PATH . DS . 'Console' . DS . 'Commands.php')) {
                 $module_commands_class = '\\Modules\\' . $row->module_system_name . '\\Console\\Commands()';
                 $ModuleCommands = new $module_commands_class();
                 $ModuleCommands->Silexapp = $this->Silexapp;
                 if (method_exists($ModuleCommands, 'register')) {
                     $registered_commands = $ModuleCommands->register();
                     if (is_array($registered_commands) && !empty($registered_commands)) {
                         $this->CliApp->addCommands($registered_commands);
                     }
                     unset($registered_commands);
                 }
                 unset($ModuleCommands, $module_commands_class);
             }
         }
         // endforeach;
         unset($row);
     }
     unset($modules_list);
 }
Example #2
0
 /**
  * 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);
     }
 }