Commit d4330c62 authored by totten's avatar totten

Convert $config->userSystem to boot service

parent 83617886
......@@ -389,17 +389,6 @@ class CRM_Core_Config extends CRM_Core_Config_MagicMerge {
return FALSE;
}
/**
* Wrapper function to allow unit tests to switch user framework on the fly.
*
* @param string $userFramework
* One of 'Drupal', 'Joomla', etc.
* @deprecated
*/
public function setUserFramework($userFramework) {
$this->getRuntime()->setUserFramework($userFramework);
}
/**
* Is back office credit card processing enabled for this site - ie are there any installed processors that support
* it?
......
......@@ -86,27 +86,31 @@ class CRM_Core_Config_MagicMerge {
'doNotResetCache' => array('local'),
'inCiviCRM' => array('local'),
'userFrameworkFrontend' => array('local'),
'userPermissionTemp' => array('local'),
// "runtime" properties are computed from define()s, $_ENV, etc.
// See also: CRM_Core_Config_Runtime.
'dsn' => array('runtime'),
'initialized' => array('runtime'),
'userFramework' => array('runtime'),
'userFrameworkBaseURL' => array('runtime'),
'userFrameworkClass' => array('runtime'),
'userFrameworkDSN' => array('runtime'),
'useFrameworkRelativeBase' => array('runtime', 'useFrameworkRelativeBase'),
'userFrameworkURLVar' => array('runtime'),
'userFrameworkVersion' => array('runtime'),
'userPermissionClass' => array('runtime'),
'userPermissionTemp' => array('runtime'),
'userSystem' => array('runtime'),
'userHookClass' => array('runtime'),
'cleanURL' => array('runtime'),
'configAndLogDir' => array('runtime'),
'templateCompileDir' => array('runtime'),
'templateDir' => array('runtime'),
// "boot-svc" properties are critical services needed during init.
// See also: Civi\Core\Container::getBootServices().
'userSystem' => array('boot-svc'),
'userPermissionClass' => array('boot-svc'),
'userFrameworkBaseURL' => array('user-system', 'getAbsoluteBaseURL'),
'userFrameworkVersion' => array('user-system', 'getVersion'),
'useFrameworkRelativeBase' => array('user-system', 'getRelativeBaseURL'), // ugh typo.
// "setting" properties are loaded through the setting layer, esp
// table "civicrm_setting" and global $civicrm_setting.
// See also: Civi::settings().
......@@ -239,10 +243,19 @@ class CRM_Core_Config_MagicMerge {
case 'runtime':
return $this->getRuntime()->{$name};
case 'boot-svc':
$this->cache[$k] = \Civi\Core\Container::getBootService($name);
return $this->cache[$k];
case 'local':
$this->initLocals();
return $this->locals[$name];
case 'user-system':
$userSystem = \Civi\Core\Container::getBootService('userSystem');
$this->cache[$k] = call_user_func(array($userSystem, $name));
return $this->cache[$k];
case 'service':
return \Civi::service($name);
......@@ -271,6 +284,7 @@ class CRM_Core_Config_MagicMerge {
case 'setting-path':
case 'setting-url-abs':
case 'setting-url-rel':
case 'user-system':
case 'runtime':
case 'callback':
// In the past, changes to $config were not persisted automatically.
......@@ -352,6 +366,7 @@ class CRM_Core_Config_MagicMerge {
'doNotResetCache' => 0,
'initialized' => FALSE,
'userFrameworkFrontend' => FALSE,
'userPermissionTemp' => NULL,
);
}
}
......
......@@ -67,25 +67,6 @@ class CRM_Core_Config_Runtime {
public $userHookClass;
public $userPermissionClass;
/**
* Manager for temporary permissions.
* @todo move to container
*
* @var CRM_Core_Permission_Temp
*/
public $userPermissionTemp;
/**
* The connector module for the CMS/UF
* @todo Introduce an interface.
* @todo move to container
*
* @var CRM_Utils_System_Base
*/
public $userSystem;
/**
* Are we generating clean url's and using mod_rewrite
* @var string
......@@ -131,56 +112,19 @@ class CRM_Core_Config_Runtime {
if (!defined('CIVICRM_UF')) {
$this->fatal('You need to define CIVICRM_UF in civicrm.settings.php');
}
$this->setUserFramework(CIVICRM_UF);
$this->templateDir = array(dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR);
if (CRM_Utils_System::isSSL()) {
$this->userSystem->mapConfigToSSL();
}
if (isset($this->customPHPPathDir) && $this->customPHPPathDir) {
set_include_path($this->customPHPPathDir . PATH_SEPARATOR . get_include_path());
}
$this->initialized = 1;
}
public function setUserFramework($userFramework) {
$this->userFramework = $userFramework;
$this->userFrameworkClass = 'CRM_Utils_System_' . $userFramework;
$this->userHookClass = 'CRM_Utils_Hook_' . $userFramework;
$userPermissionClass = 'CRM_Core_Permission_' . $userFramework;
$this->userPermissionClass = new $userPermissionClass();
$class = $this->userFrameworkClass;
$this->userSystem = new $class();
$this->userFramework = CIVICRM_UF;
$this->userFrameworkClass = 'CRM_Utils_System_' . CIVICRM_UF;
$this->userHookClass = 'CRM_Utils_Hook_' . CIVICRM_UF;
if ($userFramework == 'Joomla') {
if (CIVICRM_UF == 'Joomla') {
$this->userFrameworkURLVar = 'task';
}
if (defined('CIVICRM_UF_BASEURL')) {
$this->userFrameworkBaseURL = CRM_Utils_File::addTrailingSlash(CIVICRM_UF_BASEURL, '/');
//format url for language negotiation, CRM-7803
$this->userFrameworkBaseURL = CRM_Utils_System::languageNegotiationURL($this->userFrameworkBaseURL);
if (CRM_Utils_System::isSSL()) {
$this->userFrameworkBaseURL = str_replace('http://', 'https://', $this->userFrameworkBaseURL);
}
$base = parse_url($this->userFrameworkBaseURL);
$this->useFrameworkRelativeBase = $base['path'];
//$this->useFrameworkRelativeBase = empty($base['path']) ? '/' : $base['path'];
}
if (defined('CIVICRM_UF_DSN')) {
$this->userFrameworkDSN = CIVICRM_UF_DSN;
}
$this->userFrameworkVersion = $this->userSystem->getVersion();
// this is dynamically figured out in the civicrm.settings.php file
if (defined('CIVICRM_CLEANURL')) {
$this->cleanURL = CIVICRM_CLEANURL;
......@@ -188,6 +132,14 @@ class CRM_Core_Config_Runtime {
else {
$this->cleanURL = 0;
}
$this->templateDir = array(dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR);
if (isset($this->customPHPPathDir) && $this->customPHPPathDir) {
set_include_path($this->customPHPPathDir . PATH_SEPARATOR . get_include_path());
}
$this->initialized = 1;
}
private function fatal($message) {
......@@ -218,5 +170,4 @@ class CRM_Core_Config_Runtime {
return Civi::$statics[__CLASS__]['id'];
}
}
......@@ -50,6 +50,12 @@ abstract class CRM_Utils_System_Base {
*/
var $supports_form_extensions = FALSE;
public function initialize() {
if (\CRM_Utils_System::isSSL()) {
$this->mapConfigToSSL();
}
}
/**
* Append an additional breadcrumb tag to the existing breadcrumb.
*
......@@ -284,6 +290,33 @@ abstract class CRM_Utils_System_Base {
return 'left';
}
public function getAbsoluteBaseURL() {
if (!defined('CIVICRM_UF_BASEURL')) {
return FALSE;
}
$url = CRM_Utils_File::addTrailingSlash(CIVICRM_UF_BASEURL, '/');
//format url for language negotiation, CRM-7803
$url = $this->languageNegotiationURL($url);
if (CRM_Utils_System::isSSL()) {
$url = str_replace('http://', 'https://', $url);
}
return $url;
}
public function getRelativeBaseURL() {
$absoluteBaseURL = $this->getAbsoluteBaseURL();
if ($absoluteBaseURL === FALSE) {
return FALSE;
}
$parts = parse_url($absoluteBaseURL);
return $parts['path'];
//$this->useFrameworkRelativeBase = empty($base['path']) ? '/' : $base['path'];
}
/**
* Get CMS Version.
*
......
......@@ -74,11 +74,7 @@ class Civi {
* @return \Civi\Core\Paths
*/
public static function paths() {
// Paths must be available before container can boot.
if (!isset(Civi::$statics[__CLASS__]['paths'])) {
Civi::$statics[__CLASS__]['paths'] = new \Civi\Core\Paths();
}
return Civi::$statics[__CLASS__]['paths'];
return \Civi\Core\Container::getBootService('paths');
}
/**
......
......@@ -310,28 +310,52 @@ class Container {
* @throws \CRM_Core_Exception
*/
public static function getBootServices() {
if (!isset(\Civi::$statics['*boot*'])) {
\Civi::$statics['*boot*']['cache.settings'] = array(
if (!isset(\Civi::$statics[__CLASS__])) {
$bootServices = array();
\Civi::$statics[__CLASS__] = &$bootServices;
$config = \CRM_Core_Config::singleton();
$class = $config->userFrameworkClass;
$userSystem = new $class();
$userSystem->initialize();
$userPermissionClass = 'CRM_Core_Permission_' . $config->userFramework;
$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'),
)),
);
\Civi::$statics['*boot*']['settings_manager'] = array(
$bootServices['settings_manager'] = array(
'class' => 'Civi\Core\SettingsManager',
'obj' => new \Civi\Core\SettingsManager(\Civi::$statics['*boot*']['cache.settings']['obj']),
'obj' => new \Civi\Core\SettingsManager($bootServices['cache.settings']['obj']),
);
\Civi::$statics['*boot*']['lockManager'] = array(
$bootServices['lockManager'] = array(
'class' => 'Civi\Core\Lock\LockManager',
'obj' => self::createLockManager(),
);
}
return \Civi::$statics['*boot*'];
return \Civi::$statics[__CLASS__];
}
public static function getBootService($name) {
return \Civi::$statics['*boot*'][$name]['obj'];
return \Civi::$statics[__CLASS__][$name]['obj'];
}
}
......@@ -410,7 +410,6 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
$config = CRM_Core_Config::singleton(TRUE, TRUE); // ugh, performance
// when running unit tests, use mockup user framework
$config->setUserFramework('UnitTests');
$this->hookClass = CRM_Utils_Hook::singleton(TRUE);
// Make sure the DB connection is setup properly
......
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