Exemplo n.º 1
0
 /**
  * @param string $file
  */
 public function load($file)
 {
     $config = $this->cache->get($file);
     if (null === $config) {
         $config = $this->factory->buildFromPath($file);
         $this->cache->set($file, $config->toArray());
     } else {
         $config = new Config($config);
     }
     if ($config) {
         $this->config->merge($config);
     }
     return $this;
 }
Exemplo n.º 2
0
    public static function register(Di $di)
    {
        $environment = isset($_SERVER['PHWOOLCON_ENV']) ? $_SERVER['PHWOOLCON_ENV'] : 'production';
        // @codeCoverageIgnoreStart
        if (is_file($cacheFile = storagePath('cache/config-' . $environment . '.php'))) {
            static::$config = (include $cacheFile);
            Config::get('app.cache_config') or static::clearCache();
            return;
        }
        // @codeCoverageIgnoreEnd
        $defaultFiles = glob($_SERVER['PHWOOLCON_CONFIG_PATH'] . '/*.php');
        $environmentFiles = glob($_SERVER['PHWOOLCON_CONFIG_PATH'] . '/' . $environment . '/*.php');
        $config = new PhalconConfig(static::loadFiles($defaultFiles));
        $environmentSettings = static::loadFiles($environmentFiles);
        $environmentSettings['environment'] = $environment;
        $environmentConfig = new PhalconConfig($environmentSettings);
        $config->merge($environmentConfig);
        $di->remove('config');
        $di->setShared('config', $config);
        static::$config = $config->toArray();
        Config::get('database.default') and static::loadDb($config);
        // @codeCoverageIgnoreStart
        if (Config::get('app.cache_config')) {
            is_dir($cacheDir = dirname($cacheFile)) or mkdir($cacheDir, 0777, true);
            fileSaveArray($cacheFile, static::$config, function ($content) {
                $replacement = <<<'EOF'
$_SERVER['PHWOOLCON_ROOT_PATH'] . '
EOF;
                return str_replace("'{$_SERVER['PHWOOLCON_ROOT_PATH']}", $replacement, $content);
            });
        }
        // @codeCoverageIgnoreEnd
    }
Exemplo n.º 3
0
 /**
  * Initializes application modules
  */
 public function initModules(Config $config)
 {
     $moduleLoader = new ModuleLoader($this->getDI());
     //registers modules defined in modules.php file
     $modulesFile = $config->application->configDir . Loader::MODULE_STATIC_FILE;
     /**
      * For non-default environment modules are being dumped in each application start
      */
     if (!file_exists($modulesFile) || $this->getDI()->get('environment') != Constants::DEFAULT_ENV) {
         $modules = $moduleLoader->dump($config->application->moduleDir, $config->application->configDir);
     } else {
         $modules = (require $modulesFile);
     }
     if (!is_array($modules)) {
         throw new InvalidModulesListException();
     }
     $this->getApplication()->registerModules($modules);
     //prepares modules configurations
     foreach ($this->getApplication()->getModules() as $module) {
         $moduleConfigFile = dirname($module['path']) . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php';
         if (file_exists($moduleConfigFile)) {
             $moduleConfig = (require $moduleConfigFile);
             if (is_array($moduleConfig)) {
                 $config->merge($moduleConfig);
             }
         }
     }
     $this->getDI()->set('modules', function () {
         return $this->getApplication()->getModules();
     });
 }
Exemplo n.º 4
0
 /**
  * Initializes the config. Reads it from its location and
  * stores it in the Di container for easier access
  * @param array $aOptions
  */
 protected function initConfig($aOptions = array())
 {
     $oConfig = new PhConfig();
     $aSharedConfig = (require ROOT_PATH . '/config/config.php');
     $oConfig->merge(new PhConfig($aSharedConfig));
     $this->oDI->setShared('config', $oConfig);
 }
Exemplo n.º 5
0
 public function testConfigMerge()
 {
     $configA = new Config(['paramA' => ['paramB' => 'valueA']]);
     $configB = new Config(['paramA' => ['paramB' => 'valueB', 'paramC' => 'valueC']]);
     $configB->merge($configA);
     $this->assertEquals('valueA', $configB->paramA->paramB);
     $this->assertEquals('valueC', $configB->paramA->paramC);
 }
