Merge pull request #16541 from bhahumanists/subtype-issue-991
[civicrm-core.git] / CRM / Core / Config / Runtime.php
CommitLineData
c0a1f187
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
c0a1f187 5 | |
bc77d7c0
TO
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 |
c0a1f187
TO
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 */
1b81ed50 19class CRM_Core_Config_Runtime extends CRM_Core_Config_MagicMerge {
c0a1f187
TO
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
606999ec
TO
48 public $userFrameworkVersion;
49
c0a1f187
TO
50 public $useFrameworkRelativeBase;
51
52 public $userHookClass;
53
c0a1f187
TO
54 /**
55 * Are we generating clean url's and using mod_rewrite
56 * @var string
57 */
58 public $cleanURL;
59
c0a1f187
TO
60 /**
61 * The root directory of our template tree.
62 * @var string
63 */
64 public $templateDir;
65
c0a1f187
TO
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
c0a1f187
TO
75 if (!defined('CIVICRM_UF')) {
76 $this->fatal('You need to define CIVICRM_UF in civicrm.settings.php');
77 }
c0a1f187 78
d4330c62
TO
79 $this->userFramework = CIVICRM_UF;
80 $this->userFrameworkClass = 'CRM_Utils_System_' . CIVICRM_UF;
81 $this->userHookClass = 'CRM_Utils_Hook_' . CIVICRM_UF;
c0a1f187 82
d4330c62 83 if (CIVICRM_UF == 'Joomla') {
c0a1f187
TO
84 $this->userFrameworkURLVar = 'task';
85 }
86
c0a1f187
TO
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 }
d4330c62 98
be2fb01f 99 $this->templateDir = [dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR];
d4330c62 100
d4330c62 101 $this->initialized = 1;
c0a1f187
TO
102 }
103
f2ac86d1 104 /**
105 * Exit processing after a fatal event, outputting the message.
106 *
107 * @param string $message
108 */
c0a1f187
TO
109 private function fatal($message) {
110 echo $message;
111 exit();
112 }
113
1b81ed50 114 /**
115 * Include custom PHP and template paths
116 */
117 public function includeCustomPath() {
be2fb01f 118 $customProprtyName = ['customPHPPathDir', 'customTemplateDir'];
1b81ed50 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
83617886
TO
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'])) {
be2fb01f 139 Civi::$statics[__CLASS__]['id'] = md5(implode(\CRM_Core_DAO::VALUE_SEPARATOR, [
518fa0ee
SL
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 // e.g. CMS vs extern vs installer
145 \CRM_Utils_Array::value('SCRIPT_FILENAME', $_SERVER, ''),
146 // e.g. name-based vhosts
147 \CRM_Utils_Array::value('HTTP_HOST', $_SERVER, ''),
148 // e.g. port-based vhosts
149 \CRM_Utils_Array::value('SERVER_PORT', $_SERVER, ''),
c1e9641d
TO
150 // e.g. unit testing
151 defined('CIVICRM_TEST') ? 1 : 0,
83617886 152 // Depending on deployment arch, these signals *could* be redundant, but who cares?
be2fb01f 153 ]));
83617886
TO
154 }
155 return Civi::$statics[__CLASS__]['id'];
156 }
157
c0a1f187 158}