コード例 #1
0
ファイル: ConfigCacheFactory.php プロジェクト: Dren-x/mobit
 /**
  * {@inheritdoc}
  */
 public function cache($file, $callback)
 {
     if (!is_callable($callback)) {
         throw new \InvalidArgumentException(sprintf('Invalid type for callback argument. Expected callable, but got "%s".', gettype($callback)));
     }
     $cache = new ConfigCache($file, $this->debug);
     if (!$cache->isFresh()) {
         call_user_func($callback, $cache);
     }
     return $cache;
 }
コード例 #2
0
 /**
  * Dumps the service container to PHP code in the cache.
  *
  * @param ConfigCache      $cache     The config cache
  * @param ContainerBuilder $container The service container
  * @param string           $class     The name of the class to generate
  * @param string           $baseClass The name of the container's base class
  * @param string           $kernel The kernel that is initializing the container
  */
 protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container, string $class, string $baseClass, KernelInterface $kernel)
 {
     // cache the container
     $dumper = new PhpDumper($container);
     if (class_exists('ProxyManager\\Configuration') && class_exists('Symfony\\Bridge\\ProxyManager\\LazyProxy\\PhpDumper\\ProxyDumper')) {
         $dumper->setProxyDumper(new ProxyDumper(md5($cache->getPath())));
     }
     $content = $dumper->dump(array('class' => $class, 'base_class' => $baseClass, 'file' => $cache->getPath()));
     if (!$kernel->getConfig()->isDebug()) {
         $content = static::stripComments($content);
     }
     $cache->write($content, $container->getResources());
 }
コード例 #3
0
ファイル: mojavi.php プロジェクト: bobah/acbdb
/**
 * Handles autoloading of classes that have been specified in autoload.ini.
 *
 * @param string A class name.
 *
 * @return void
 *
 * @author Sean Kerr (skerr@mojavi.org)
 * @since  3.0.0
 */
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');
        } catch (MojaviException $e) {
            $e->printStackTrace();
        } catch (Exception $e) {
            // unknown exception
            $e = new MojaviException($e->getMessage());
            $e->printStackTrace();
        }
        require_once $config;
    }
    if (!isset($classes[$class])) {
        // unspecified class
        $error = 'Autoloading of class "%s" failed';
        $error = sprintf($error, $class);
        $e = new AutoloadException($error);
        $e->printStackTrace();
    }
    // class exists, let's include it
    require_once $classes[$class];
}
コード例 #4
0
ファイル: Cache.php プロジェクト: pdedkov/config
 public static function getInstance()
 {
     if (is_null(self::$_Instance)) {
         $class = get_called_class();
         self::$_Instance = new $class(__NAMESPACE__);
     }
     return self::$_Instance;
 }
コード例 #5
0
ファイル: Controller.class.php プロジェクト: bobah/acbdb
 /**
  * Load module filters.
  *
  * @param FilterChain A FilterChain instance.
  *
  * @return void
  *
  * @author Sean Kerr (skerr@mojavi.org)
  * @since  3.0.0
  */
 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);
     }
 }
コード例 #6
0
ファイル: DatabaseManager.class.php プロジェクト: bobah/acbdb
 /**
  * Initialize this DatabaseManager.
  *
  * @return bool true, if initialization completes successfully, otherwise
  *              false.
  *
  * @throws <b>InitializationException</b> If an error occurs while
  *                                        initializing this DatabaseManager.
  *
  * @author Sean Kerr (skerr@mojavi.org)
  * @since  3.0.0
  */
 public function initialize()
 {
     // load database configuration
     require_once ConfigCache::checkConfig('config/databases.ini');
 }
コード例 #7
0
ファイル: ConfigCache.class.php プロジェクト: bobah/acbdb
 /**
  * Load all configuration application and module level handlers.
  *
  * @return void
  *
  * @throws <b>ConfigurationException</b> If a configuration related error
  *                                       occurs.
  *
  * @author Sean Kerr (skerr@mojavi.org)
  * @since  3.0.0
  */
 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
         $fp = opendir(MO_MODULE_DIR);
         // loop through the directory and grab the modules
         while (($directory = readdir($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
         fclose($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 ConfigurationException($error);
     }
 }
コード例 #8
0
ファイル: ExecutionFilter.class.php プロジェクト: bobah/acbdb
 /**
  * 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.
  *
  * @author Sean Kerr (skerr@mojavi.org)
  * @since  1.0.0
  */
 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.class.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);
         }
     }
 }
コード例 #9
0
ファイル: SugarKernel.php プロジェクト: svnvcristea/pslib
 protected function initializeContainer()
 {
     $class = $this->getContainerClass();
     $cache = new ConfigCache($this->getCacheDir() . '/' . $class . '.php', $this->debug);
     $fresh = true;
     if (!$cache->isFresh()) {
         $container = $this->buildContainer();
         $container->compile();
         $this->dumpContainer($cache, $container, $class, $this->getContainerBaseClass());
         $fresh = false;
     }
     require_once $cache->getPath();
     $this->container = new $class();
     $this->container->set('kernel', $this);
     if (!$fresh && $this->container->has('cache_warmer')) {
         $this->container->get('cache_warmer')->warmUp($this->container->getParameter('kernel.cache_dir'));
     }
 }