144 private $initial_values;
149 private $cookies_configured =
false;
154 private $cookies = [];
161 protected $locked_values = [
165 'elgg_settings_file',
178 protected $deprecated = [
179 'elgg_settings_file' =>
'4.3',
181 'pluginspath' =>
'4.3',
182 'site_guid' =>
'4.3',
183 'sitedescription' =>
'4.3',
193 protected $config_defaults = [
194 'allow_phpinfo' =>
false,
195 'authentication_failures_lifetime' => 600,
196 'authentication_failures_limit' => 5,
197 'auto_disable_plugins' =>
true,
198 'batch_run_time_in_secs' => 4,
199 'boot_cache_ttl' => 3600,
200 'bootdata_plugin_settings_limit' => 40,
201 'can_change_username' =>
false,
202 'class_loader_verify_file_existence' =>
true,
203 'comment_box_collapses' =>
true,
204 'comments_group_only' =>
true,
205 'comments_latest_first' =>
true,
206 'comments_max_depth' => 0,
207 'comments_per_page' => 25,
208 'db_query_cache_limit' => 50,
209 'default_limit' => 10,
210 'elgg_maintenance_mode' =>
false,
211 'email_html_part' =>
true,
212 'email_html_part_images' =>
'no',
213 'email_subject_limit' => 998,
214 'enable_delayed_email' =>
true,
215 'friendly_time_number_of_days' => 30,
217 'topbar' => [
'w' => 16,
'h' => 16,
'square' =>
true,
'upscale' =>
true],
218 'tiny' => [
'w' => 25,
'h' => 25,
'square' =>
true,
'upscale' =>
true],
219 'small' => [
'w' => 40,
'h' => 40,
'square' =>
true,
'upscale' =>
true],
220 'medium' => [
'w' => 100,
'h' => 100,
'square' =>
true,
'upscale' =>
true],
221 'large' => [
'w' => 200,
'h' => 200,
'square' =>
true,
'upscale' =>
true],
222 'master' => [
'w' => 10240,
'h' => 10240,
'square' =>
false,
'upscale' =>
false,
'crop' =>
false],
225 'language_detect_from_browser' =>
true,
227 'message_delay' => 6,
228 'min_password_length' => 6,
230 'notifications_max_runtime' => 45,
231 'notifications_queue_delay' => 0,
232 'pagination_behaviour' =>
'ajax-replace',
233 'security_email_require_confirmation' =>
true,
234 'security_email_require_password' =>
true,
235 'security_notify_admins' =>
true,
236 'security_notify_user_password' =>
true,
237 'security_protect_upgrade' =>
true,
238 'session_bound_entity_icons' =>
false,
239 'simplecache_enabled' =>
false,
241 'subresource_integrity_enabled' =>
false,
242 'system_cache_enabled' =>
false,
243 'testing_mode' =>
false,
244 'webp_enabled' =>
true,
245 'who_can_change_language' =>
'everyone',
253 protected $path_properties = [
264 const ENTITY_TYPES = [
'group',
'object',
'site',
'user'];
271 const SENSITIVE_PROPERTIES = [
287 $this->saveInitialValues($values);
289 $this->values = array_merge($this->config_defaults, $values);
292 $this->getCookieConfig();
304 foreach (self::SENSITIVE_PROPERTIES as
$name) {
305 unset($values[$name]);
308 $this->initial_values = $values;
320 public static function factory($settings_path =
'', $try_env =
true) {
323 $settings_path = self::resolvePath($settings_path, $try_env);
325 $config = self::fromFile($settings_path, $reason1);
343 if (!is_file(
$path)) {
344 $reason =
"File $path not present.";
348 if (!is_readable(
$path)) {
349 $reason =
"File $path not readable.";
355 if (isset($GLOBALS[
'CONFIG'])) {
357 $global = $GLOBALS[
'CONFIG'];
358 unset($GLOBALS[
'CONFIG']);
363 Includer::requireFile(
$path);
365 if (empty($GLOBALS[
'CONFIG']->
dataroot)) {
366 $reason =
'The Elgg settings file is missing $CONFIG->dataroot.';
370 if (empty($GLOBALS[
'CONFIG']->
wwwroot)) {
371 $reason =
'The Elgg settings file is missing $CONFIG->wwwroot.';
375 $config =
new self(get_object_vars($GLOBALS[
'CONFIG']));
377 if ($global !== null) {
379 $GLOBALS[
'CONFIG'] = $global;
381 unset($GLOBALS[
'CONFIG']);
384 if (
$config->{
'X-Sendfile-Type'}) {
386 unset(
$config->{
'X-Sendfile-Type'});
388 if (
$config->{
'X-Accel-Mapping'}) {
390 unset(
$config->{
'X-Accel-Mapping'});
405 public static function resolvePath($settings_path =
'', $try_env =
true) {
406 if (!$settings_path) {
407 if ($try_env && !empty($_ENV[
'ELGG_SETTINGS_FILE'])) {
408 $settings_path = $_ENV[
'ELGG_SETTINGS_FILE'];
409 }
else if (!$settings_path) {
410 $settings_path = Paths::settingsFile(Paths::SETTINGS_PHP);
414 return \Elgg\Project\Paths::sanitize($settings_path,
false);
437 return $this->values;
446 if ($this->cookies_configured) {
447 return $this->cookies;
451 if ($this->hasInitialValue(
'cookies')) {
452 $cookies = $this->getInitialValue(
'cookies');
456 if (!isset($cookies[
'session'])) {
457 $cookies[
'session'] = [];
459 $session_defaults = session_get_cookie_params();
460 $session_defaults[
'name'] =
'Elgg';
461 $cookies[
'session'] = array_merge($session_defaults, $cookies[
'session']);
464 if (!isset($cookies[
'remember_me'])) {
465 $cookies[
'remember_me'] = [];
467 $session_defaults[
'name'] =
'elggperm';
468 $session_defaults[
'expire'] = strtotime(
"+30 days");
469 $cookies[
'remember_me'] = array_merge($session_defaults, $cookies[
'remember_me']);
471 $this->cookies = $cookies;
472 $this->cookies_configured =
true;
488 if (array_key_exists(
$name, $this->deprecated)) {
492 if (isset($this->values[
$name])) {
493 return $this->values[
$name];
507 return isset($this->values[
$name]);
517 return $this->initial_values[
$name] ?? null;
528 return isset($this->initial_values[
$name]);
539 elgg_deprecated_notice(__METHOD__ .
'has been deprecated. It is no longer possible to lock config values.',
'4.3');
550 $testing = $this->values[
'testing_mode'] ??
false;
551 return !$testing && in_array(
$name, $this->locked_values) && $this->hasValue(
$name);
564 if ($this->wasWarnedLocked(
$name)) {
568 if (in_array(
$name, $this->path_properties)) {
582 return $this->__get(
$name) !== null;
592 if ($this->wasWarnedLocked(
$name)) {
596 unset($this->values[
$name]);
608 if ($this->wasWarnedLocked(
$name)) {
613 $this->
getLogger()->error(
"The name length for configuration variables cannot be greater than 255");
619 return $this->
remove(
$name);
637 if ($this->wasWarnedLocked(
$name)) {
643 unset($this->values[
$name]);
655 if (!$this->isLocked(
$name)) {
659 $this->
getLogger()->warning(
"The property {$name} is read-only.");
wasWarnedLocked($name)
Log a read-only warning if the name is read-only.
__isset($name)
Handle isset()
A generic parent class for Configuration exceptions.
isLocked($name)
Is this value locked?
if(!isset($CONFIG)) $CONFIG dataroot
The full file path for Elgg data storage.
getInitialValue($name)
Get a value set at construction time.
saveInitialValues(array $values)
Stores the inital values.
__get($name)
Get an Elgg configuration value if it's been set or loaded during the boot process.
elgg_deprecated_notice(string $msg, string $dep_version)
Log a notice about deprecated use of a function, view, etc.
if(!$user||!$user->canDelete()) $name
mergeValues(array $values)
Set an array of values.
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is void
hasInitialValue($name)
Was a value available at construction time? (From settings.php)
__construct(array $values=[])
Constructor.
$config
Advanced site settings, debugging section.
trait Loggable
Enables adding a logger.
hasValue($name)
Test if we have a set value.
lock($name)
Make a value read-only.
__set($name, $value)
Set an Elgg configuration value.
static resolvePath($settings_path= '', $try_env=true)
Resolve settings path.
__unset($name)
Handle unset()
static factory($settings_path= '', $try_env=true)
Build a config from default settings locations.
getLogger()
Returns logger.
getCookieConfig()
Set up and return the cookie configuration array resolved from settings.
static fromFile($path, &$reason= '')
Build a config from a file.
getValues()
Get all values.
_elgg_services()
Get the global service provider.
$CONFIG wwwroot
The installation root URL of the site.
save($name, $value)
Save a configuration setting to the database.