Commit 7f835399 authored by totten's avatar totten

Construct runtime+extensions+container through boot services

parent d4330c62
......@@ -87,15 +87,8 @@ class CRM_Core_Config extends CRM_Core_Config_MagicMerge {
}
self::$_singleton = new CRM_Core_Config();
self::$_singleton->getRuntime()->initialize($loadFromDB);
if ($loadFromDB && self::$_singleton->getRuntime()->dsn) {
CRM_Core_DAO::init(self::$_singleton->getRuntime()->dsn);
}
\Civi\Core\Container::getBootServices();
if ($loadFromDB && self::$_singleton->getRuntime()->dsn) {
CRM_Extension_System::singleton();
\Civi\Core\Container::singleton();
\Civi\Core\Container::boot($loadFromDB);
if ($loadFromDB && self::$_singleton->dsn) {
$domain = \CRM_Core_BAO_Domain::getDomain();
\CRM_Core_BAO_ConfigSetting::applyLocale(\Civi::settings($domain->id), $domain->locales);
......
......@@ -54,7 +54,7 @@ class CRM_Core_Config_MagicMerge {
*/
private $map;
private $runtime, $locals, $settings;
private $locals, $settings;
private $cache = array();
......@@ -103,7 +103,7 @@ class CRM_Core_Config_MagicMerge {
'templateDir' => array('runtime'),
// "boot-svc" properties are critical services needed during init.
// See also: Civi\Core\Container::getBootServices().
// See also: Civi\Core\Container::getBootService().
'userSystem' => array('boot-svc'),
'userPermissionClass' => array('boot-svc'),
......@@ -241,7 +241,7 @@ class CRM_Core_Config_MagicMerge {
return $this->cache[$k];
case 'runtime':
return $this->getRuntime()->{$name};
return \Civi\Core\Container::getBootService('runtime')->{$name};
case 'boot-svc':
$this->cache[$k] = \Civi\Core\Container::getBootService($name);
......@@ -339,16 +339,6 @@ class CRM_Core_Config_MagicMerge {
}
}
/**
* @return CRM_Core_Config_Runtime
*/
protected function getRuntime() {
if ($this->runtime === NULL) {
$this->runtime = new CRM_Core_Config_Runtime();
}
return $this->runtime;
}
/**
* @return \Civi\Core\SettingsBag
*/
......
......@@ -135,6 +135,7 @@ class CRM_Core_Config_Runtime {
$this->templateDir = array(dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR);
// FIXME
if (isset($this->customPHPPathDir) && $this->customPHPPathDir) {
set_include_path($this->customPHPPathDir . PATH_SEPARATOR . get_include_path());
}
......
......@@ -94,8 +94,7 @@ class Civi {
*/
public static function reset() {
self::$statics = array();
Civi\Core\Container::getBootServices();
Civi\Core\Container::singleton(TRUE);
Civi\Core\Container::singleton();
}
/**
......
......@@ -28,22 +28,16 @@ class Container {
const SELF = 'civi_container_factory';
/**
* @var ContainerBuilder
*/
private static $singleton;
/**
* @param bool $reset
* Whether to forcibly rebuild the entire container.
* @return \Symfony\Component\DependencyInjection\TaggedContainerInterface
*/
public static function singleton($reset = FALSE) {
if ($reset || self::$singleton === NULL) {
$c = new self();
self::$singleton = $c->loadContainer();
if ($reset || !isset(\Civi::$statics[__CLASS__]['container'])) {
self::boot(TRUE);
}
return self::$singleton;
return \Civi::$statics[__CLASS__]['container'];
}
/**
......@@ -175,7 +169,10 @@ class Container {
$container->setDefinition('pear_mail', new Definition('Mail'))
->setFactoryClass('CRM_Utils_Mail')->setFactoryMethod('createMailer');
foreach (self::getBootServices() as $bootService => $def) {
if (empty(\Civi::$statics[__CLASS__]['boot'])) {
throw new \RuntimeException("Cannot initialize container. Boot services are undefined.");
}
foreach (\Civi::$statics[__CLASS__]['boot'] as $bootService => $def) {
$container->setDefinition($bootService, new Definition($def['class'], array($bootService)))
->setFactoryClass(__CLASS__)
->setFactoryMethod('getBootService');
......@@ -305,57 +302,70 @@ class Container {
*
* These are services which must be setup *before* the container can operate.
*
* @return array
* Ex: $result['serviceName'] = array('class' => $, 'obj' => $).
* @param bool $loadFromDB
* @throws \CRM_Core_Exception
*/
public static function getBootServices() {
if (!isset(\Civi::$statics[__CLASS__])) {
$bootServices = array();
\Civi::$statics[__CLASS__] = &$bootServices;
public static function boot($loadFromDB) {
$bootServices = array();
\Civi::$statics[__CLASS__]['boot'] = &$bootServices;
$config = \CRM_Core_Config::singleton();
$bootServices['runtime'] = array(
'class' => 'CRM_Core_Config_Runtime',
'obj' => ($runtime = new \CRM_Core_Config_Runtime()),
);
$runtime->initialize($loadFromDB);
$class = $config->userFrameworkClass;
$userSystem = new $class();
$userSystem->initialize();
if ($loadFromDB && $runtime->dsn) {
\CRM_Core_DAO::init($runtime->dsn);
}
$userPermissionClass = 'CRM_Core_Permission_' . $config->userFramework;
$bootServices['paths'] = array(
'class' => 'Civi\Core\Paths',
'obj' => new \Civi\Core\Paths(),
);
$bootServices['paths'] = array(
'class' => 'Civi\Core\Paths',
'obj' => new \Civi\Core\Paths(),
);
$bootServices['userSystem'] = array(
'class' => 'CRM_Utils_Cache_Interface',
'obj' => $userSystem,
);
$bootServices['userPermissionClass'] = array(
// Ugh, silly name.
'class' => 'CRM_Core_Permission_Base',
'obj' => new $userPermissionClass(),
);
$bootServices['cache.settings'] = array(
'class' => 'CRM_Utils_Cache_Interface',
'obj' => \CRM_Utils_Cache::create(array(
'name' => 'settings',
'type' => array('*memory*', 'SqlGroup', 'ArrayCache'),
)),
);
$bootServices['settings_manager'] = array(
'class' => 'Civi\Core\SettingsManager',
'obj' => new \Civi\Core\SettingsManager($bootServices['cache.settings']['obj']),
);
$bootServices['lockManager'] = array(
'class' => 'Civi\Core\Lock\LockManager',
'obj' => self::createLockManager(),
);
$class = $runtime->userFrameworkClass;
$bootServices['userSystem'] = array(
'class' => 'CRM_Utils_Cache_Interface',
'obj' => ($userSystem = new $class()),
);
$userSystem->initialize();
$userPermissionClass = 'CRM_Core_Permission_' . $runtime->userFramework;
$bootServices['userPermissionClass'] = array(
// Ugh, silly name.
'class' => 'CRM_Core_Permission_Base',
'obj' => new $userPermissionClass(),
);
$bootServices['cache.settings'] = array(
'class' => 'CRM_Utils_Cache_Interface',
'obj' => \CRM_Utils_Cache::create(array(
'name' => 'settings',
'type' => array('*memory*', 'SqlGroup', 'ArrayCache'),
)),
);
$bootServices['settings_manager'] = array(
'class' => 'Civi\Core\SettingsManager',
'obj' => new \Civi\Core\SettingsManager($bootServices['cache.settings']['obj']),
);
$bootServices['lockManager'] = array(
'class' => 'Civi\Core\Lock\LockManager',
'obj' => self::createLockManager(),
);
if ($loadFromDB && $runtime->dsn) {
\CRM_Extension_System::singleton(TRUE);
$c = new self();
\Civi::$statics[__CLASS__]['container'] = $c->loadContainer();
}
return \Civi::$statics[__CLASS__];
}
public static function getBootService($name) {
return \Civi::$statics[__CLASS__][$name]['obj'];
return \Civi::$statics[__CLASS__]['boot'][$name]['obj'];
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment