(dev/cloud-native#3) configAndLogDir,templateCompileDir - Move from "Runtime" to...
[civicrm-core.git] / CRM / Core / Config / Runtime.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 * Class CRM_Core_Config_Runtime
30 *
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).
34 */
35 class CRM_Core_Config_Runtime extends CRM_Core_Config_MagicMerge {
36
37 public $dsn;
38
39 /**
40 * The name of user framework
41 *
42 * @var string
43 */
44 public $userFramework;
45
46 public $userFrameworkBaseURL;
47
48 public $userFrameworkClass;
49
50 /**
51 * The dsn of the database connection for user framework
52 *
53 * @var string
54 */
55 public $userFrameworkDSN;
56
57 /**
58 * The name of user framework url variable name
59 *
60 * @var string
61 */
62 public $userFrameworkURLVar = 'q';
63
64 public $userFrameworkVersion;
65
66 public $useFrameworkRelativeBase;
67
68 public $userHookClass;
69
70 /**
71 * Are we generating clean url's and using mod_rewrite
72 * @var string
73 */
74 public $cleanURL;
75
76 /**
77 * The root directory of our template tree.
78 * @var string
79 */
80 public $templateDir;
81
82 /**
83 * @param bool $loadFromDB
84 */
85 public function initialize($loadFromDB = TRUE) {
86 if (!defined('CIVICRM_DSN') && $loadFromDB) {
87 $this->fatal('You need to define CIVICRM_DSN in civicrm.settings.php');
88 }
89 $this->dsn = defined('CIVICRM_DSN') ? CIVICRM_DSN : NULL;
90
91 if (!defined('CIVICRM_TEMPLATE_COMPILEDIR') && $loadFromDB) {
92 $this->fatal('You need to define CIVICRM_TEMPLATE_COMPILEDIR in civicrm.settings.php');
93 }
94
95 if (!defined('CIVICRM_UF')) {
96 $this->fatal('You need to define CIVICRM_UF in civicrm.settings.php');
97 }
98
99 $this->userFramework = CIVICRM_UF;
100 $this->userFrameworkClass = 'CRM_Utils_System_' . CIVICRM_UF;
101 $this->userHookClass = 'CRM_Utils_Hook_' . CIVICRM_UF;
102
103 if (CIVICRM_UF == 'Joomla') {
104 $this->userFrameworkURLVar = 'task';
105 }
106
107 if (defined('CIVICRM_UF_DSN')) {
108 $this->userFrameworkDSN = CIVICRM_UF_DSN;
109 }
110
111 // this is dynamically figured out in the civicrm.settings.php file
112 if (defined('CIVICRM_CLEANURL')) {
113 $this->cleanURL = CIVICRM_CLEANURL;
114 }
115 else {
116 $this->cleanURL = 0;
117 }
118
119 $this->templateDir = [dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR];
120
121 $this->initialized = 1;
122 }
123
124 /**
125 * Exit processing after a fatal event, outputting the message.
126 *
127 * @param string $message
128 */
129 private function fatal($message) {
130 echo $message;
131 exit();
132 }
133
134 /**
135 * Include custom PHP and template paths
136 */
137 public function includeCustomPath() {
138 $customProprtyName = ['customPHPPathDir', 'customTemplateDir'];
139 foreach ($customProprtyName as $property) {
140 $value = $this->getSettings()->get($property);
141 if (!empty($value)) {
142 $customPath = Civi::paths()->getPath($value);
143 set_include_path($customPath . PATH_SEPARATOR . get_include_path());
144 }
145 }
146 }
147
148 /**
149 * Create a unique identification code for this runtime.
150 *
151 * If two requests involve a different hostname, different
152 * port, different DSN, etc., then they should also have a
153 * different runtime ID.
154 *
155 * @return mixed
156 */
157 public static function getId() {
158 if (!isset(Civi::$statics[__CLASS__]['id'])) {
159 Civi::$statics[__CLASS__]['id'] = md5(implode(\CRM_Core_DAO::VALUE_SEPARATOR, [
160 // e.g. one database, multi URL
161 defined('CIVICRM_DOMAIN_ID') ? CIVICRM_DOMAIN_ID : 1,
162 // e.g. one codebase, multi database
163 parse_url(CIVICRM_DSN, PHP_URL_PATH),
164 // e.g. CMS vs extern vs installer
165 \CRM_Utils_Array::value('SCRIPT_FILENAME', $_SERVER, ''),
166 // e.g. name-based vhosts
167 \CRM_Utils_Array::value('HTTP_HOST', $_SERVER, ''),
168 // e.g. port-based vhosts
169 \CRM_Utils_Array::value('SERVER_PORT', $_SERVER, ''),
170 // Depending on deployment arch, these signals *could* be redundant, but who cares?
171 ]));
172 }
173 return Civi::$statics[__CLASS__]['id'];
174 }
175
176 }