Exemplo n.º 6
0
 /**
  * Load configuration files
  */
 protected function initConfig()
 {
     // read in config arrays
     $defaultConfig = (require APP_PATH . '/etc/config.php');
     $localConfig = (require APP_PATH . '/etc/config.local.php');
     // instantiate them into the phalcon config
     $config = new Config($defaultConfig);
     $config->merge(new Config($localConfig));
     $this->di['config'] = $config;
 }
Exemplo n.º 7
0
 protected function mergeConfigFile(Config &$config, $file)
 {
     if (is_readable($file)) {
         $mergeconf = (include $file);
         if (is_array($mergeconf)) {
             $mergeconf = new Config($mergeconf);
         }
         if ($mergeconf instanceof Config) {
             $config->merge($mergeconf);
         }
     }
 }
Exemplo n.º 8
0
 public function diRouter()
 {
     $di = $this->getDI();
     $cachePrefix = $this->getAppName();
     $cacheFile = $this->getConfigPath() . "/_cache.{$cachePrefix}.router.php";
     if ($router = $this->readCache($cacheFile, true)) {
         return $router;
     }
     $moduleManager = $di->getModuleManager();
     $config = new Config();
     $moduleName = '';
     if ($moduleManager && ($modulesArray = $moduleManager->getModules())) {
         foreach ($modulesArray as $moduleName => $module) {
             //NOTICE: EvaEngine Load front-end router at last
             $config->merge(new Config($moduleManager->getModuleRoutesFrontend($moduleName)));
             $config->merge(new Config($moduleManager->getModuleRoutesBackend($moduleName)));
         }
     }
     //Disable default router
     $router = new Router(false);
     //Last extra slash
     $router->removeExtraSlashes(true);
     //Set last module as default module
     $router->setDefaultModule($moduleName);
     //NOTICE: Set a strange controller here to make router not match default index/index
     $router->setDefaultController('EvaEngineDefaultController');
     $config = $config->toArray();
     foreach ($config as $url => $route) {
         if (count($route) !== count($route, COUNT_RECURSIVE)) {
             if (isset($route['pattern']) && isset($route['paths'])) {
                 $method = isset($route['httpMethods']) ? $route['httpMethods'] : null;
                 $router->add($route['pattern'], $route['paths'], $method);
             } else {
                 throw new Exception\RuntimeException(sprintf('No route pattern and paths found by route %s', $url));
             }
         } else {
             $router->add($url, $route);
         }
     }
     if (!$di->getConfig()->debug) {
         $this->writeCache($cacheFile, $router, true);
     } else {
         //Dump merged routers for debug
         $this->writeCache($this->getConfigPath() . "/_debug.{$cachePrefix}.router.php", $router, true);
     }
     return $router;
 }
Exemplo n.º 9
0
 /**
  * @param array $modules
  * @return Config
  */
 public function getConfigs(array $modules)
 {
     $config = new Config();
     foreach ($modules as $moduleName => $moduleConfig) {
         $configPath = Path::join($moduleConfig['dir'], self::MODULE_CONFIG_DIR, 'config.php');
         if (file_exists($configPath)) {
             $moduleConfig = (require $configPath);
             if (!$moduleConfig instanceof Config) {
                 $moduleConfig = new Config($moduleConfig);
             }
             $config->merge($moduleConfig);
         }
     }
     return $config;
 }
Exemplo n.º 10
0
 private function _mergeModConf($conf, $merge)
 {
     if (!$conf instanceof Config) {
         if (!is_array($conf)) {
             $conf = array();
         }
         $conf = new Config($conf);
     }
     if (!$merge instanceof Config) {
         if (!is_array($merge)) {
             $merge = array();
         }
         $merge = new Config($merge);
     }
     return $conf->merge($merge);
 }
Exemplo n.º 11
0
 /**
  * @param Config $config
  * @return Config
  */
 public function mergeConfig(Config $config)
 {
     $this->config = $config->merge($this->config);
     return $this->config;
 }
Exemplo n.º 12
0
 public function merge(PhConfig $config)
 {
     return parent::merge($config);
 }
