public function __construct(\Silex\Application $App = null) { parent::__construct($App); $Module = new \System\Libraries\Modules($App); $Module->bindTextDomainForModule('agnifw'); // load functions $this->Loader->loadFunctions('language'); }
/** * 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); }
/** * 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); } }
/** * index action * * @return string */ public function indexAction() { $Module = new \System\Libraries\Modules($this->Silexapp); $Module->bindTextDomainForModule('cms'); // load functions $this->Loader->loadFunctions('language'); // list languages for language selector. $LanguagesDb = new \System\Core\Models\LanguagesDb($this->Silexapp['Db']); $language_file = $LanguagesDb->getConfigFile(); if (is_file($language_file)) { $languages_config = (include $language_file); } unset($LanguagesDb, $language_file); if (isset($languages_config) && is_array($languages_config) && array_key_exists('languages', $languages_config)) { $data['languages'] = $languages_config['languages']; } else { $data['languages'] = []; } unset($languages_config); $data['Uri'] = new \System\Libraries\Uri(); $data['framework_name'] = _t('Agni Framework', 'cms'); $data['page_content'] = $this->Theme->render('front/templates/index/index_v', $data); return $this->Theme->render('front/templates/body_v', $data); }
/** * render the theme or views. * * @param string $views_file path to theme file or views file. * @param array $output_data the data that will be sent to theme or views. */ public function render($views_file, array $output_data = []) { // get the module name of this views. // the $module_name can be just name and folder/name. for example: Cms = Modules\Cms, System/Core = System\Core. $Modules = new \System\Libraries\Modules(); $module_name = $Modules->currentModule(); unset($Modules); // init config library to load theme config file. $config = new \System\Libraries\Config(); $config->load('theme'); // get the theme name. if (strpos($views_file, 'admin/') !== false) { $fallback_type = 'admin'; } else { $fallback_type = 'front'; } $theme_name = $this->getThemeNameWithFallback($config, $fallback_type); $theme_name_fallback = $this->getThemeFallback($config, $fallback_type); unset($fallback_type); $output = ''; // check template engine enabled. $template_engine = $config->get('template_engine', 'theme'); $theme_dir = $config->get('theme_dir', 'theme'); if ($template_engine != null) { // theme config uses template engine. $TemplateClass = call_user_func($template_engine); $theme_location = $this->findThemeOrViewsLocation($views_file, $theme_dir, $theme_name, $theme_name_fallback, $module_name, $TemplateClass); if (is_array($theme_location) && array_key_exists('theme_path', $theme_location) && array_key_exists('theme_file', $theme_location) && array_key_exists('use_template', $theme_location) && array_key_exists('theme_name', $theme_location)) { // can find template location. if ($theme_location['use_template'] === true) { // confirmed use template file. // use load template and render it. $output = $TemplateClass->render($theme_location['theme_path'], $theme_location['theme_file'], $theme_location['theme_name'], $module_name, $output_data); } else { // cannot confirmed use template file. // use normal load views file. $output = $this->loadViews($theme_location['theme_path'] . '/' . $theme_location['theme_file'], $output_data); } } else { // cannot find template location. // use normal load views file. $output = $this->loadViews($theme_location['theme_path'] . '/' . $theme_location['theme_file'], $output_data); } unset($TemplateClass); } else { // theme config do not use template engine. $views_location = $this->findThemeOrViewsLocation($views_file, $theme_dir, $theme_name, $theme_name_fallback, $module_name); $output = $this->loadViews($views_location['theme_path'] . '/' . $views_location['theme_file'], $output_data); } unset($config, $module_name, $template_engine, $theme_dir, $theme_location, $theme_name, $theme_name_fallback, $views_location); return $output; }