/** * Startup the Agavi core * * @param string environment the environment to use for this session. * * @author David Zülke <*****@*****.**> * @since 0.11.0 */ public static function bootstrap($environment = null) { // set up our __autoload spl_autoload_register(array('AgaviAutoloader', 'loadClass')); try { if ($environment === null) { // no env given? let's read one from core.environment $environment = AgaviConfig::get('core.environment'); } elseif (AgaviConfig::has('core.environment') && AgaviConfig::isReadonly('core.environment')) { // env given, but core.environment is read-only? then we must use that instead and ignore the given setting $environment = AgaviConfig::get('core.environment'); } if ($environment === null) { // still no env? oh man... throw new AgaviException('You must supply an environment name to Agavi::bootstrap() or set the name of the default environment to be used in the configuration directive "core.environment".'); } // finally set the env to what we're really using now. AgaviConfig::set('core.environment', $environment, true, true); AgaviConfig::set('core.debug', false, false); if (!AgaviConfig::has('core.app_dir')) { throw new AgaviException('Configuration directive "core.app_dir" not defined, terminating...'); } // define a few filesystem paths AgaviConfig::set('core.cache_dir', AgaviConfig::get('core.app_dir') . '/cache', false, true); AgaviConfig::set('core.config_dir', AgaviConfig::get('core.app_dir') . '/config', false, true); AgaviConfig::set('core.system_config_dir', AgaviConfig::get('core.agavi_dir') . '/config/defaults', false, true); AgaviConfig::set('core.lib_dir', AgaviConfig::get('core.app_dir') . '/lib', false, true); AgaviConfig::set('core.model_dir', AgaviConfig::get('core.app_dir') . '/models', false, true); AgaviConfig::set('core.module_dir', AgaviConfig::get('core.app_dir') . '/modules', false, true); AgaviConfig::set('core.template_dir', AgaviConfig::get('core.app_dir') . '/templates', false, true); AgaviConfig::set('core.cldr_dir', AgaviConfig::get('core.agavi_dir') . '/translation/data', false, true); // autoloads first (will trigger the compilation of config_handlers.xml) $autoload = AgaviConfig::get('core.config_dir') . '/autoload.xml'; if (!is_readable($autoload)) { $autoload = AgaviConfig::get('core.system_config_dir') . '/autoload.xml'; } AgaviConfigCache::load($autoload); // load base settings AgaviConfigCache::load(AgaviConfig::get('core.config_dir') . '/settings.xml'); // clear our cache if the conditions are right if (AgaviConfig::get('core.debug')) { AgaviToolkit::clearCache(); // load base settings AgaviConfigCache::load(AgaviConfig::get('core.config_dir') . '/settings.xml'); } $compile = AgaviConfig::get('core.config_dir') . '/compile.xml'; if (!is_readable($compile)) { $compile = AgaviConfig::get('core.system_config_dir') . '/compile.xml'; } // required classes for the framework AgaviConfigCache::load($compile); } catch (Exception $e) { AgaviException::render($e); } }
public function testload() { $this->assertFalse(defined('ConfigCacheImportTest_included')); AgaviConfigCache::load(AgaviConfig::get('core.config_dir') . '/tests/importtest.xml'); $this->assertTrue(defined('ConfigCacheImportTest_included')); $GLOBALS["ConfigCacheImportTestOnce_included"] = false; AgaviConfigCache::load(AgaviConfig::get('core.config_dir') . '/tests/importtest_once.xml', true); $this->assertTrue($GLOBALS["ConfigCacheImportTestOnce_included"]); $GLOBALS["ConfigCacheImportTestOnce_included"] = false; AgaviConfigCache::load(AgaviConfig::get('core.config_dir') . '/tests/importtest_once.xml', true); $this->assertFalse($GLOBALS["ConfigCacheImportTestOnce_included"]); }
/** * Initialize a module and load its autoload, module config etc. * * @param string The name of the module to initialize. * * @author Felix Gilcher <*****@*****.**> * @since 1.0.0 */ public function initializeModule($moduleName) { $lowerModuleName = strtolower($moduleName); if (null === AgaviConfig::get('modules.' . $lowerModuleName . '.enabled')) { // set some defaults first AgaviConfig::fromArray(array('modules.' . $lowerModuleName . '.agavi.action.path' => '%core.module_dir%/${moduleName}/actions/${actionName}Action.class.php', 'modules.' . $lowerModuleName . '.agavi.cache.path' => '%core.module_dir%/${moduleName}/cache/${actionName}.xml', 'modules.' . $lowerModuleName . '.agavi.template.directory' => '%core.module_dir%/${module}/templates', 'modules.' . $lowerModuleName . '.agavi.validate.path' => '%core.module_dir%/${moduleName}/validate/${actionName}.xml', 'modules.' . $lowerModuleName . '.agavi.view.path' => '%core.module_dir%/${moduleName}/views/${viewName}View.class.php', 'modules.' . $lowerModuleName . '.agavi.view.name' => '${actionName}${viewName}')); // include the module configuration // loaded only once due to the way load() (former import()) works if (is_readable(AgaviConfig::get('core.module_dir') . '/' . $moduleName . '/config/module.xml')) { include_once AgaviConfigCache::checkConfig(AgaviConfig::get('core.module_dir') . '/' . $moduleName . '/config/module.xml'); } else { AgaviConfig::set('modules.' . $lowerModuleName . '.enabled', true); } $moduleAutoload = AgaviConfig::get('core.module_dir') . '/' . $moduleName . '/config/autoload.xml'; if (is_readable($moduleAutoload)) { AgaviConfigCache::load($moduleAutoload); } if (AgaviConfig::get('modules.' . $lowerModuleName . '.enabled')) { $moduleConfigHandlers = AgaviConfig::get('core.module_dir') . '/' . $moduleName . '/config/config_handlers.xml'; if (is_readable($moduleConfigHandlers)) { AgaviConfigCache::addConfigHandlersFile($moduleConfigHandlers); } } } if (!AgaviConfig::get('modules.' . $lowerModuleName . '.enabled')) { throw new AgaviDisabledModuleException(sprintf('The module "%1$s" is disabled.', $moduleName)); } // check for a module config.php $moduleConfig = AgaviConfig::get('core.module_dir') . '/' . $moduleName . '/config.php'; if (is_readable($moduleConfig)) { require_once $moduleConfig; } }