3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
29 * Class CRM_Core_Config_Runtime
31 * The runtime describes the environment in which CiviCRM executes -- ie
32 * the DSN, CMS type, CMS URL, etc. Generally, runtime properties must be
33 * determined externally (before loading CiviCRM).
35 class CRM_Core_Config_Runtime
extends CRM_Core_Config_MagicMerge
{
40 * The name of user framework
44 public $userFramework;
46 public $userFrameworkBaseURL;
48 public $userFrameworkClass;
51 * The dsn of the database connection for user framework
55 public $userFrameworkDSN;
58 * The name of user framework url variable name
62 public $userFrameworkURLVar = 'q';
64 public $userFrameworkVersion;
66 public $useFrameworkRelativeBase;
68 public $userHookClass;
71 * Are we generating clean url's and using mod_rewrite
79 public $configAndLogDir;
81 public $templateCompileDir;
84 * The root directory of our template tree.
90 * @param bool $loadFromDB
92 public function initialize($loadFromDB = TRUE) {
93 if (!defined('CIVICRM_DSN') && $loadFromDB) {
94 $this->fatal('You need to define CIVICRM_DSN in civicrm.settings.php');
96 $this->dsn
= defined('CIVICRM_DSN') ? CIVICRM_DSN
: NULL;
98 if (!defined('CIVICRM_TEMPLATE_COMPILEDIR') && $loadFromDB) {
99 $this->fatal('You need to define CIVICRM_TEMPLATE_COMPILEDIR in civicrm.settings.php');
102 if (defined('CIVICRM_TEMPLATE_COMPILEDIR')) {
103 $this->configAndLogDir
= CRM_Utils_File
::baseFilePath() . 'ConfigAndLog' . DIRECTORY_SEPARATOR
;
104 $this->templateCompileDir
= defined('CIVICRM_TEMPLATE_COMPILEDIR') ? CRM_Utils_File
::addTrailingSlash(CIVICRM_TEMPLATE_COMPILEDIR
) : NULL;
105 CRM_Utils_File
::createDir($this->templateCompileDir
);
106 CRM_Utils_File
::restrictAccess($this->templateCompileDir
);
109 $civicrm_private = $GLOBALS['civicrm_paths']['civicrm.private'];
110 if (!empty($civicrm_private)) {
111 $this->configAndLogDir
= rtrim($civicrm_private, DIRECTORY_SEPARATOR
) . DIRECTORY_SEPARATOR
. 'ConfigAndLog' . DIRECTORY_SEPARATOR
;
113 CRM_Utils_File
::createDir($this->configAndLogDir
);
114 CRM_Utils_File
::restrictAccess($this->configAndLogDir
);
116 if (!defined('CIVICRM_UF')) {
117 $this->fatal('You need to define CIVICRM_UF in civicrm.settings.php');
120 $this->userFramework
= CIVICRM_UF
;
121 $this->userFrameworkClass
= 'CRM_Utils_System_' . CIVICRM_UF
;
122 $this->userHookClass
= 'CRM_Utils_Hook_' . CIVICRM_UF
;
124 if (CIVICRM_UF
== 'Joomla') {
125 $this->userFrameworkURLVar
= 'task';
128 if (defined('CIVICRM_UF_DSN')) {
129 $this->userFrameworkDSN
= CIVICRM_UF_DSN
;
132 // this is dynamically figured out in the civicrm.settings.php file
133 if (defined('CIVICRM_CLEANURL')) {
134 $this->cleanURL
= CIVICRM_CLEANURL
;
140 $this->templateDir
= [dirname(dirname(dirname(__DIR__
))) . DIRECTORY_SEPARATOR
. 'templates' . DIRECTORY_SEPARATOR
];
142 $this->initialized
= 1;
146 * Exit processing after a fatal event, outputting the message.
148 * @param string $message
150 private function fatal($message) {
156 * Include custom PHP and template paths
158 public function includeCustomPath() {
159 $customProprtyName = ['customPHPPathDir', 'customTemplateDir'];
160 foreach ($customProprtyName as $property) {
161 $value = $this->getSettings()->get($property);
162 if (!empty($value)) {
163 $customPath = Civi
::paths()->getPath($value);
164 set_include_path($customPath . PATH_SEPARATOR
. get_include_path());
170 * Create a unique identification code for this runtime.
172 * If two requests involve a different hostname, different
173 * port, different DSN, etc., then they should also have a
174 * different runtime ID.
178 public static function getId() {
179 if (!isset(Civi
::$statics[__CLASS__
]['id'])) {
180 Civi
::$statics[__CLASS__
]['id'] = md5(implode(\CRM_Core_DAO
::VALUE_SEPARATOR
, [
181 // e.g. one database, multi URL
182 defined('CIVICRM_DOMAIN_ID') ? CIVICRM_DOMAIN_ID
: 1,
183 // e.g. one codebase, multi database
184 parse_url(CIVICRM_DSN
, PHP_URL_PATH
),
185 // e.g. CMS vs extern vs installer
186 \CRM_Utils_Array
::value('SCRIPT_FILENAME', $_SERVER, ''),
187 // e.g. name-based vhosts
188 \CRM_Utils_Array
::value('HTTP_HOST', $_SERVER, ''),
189 // e.g. port-based vhosts
190 \CRM_Utils_Array
::value('SERVER_PORT', $_SERVER, ''),
191 // Depending on deployment arch, these signals *could* be redundant, but who cares?
194 return Civi
::$statics[__CLASS__
]['id'];