8 * The `Model` defines the main options and inputs that are used to configure
11 * @property string $srcPath
12 * Path to CiviCRM-core source tree.
13 * Ex: '/var/www/sites/all/modules/civicrm'.
14 * @property string $setupPath
15 * Path to CiviCRM-setup source tree.
16 * Ex: '/var/www/sites/all/modules/civicrm/setup'.
17 * @property string $settingsPath
18 * Ex: '/var/www/sites/default/civicrm.settings.php'.
19 * @property string $templateCompilePath
20 * Ex: '/var/www/sites/default/files/civicrm/templates_c'.
21 * @property string $cms
22 * Ex: 'Backdrop', 'Drupal', 'Drupal8', 'Joomla', 'WordPress'.
23 * @property string $cmsBaseUrl
24 * Ex: 'http://example.org/'.
26 * Ex: ['server'=>'localhost:3306', 'username'=>'admin', 'password'=>'s3cr3t', 'database'=>'mydb']
27 * @property array $cmsDb
28 * Ex: ['server'=>'localhost:3306', 'username'=>'admin', 'password'=>'s3cr3t', 'database'=>'mydb']
29 * @property string $siteKey
30 * Ex: 'abcd1234ABCD9876'.
31 * @property string[] $credKeys
32 * Ex: ['::abcd1234ABCD9876'].
33 * @property string[] $signKeys
34 * Ex: ['jwt-hs256::abcd1234ABCD9876'].
35 * @property string|NULL $lang
36 * The language of the default dataset.
38 * @property bool $loadGenerated
39 * UNSUPPORTED: Load example dataset (in lieu of the standard dataset).
40 * This was copied-in from the previous installer code, but it should probably be
42 * @property array $components
43 * Ex: ['CiviMail', 'CiviContribute', 'CiviEvent', 'CiviMember', 'CiviReport']
44 * @property array $extensions
45 * Ex: ['org.civicrm.flexmailer', 'org.civicrm.shoreditch'].
46 * @property array $paths
47 * List of hard-coded path-overrides.
48 * Ex: ['wp.frontend.base'=>['url'=>'http://example.org/']].
49 * @property array $settings
50 * List of domain settings to apply.
51 * These are defaults during installation; they could be changed by the admin post-install via GUI or API.
52 * Ex: ['ajaxPopupsEnabled' => 0].
53 * @property array $mandatorySettings
54 * List of hard-coded setting-overrides.
55 * These are mandatory settings which are hard-coded into the config file. Changing requires editing the file.
56 * This makes sense for path/URL settings that are generally system-local and not migrated between dev/prod/etc.
57 * Ex: ['ajaxPopupsEnabled' => 0].
58 * @property array $extras
59 * Open-ended list of private, adhoc fields/flags/tags.
60 * Keys should be prefixed based on which plugin manages the field.
61 * Values must only be scalars (bool/int/string) and arrays.
62 * Ex: ['opt-in.version-check' => TRUE].
66 protected $sorted = FALSE;
67 protected $fields = array();
68 protected $values = array();
70 public function __construct() {
71 $this->addField(array(
72 'description' => 'Local path of the CiviCRM-core tree',
76 $this->addField(array(
77 'description' => 'Local path of the CiviCRM-setup tree',
78 'name' => 'setupPath',
81 $this->addField(array(
82 'description' => 'Local path to civicrm.settings.php',
83 'name' => 'settingsPath',
86 $this->addField(array(
87 'description' => 'Local path to the PHP compilation cache',
88 'name' => 'templateCompilePath',
91 $this->addField(array(
92 'description' => 'Symbolic name of the CMS/user-framework',
96 $this->addField(array(
97 'description' => 'The CMS base URL',
98 'name' => 'cmsBaseUrl',
101 $this->addField(array(
102 'description' => 'Credentials for Civi database',
106 $this->addField(array(
107 'description' => 'Credentials for CMS database',
111 $this->addField(array(
112 'description' => 'Site key',
116 $this->addField(array(
117 'description' => 'Credential encryption keys',
118 'name' => 'credKeys',
121 $this->addField(array(
122 'description' => 'Signing keys',
123 'name' => 'signKeys',
126 $this->addField(array(
127 'description' => 'Load example data',
128 'name' => 'loadGenerated',
131 $this->addField(array(
132 'description' => 'Language',
135 'options' => array(),
137 $this->addField(array(
138 'description' => 'List of CiviCRM components to enable',
139 'name' => 'components',
143 $this->addField(array(
144 'description' => 'List of CiviCRM extensions to enable',
145 'name' => 'extensions',
149 $this->addField(array(
150 'description' => 'List of mandatory path overrides.',
155 $this->addField(array(
156 'description' => 'List of setting overrides.',
157 'name' => 'settings',
161 $this->addField(array(
162 'description' => 'List of mandatory settings',
163 'name' => 'mandatorySettings',
167 $this->addField(array(
168 'description' => 'Open-ended list of private, adhoc fields/flags/tags',
176 * @param array $field
178 * - description: string
179 * - type: string. One of "checkbox", "string".
180 * - weight: int. (Default: 0)
181 * - visible: bool. (Default: TRUE)
182 * - value: mixed. (Default: NULL)
185 public function addField($field) {
190 $field = array_merge($defaults, $field);
192 if (array_key_exists('value', $field) ||
!array_key_exists($field['name'], $this->values
)) {
193 $this->values
[$field['name']] = $field['value'] ??
NULL;
194 unset($field['value']);
197 $this->fields
[$field['name']] = $field;
199 $this->sorted
= FALSE;
203 public function setField($field, $property, $value) {
204 $this->fields
[$field][$property] = $value;
209 * @param string $field
210 * The name of the field.
211 * Ex: 'cmsDb', 'lang'.
212 * @param string $property
213 * A specific property of the field to load.
214 * Ex: 'name', 'description', 'type', 'options'.
217 public function getField($field, $property = NULL) {
219 return $this->fields
[$field][$property] ??
NULL;
222 return $this->fields
[$field] ??
NULL;
226 public function getFields() {
227 if (!$this->sorted
) {
228 uasort($this->fields
, function ($a, $b) {
229 if ($a['weight'] < $b['weight']) {
232 if ($a['weight'] > $b['weight']) {
235 return strcmp($a['name'], $b['name']);
238 return $this->fields
;
242 * Set the values of multiple fields.
244 * @param array $values
245 * Ex: array('root' => '/var/www/sites/default/files/civicrm')
248 public function setValues($values) {
249 foreach ($values as $key => $value) {
250 $this->values
[$key] = $value;
255 public function getValues() {
256 return $this->values
;
259 public function &__get($name) {
260 return $this->values
[$name];
263 public function __set($name, $value) {
264 $this->values
[$name] = $value;
267 public function __isset($name) {
268 return isset($this->values
[$name]);
271 public function __unset($name) {
272 unset($this->values
[$name]);