Exemplo n.º 13
0
 public function getServerAttr($attr)
 {
     static $cache;
     static $server;
     if (!$cache || $server !== $_SERVER) {
         $cache = new Config(['REMOTE_ADDR' => 'localhost', 'HTTP_USER_AGENT' => 'shell']);
         if ($_SERVER) {
             $cache->merge(new Config($_SERVER));
         }
     }
     $server = $_SERVER;
     return $cache[$attr];
 }
Exemplo n.º 14
0
<?php

use Phalcon\Config;
$projectDir = realpath(__DIR__ . '/../../..') . '/';
$appDir = $projectDir . 'app/';
$etcDir = $projectDir . 'etc/';
$devDir = $projectDir . 'dev/';
$distDir = $projectDir . 'dist/';
$composerDir = $devDir . 'vendor/';
$cacheDir = $tmpDir . 'cache/';
// Clear cache for gettext and other extensions
clearstatcache();
// Create the path to the temporary Volt cache directory
exec("mkdir -p " . escapeshellarg($cacheDir . 'volt/'));
exec("mkdir -p " . escapeshellarg($cacheDir . 'locale/'));
$config = new Config(yaml_parse_file("{$etcDir}/dev_defaults.yml"));
$config2 = new Config(yaml_parse_file("{$etcDir}/dev.yml"));
$config3 = new Config([DEV_ENV => ['path' => ['projectDir' => $projectDir, 'etcDir' => $etcDir, 'devDir' => $devDir, 'distDir' => $distDir]]]);
$config4 = new Config(['locale' => yaml_parse_file("{$appDir}/locale/config.yml")]);
$config->merge($config2);
$config->merge($config3);
$config->merge($config4);
return $config;
Exemplo n.º 15
0
 /**
  * Tests merging complex config objects
  *
  * @author Andres Gutierrez <*****@*****.**>
  * @since  2012-12-16
  */
 public function testConfigMergeComplexObjects()
 {
     $this->specify("Config objects does not merged properly", function () {
         $config1 = new PhConfig(['controllersDir' => '../x/y/z', 'modelsDir' => '../x/y/z', 'database' => ['adapter' => 'Mysql', 'host' => 'localhost', 'username' => 'scott', 'password' => 'cheetah', 'name' => 'test_db', 'charset' => ['primary' => 'utf8'], 'alternatives' => ['primary' => 'latin1', 'second' => 'latin1']]]);
         $config2 = new PhConfig(['modelsDir' => '../x/y/z', 'database' => ['adapter' => 'Postgresql', 'host' => 'localhost', 'username' => 'peter', 'options' => ['case' => 'lower', \PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'], 'alternatives' => ['primary' => 'swedish', 'third' => 'american']]]);
         $config1->merge($config2);
         $expected = PhConfig::__set_state(['controllersDir' => '../x/y/z', 'modelsDir' => '../x/y/z', 'database' => PhConfig::__set_state(['adapter' => 'Postgresql', 'host' => 'localhost', 'username' => 'peter', 'password' => 'cheetah', 'name' => 'test_db', 'charset' => PhConfig::__set_state(['primary' => 'utf8']), 'alternatives' => PhConfig::__set_state(['primary' => 'swedish', 'second' => 'latin1', 'third' => 'american']), 'options' => PhConfig::__set_state(['case' => 'lower', (string) \PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'])])]);
         expect($config1)->equals($expected);
     });
 }
Exemplo n.º 16
0
<?php

use Phalcon\Config;
$config = new Config(['database' => ['dbname' => APP_PATH . '/cache/demo.db'], 'application' => ['viewsDir' => APP_PATH . '/views/', 'cacheDir' => APP_PATH . '/cache/', 'logsDir' => APP_PATH . '/logs/', 'baseDir' => APP_PATH . '/', 'controllersDir' => APP_PATH . '/src/Controllers', 'tasksDir' => APP_PATH . '/src/Tasks', 'baseUri' => '', 'staticBaseUri' => '/'], 'eventListeners' => ['db' => ['PhalconX\\Db\\DbListener' => ['logging' => true]]], 'annotations' => ['prefix' => 'v1', 'lifetime' => 10], 'metadata' => ['prefix' => 'v1', 'lifetime' => 10]]);
if (PHP_SAPI != 'cli') {
    $config->merge(new Config(['eventListeners' => ['dispatch' => ['PhalconX\\Mvc\\Controller\\Filters', 'AdminGen\\Mvc\\ExceptionHandler']]]));
}
return $config;