3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * Class CRM_Core_Config_Runtime
15 * The runtime describes the environment in which CiviCRM executes -- ie
16 * the DSN, CMS type, CMS URL, etc. Generally, runtime properties must be
17 * determined externally (before loading CiviCRM).
19 class CRM_Core_Config_Runtime
extends CRM_Core_Config_MagicMerge
{
24 * The name of user framework
28 public $userFramework;
30 public $userFrameworkBaseURL;
32 public $userFrameworkClass;
35 * The dsn of the database connection for user framework
39 public $userFrameworkDSN;
42 * The name of user framework url variable name
46 public $userFrameworkURLVar = 'q';
48 public $userFrameworkVersion;
50 public $useFrameworkRelativeBase;
52 public $userHookClass;
55 * Are we generating clean url's and using mod_rewrite
61 * The root directory of our template tree.
67 * @param bool $loadFromDB
69 public function initialize($loadFromDB = TRUE) {
70 if (!defined('CIVICRM_DSN') && $loadFromDB) {
71 $this->fatal('You need to define CIVICRM_DSN in civicrm.settings.php');
73 $this->dsn
= defined('CIVICRM_DSN') ? CIVICRM_DSN
: NULL;
75 if (!defined('CIVICRM_UF')) {
76 $this->fatal('You need to define CIVICRM_UF in civicrm.settings.php');
79 $this->userFramework
= CIVICRM_UF
;
80 $this->userFrameworkClass
= 'CRM_Utils_System_' . CIVICRM_UF
;
81 $this->userHookClass
= 'CRM_Utils_Hook_' . CIVICRM_UF
;
83 if (CIVICRM_UF
== 'Joomla') {
84 $this->userFrameworkURLVar
= 'task';
87 if (defined('CIVICRM_UF_DSN')) {
88 $this->userFrameworkDSN
= CIVICRM_UF_DSN
;
91 // this is dynamically figured out in the civicrm.settings.php file
92 if (defined('CIVICRM_CLEANURL')) {
93 $this->cleanURL
= CIVICRM_CLEANURL
;
99 $this->templateDir
= [dirname(dirname(dirname(__DIR__
))) . DIRECTORY_SEPARATOR
. 'templates' . DIRECTORY_SEPARATOR
];
101 $this->initialized
= 1;
105 * Exit processing after a fatal event, outputting the message.
107 * @param string $message
109 private function fatal($message) {
115 * Include custom PHP and template paths
117 public function includeCustomPath() {
118 $customProprtyName = ['customPHPPathDir', 'customTemplateDir'];
119 foreach ($customProprtyName as $property) {
120 $value = $this->getSettings()->get($property);
121 if (!empty($value)) {
122 $customPath = Civi
::paths()->getPath($value);
123 set_include_path($customPath . PATH_SEPARATOR
. get_include_path());
129 * Create a unique identification code for this runtime.
131 * If two requests involve a different hostname, different
132 * port, different DSN, etc., then they should also have a
133 * different runtime ID.
137 public static function getId() {
138 if (!isset(Civi
::$statics[__CLASS__
]['id'])) {
139 Civi
::$statics[__CLASS__
]['id'] = md5(implode(\CRM_Core_DAO
::VALUE_SEPARATOR
, [
140 // e.g. one database, multi URL
141 defined('CIVICRM_DOMAIN_ID') ? CIVICRM_DOMAIN_ID
: 1,
142 // e.g. one codebase, multi database
143 parse_url(CIVICRM_DSN
, PHP_URL_PATH
),
145 // e.g. when you load a new version of the codebase, use different caches
146 // Note: in principle, the version number is just a proxy for a dozen other signals (new versions of file A, B, C).
147 // Proper caches should reset whenever the underlying signal (file A, B, or C) changes. However, bugs in this
148 // behavior often go un-detected during dev/test. Including the software-version basically mitigates the problem
149 // for sysadmin-workflows - so that such bugs should only impact developer-workflows.
150 \CRM_Utils_System
::version(),
152 // e.g. CMS vs extern vs installer
153 \CRM_Utils_Array
::value('SCRIPT_FILENAME', $_SERVER, ''),
154 // e.g. name-based vhosts
155 \CRM_Utils_Array
::value('HTTP_HOST', $_SERVER, ''),
156 // e.g. port-based vhosts
157 \CRM_Utils_Array
::value('SERVER_PORT', $_SERVER, ''),
159 defined('CIVICRM_TEST') ?
1 : 0,
160 // Depending on deployment arch, these signals *could* be redundant, but who cares?
163 return Civi
::$statics[__CLASS__
]['id'];