/** * Handles autoloading of classes that have been specified in autoload.ini. * * @param string A class name. * * @return void */ function __autoload($class) { // this static variable is generated by the $config file below static $classes; if (!isset($classes)) { try { // include the list of autoload classes $config = ConfigCache::checkConfig('config/autoload.ini'); require_once $config; } catch (MojaviException $e) { $e->printStackTrace(); } catch (Exception $e) { // unknown exception $e = new MojaviException($e->getMessage()); $e->printStackTrace(); } } if (isset($classes[$class])) { // class exists, let's include it require_once $classes[$class]; } else { $className = ltrim($class, '\\'); $fileName = ''; $namespace = ''; if (($lastNsPos = strripos($className, '\\')) !== false) { $namespace = substr($className, 0, $lastNsPos); $className = substr($className, $lastNsPos + 1); $fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR; } $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className); if (file_exists(MO_LIB_DIR . DIRECTORY_SEPARATOR . $fileName . '.php')) { require_once $fileName . '.php'; } else { // Split the class by underscores and look for it $class_file = str_replace('_', DIRECTORY_SEPARATOR, $class); if (file_exists(MO_LIB_DIR . DIRECTORY_SEPARATOR . $class_file . '.php')) { require_once MO_LIB_DIR . DIRECTORY_SEPARATOR . $class_file . '.php'; } else { if (false) { // Destroy the session completely session_destroy(); // unspecified class $error = 'Autoloading of class "%s" failed'; $error = sprintf($error, $class); $e = new AutoloadException($error); $e->printStackTrace(); // Clear the cache // Clearing the cache here can cause a bunch of bus errors in apache, so we don't do it anymore */ // ConfigCache::clear(); if (in_array(session_name(), $_COOKIE)) { if (file_exists("/tmp/sess_" . $_COOKIE[session_name()])) { try { unlink("/tmp/sess_" . $_COOKIE[session_name()]); } catch (Exception $e) { $e = new \Mojavi\Exception\MojaviException($e->getMessage()); $e->printStackTrace(""); } } } } } } } }
/** * Initialize this LoggingManager. * * @return bool true, if initialization completes successfully, otherwise * false. * * @throws <b>InitializationException</b> If an error occurs while * initializing this LoggingManager. */ public static function initialize() { // load database configuration require_once ConfigCache::checkConfig('config/logging.ini'); }
/** * Execute this filter. * * @param FilterChain The filter chain. * * @return void * * @throws <b>InitializeException</b> If an error occurs during view * initialization. * @throws <b>ViewException</b> If an error occurs while executing * the view. */ public function execute($filterChain) { static $context, $controller, $validatorManager; if (!isset($context)) { // get the context and controller $context = $this->getContext(); $controller = $context->getController(); // create validator manager $validatorManager = new ValidatorManager(); $validatorManager->initialize($context); } else { // clear the validator manager for reuse $validatorManager->clear(); } // get the current action instance $actionEntry = $controller->getActionStack()->getLastEntry(); $actionInstance = $actionEntry->getActionInstance(); // get the current action information $moduleName = $context->getModuleName(); $actionName = $context->getActionName(); // get the request method $method = $context->getRequest()->getMethod(); if (($actionInstance->getRequestMethods() & $method) != $method) { // this action will skip validation/execution for this method // get the default view $viewName = $actionInstance->getDefaultView(); } else { // set default validated status $validated = true; // get the current action validation configuration $validationConfig = MO_MODULE_DIR . '/' . $moduleName . '/validate/' . $actionName . '.ini'; if (is_readable($validationConfig)) { // load validation configuration // do NOT use require_once $validationConfig = 'modules/' . $moduleName . '/validate/' . $actionName . '.ini'; require ConfigCache::checkConfig($validationConfig); } // manually load validators $actionInstance->registerValidators($validatorManager); // process validators $validated = $validatorManager->execute(); // process manual validation if ($validated && $actionInstance->validate()) { // execute the action $viewName = $actionInstance->execute(); } else { // validation failed $viewName = $actionInstance->handleError(); } } if ($viewName != View::NONE) { if (is_array($viewName)) { // we're going to use an entirely different action for this view $moduleName = $viewName[0]; $viewName = $viewName[1]; } else { // use a view related to this action $viewName = $actionName . $viewName; } // display this view if (!$controller->viewExists($moduleName, $viewName)) { // the requested view doesn't exist $file = MO_MODULE_DIR . '/' . $moduleName . '/views/' . $viewName . 'View.php'; $error = 'Module "%s" does not contain the view "%sView" or ' . 'the file "%s" is unreadable'; $error = sprintf($error, $moduleName, $viewName, $file); throw new ViewException($error); } // get the view instance $viewInstance = $controller->getView($moduleName, $viewName); // initialize the view if ($viewInstance->initialize($context)) { // view initialization completed successfully $viewInstance->execute(); // render the view and if data is returned, stick it in the // action entry which was retrieved from the execution chain $viewData =& $viewInstance->render(); if ($controller->getRenderMode() == View::RENDER_VAR) { $actionEntry->setPresentation($viewData); } } else { // view failed to initialize $error = 'View initialization failed for module "%s", ' . 'view "%sView"'; $error = sprintf($error, $moduleName, $viewName); throw new InitializationException($error); } } }
/** * Load all configuration application and module level handlers. * * @return void * * @throws <b>ConfigurationException</b> If a configuration related error * occurs. */ private static function loadConfigHandlers() { // manually create our config_handlers.ini handler self::$handlers['config_handlers.ini'] = new RootConfigHandler(); self::$handlers['config_handlers.ini']->initialize(); // application configuration handlers require_once ConfigCache::checkConfig('config/config_handlers.ini'); // module level configuration handlers // make sure our modules directory exists if (is_readable(MO_MODULE_DIR)) { // ignore names $ignore = array('.', '..', 'CVS', '.svn'); // create a file pointer to the module dir $cc_fp = opendir(MO_MODULE_DIR); // loop through the directory and grab the modules while (($directory = readdir($cc_fp)) !== false) { if (!in_array($directory, $ignore)) { $config = MO_MODULE_DIR . '/' . $directory . '/config/config_handlers.ini'; if (is_readable($config)) { // initialize the root configuration handler with this // module name $params = array('module_level' => true, 'module_name' => $directory); self::$handlers['config_handlers.ini']->initialize($params); // replace module dir path with a special keyword that // checkConfig knows how to use $config = 'modules/' . $directory . '/config/config_handlers.ini'; require_once ConfigCache::checkConfig($config); } } } // close file pointer if (!is_int($cc_fp)) { @fclose($cc_fp); } } else { // module directory doesn't exist or isn't readable $error = 'Module directory "%s" does not exist or is not readable'; $error = sprintf($error, MO_MODULE_DIR); throw new \Mojavi\Exception\ConfigurationException($error); } }
/** * Load module filters. * * @param FilterChain A FilterChain instance. * * @return void */ private function loadModuleFilters($filterChain) { // filter list cache file static $list = array(); // get the module name $moduleName = $this->context->getModuleName(); if (!isset($list[$moduleName])) { // we haven't loaded a filter list for this module yet $config = MO_MODULE_DIR . '/' . $moduleName . '/config/filters.ini'; if (is_readable($config)) { require_once ConfigCache::checkConfig($config); } else { // add an emptry array for this module since no filters // exist $list[$moduleName] = array(); } } // register filters foreach ($list[$moduleName] as $filter) { $filterChain->register($filter); } }