Merge pull request #21644 from sunilpawar/processed_token
[civicrm-core.git] / CRM / Core / Config / Runtime.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 +--------------------------------------------------------------------+
10 */
11
12 /**
13 * Class CRM_Core_Config_Runtime
14 *
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).
18 */
19 class CRM_Core_Config_Runtime extends CRM_Core_Config_MagicMerge {
20
21 public $dsn;
22
23 /**
24 * The name of user framework
25 *
26 * @var string
27 */
28 public $userFramework;
29
30 public $userFrameworkBaseURL;
31
32 public $userFrameworkClass;
33
34 /**
35 * The dsn of the database connection for user framework
36 *
37 * @var string
38 */
39 public $userFrameworkDSN;
40
41 /**
42 * The name of user framework url variable name
43 *
44 * @var string
45 */
46 public $userFrameworkURLVar = 'q';
47
48 public $userFrameworkVersion;
49
50 public $useFrameworkRelativeBase;
51
52 public $userHookClass;
53
54 /**
55 * Are we generating clean url's and using mod_rewrite
56 * @var string
57 */
58 public $cleanURL;
59
60 /**
61 * The root directory of our template tree.
62 * @var string
63 */
64 public $templateDir;
65
66 /**
67 * @param bool $loadFromDB
68 */
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');
72 }
73 $this->dsn = defined('CIVICRM_DSN') ? CIVICRM_DSN : NULL;
74
75 if (!defined('CIVICRM_UF')) {
76 $this->fatal('You need to define CIVICRM_UF in civicrm.settings.php');
77 }
78
79 $this->userFramework = CIVICRM_UF;
80 $this->userFrameworkClass = 'CRM_Utils_System_' . CIVICRM_UF;
81 $this->userHookClass = 'CRM_Utils_Hook_' . CIVICRM_UF;
82
83 if (CIVICRM_UF == 'Joomla') {
84 $this->userFrameworkURLVar = 'task';
85 }
86
87 if (defined('CIVICRM_UF_DSN')) {
88 $this->userFrameworkDSN = CIVICRM_UF_DSN;
89 }
90
91 // this is dynamically figured out in the civicrm.settings.php file
92 if (defined('CIVICRM_CLEANURL')) {
93 $this->cleanURL = CIVICRM_CLEANURL;
94 }
95 else {
96 $this->cleanURL = 0;
97 }
98
99 $this->templateDir = [dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR];
100
101 $this->initialized = 1;
102 }
103
104 /**
105 * Exit processing after a fatal event, outputting the message.
106 *
107 * @param string $message
108 */
109 private function fatal($message) {
110 echo $message;
111 exit();
112 }
113
114 /**
115 * Include custom PHP and template paths
116 */
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());
124 }
125 }
126 }
127
128 /**
129 * Create a unique identification code for this runtime.
130 *
131 * If two requests involve a different hostname, different
132 * port, different DSN, etc., then they should also have a
133 * different runtime ID.
134 *
135 * @return mixed
136 */
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),
144
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(),
151
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, ''),
158 // e.g. unit testing
159 defined('CIVICRM_TEST') ? 1 : 0,
160 // Depending on deployment arch, these signals *could* be redundant, but who cares?
161 ]));
162 }
163 return Civi::$statics[__CLASS__]['id'];
164 }
165
166 }