140 private $initial_values;
145 private $cookies_configured =
false;
150 private $cookies = [];
157 protected $locked_values = [
171 protected $deprecated = [
179 protected $config_defaults = [
180 'allow_phpinfo' =>
false,
181 'authentication_failures_lifetime' => 600,
182 'authentication_failures_limit' => 5,
183 'auto_disable_plugins' =>
true,
184 'batch_run_time_in_secs' => 4,
185 'boot_cache_ttl' => 3600,
186 'can_change_username' =>
false,
187 'class_loader_verify_file_existence' =>
true,
188 'comment_box_collapses' =>
true,
189 'comments_group_only' =>
true,
190 'comments_latest_first' =>
true,
191 'comments_max_depth' => 0,
192 'comments_per_page' => 25,
193 'db_query_cache_limit' => 50,
194 'default_limit' => 10,
195 'elgg_maintenance_mode' =>
false,
196 'email_html_part' =>
true,
197 'email_html_part_images' =>
'no',
198 'email_subject_limit' => 998,
199 'enable_delayed_email' =>
true,
200 'friendly_time_number_of_days' => 30,
202 'topbar' => [
'w' => 16,
'h' => 16,
'square' =>
true,
'upscale' =>
true],
203 'tiny' => [
'w' => 25,
'h' => 25,
'square' =>
true,
'upscale' =>
true],
204 'small' => [
'w' => 40,
'h' => 40,
'square' =>
true,
'upscale' =>
true],
205 'medium' => [
'w' => 100,
'h' => 100,
'square' =>
true,
'upscale' =>
true],
206 'large' => [
'w' => 200,
'h' => 200,
'square' =>
true,
'upscale' =>
true],
207 'master' => [
'w' => 10240,
'h' => 10240,
'square' =>
false,
'upscale' =>
false,
'crop' =>
false],
210 'language_detect_from_browser' =>
true,
212 'message_delay' => 6,
213 'min_password_length' => 6,
215 'notifications_max_runtime' => 45,
216 'notifications_queue_delay' => 0,
217 'pagination_behaviour' =>
'ajax-replace',
218 'security_email_require_confirmation' =>
true,
219 'security_email_require_password' =>
true,
220 'security_notify_admins' =>
true,
221 'security_notify_user_password' =>
true,
222 'security_protect_upgrade' =>
true,
223 'session_bound_entity_icons' =>
false,
224 'simplecache_enabled' =>
false,
225 'subresource_integrity_enabled' =>
false,
226 'system_cache_enabled' =>
false,
227 'testing_mode' =>
false,
228 'user_joined_river' =>
false,
229 'webp_enabled' =>
true,
230 'who_can_change_language' =>
'everyone',
238 protected $path_properties = [
249 const ENTITY_TYPES = [
'group',
'object',
'site',
'user'];
256 const SENSITIVE_PROPERTIES = [
272 $this->saveInitialValues($values);
274 $this->values = array_merge($this->config_defaults, $values);
277 $this->getCookieConfig();
289 foreach (self::SENSITIVE_PROPERTIES as
$name) {
290 unset($values[$name]);
293 $this->initial_values = $values;
303 public static function factory(
string $settings_path =
''): static {
304 $settings_path = self::resolvePath($settings_path);
306 return self::fromFile($settings_path);
318 if (!is_file(
$path)) {
322 if (!is_readable(
$path)) {
328 if (isset($GLOBALS[
'CONFIG'])) {
330 $global = $GLOBALS[
'CONFIG'];
331 unset($GLOBALS[
'CONFIG']);
336 Includer::requireFile(
$path);
338 if (empty($GLOBALS[
'CONFIG']->
dataroot)) {
339 throw new ConfigurationException(__METHOD__ .
': Reading configs failed: The Elgg settings file is missing $CONFIG->dataroot.');
342 if (empty($GLOBALS[
'CONFIG']->
wwwroot)) {
343 throw new ConfigurationException(__METHOD__ .
': Reading configs failed: The Elgg settings file is missing $CONFIG->wwwroot.');
346 $config =
new self(get_object_vars($GLOBALS[
'CONFIG']));
348 if ($global !== null) {
350 $GLOBALS[
'CONFIG'] = $global;
352 unset($GLOBALS[
'CONFIG']);
355 if (
$config->{
'X-Sendfile-Type'}) {
357 unset(
$config->{
'X-Sendfile-Type'});
360 if (
$config->{
'X-Accel-Mapping'}) {
362 unset(
$config->{
'X-Accel-Mapping'});
375 public static function resolvePath(
string $settings_path =
''): string {
376 if (empty($settings_path)) {
377 $settings_path = Paths::settingsFile(Paths::SETTINGS_PHP);
380 return \Elgg\Project\Paths::sanitize($settings_path,
false);
389 return $this->values;
398 if ($this->cookies_configured) {
399 return $this->cookies;
403 if ($this->hasInitialValue(
'cookies')) {
404 $cookies = $this->getInitialValue(
'cookies');
408 if (!isset($cookies[
'session'])) {
409 $cookies[
'session'] = [];
412 $session_defaults = session_get_cookie_params();
413 $session_defaults[
'name'] =
'Elgg';
414 $cookies[
'session'] = array_merge($session_defaults, $cookies[
'session']);
417 if (!isset($cookies[
'remember_me'])) {
418 $cookies[
'remember_me'] = [];
421 $session_defaults[
'name'] =
'elggperm';
422 $session_defaults[
'expire'] = strtotime(
'+30 days');
423 $cookies[
'remember_me'] = array_merge($session_defaults, $cookies[
'remember_me']);
425 $this->cookies = $cookies;
426 $this->cookies_configured =
true;
442 if (array_key_exists($name, $this->deprecated)) {
446 if (isset($this->values[$name])) {
447 return $this->values[
$name];
461 return isset($this->values[$name]);
471 return $this->initial_values[
$name] ?? null;
482 return isset($this->initial_values[$name]);
493 $testing = $this->values[
'testing_mode'] ??
false;
494 return !$testing && in_array($name, $this->locked_values) && $this->hasValue($name);
507 if ($this->wasWarnedLocked($name)) {
511 if (in_array($name, $this->path_properties)) {
525 return $this->__get($name) !== null;
535 if ($this->wasWarnedLocked($name)) {
539 unset($this->values[$name]);
551 if ($this->wasWarnedLocked($name)) {
555 if (
strlen($name) > 255) {
556 $this->
getLogger()->error(
'The name length for configuration variables cannot be greater than 255');
562 return $this->
remove(
$name);
567 $this->__set($name,
$value);
579 public function remove(
string $name):
bool {
580 if ($this->wasWarnedLocked(
$name)) {
586 unset($this->values[
$name]);
598 if (!$this->isLocked($name)) {
602 $this->
getLogger()->warning(
"The property {$name} is read-only.");
hasInitialValue(string $name)
Was a value available at construction time? (From settings.php)
static resolvePath(string $settings_path= '')
Resolve settings path.
A generic parent class for Configuration exceptions.
if(!isset($CONFIG)) $CONFIG dataroot
The full file path for Elgg data storage.
elgg_deprecated_notice(string $msg, string $dep_version)
Log a notice about deprecated use of a function, view, etc.
saveInitialValues(array $values)
Stores the inital values.
save(string $name, $value)
Save a configuration setting to the database.
if(!$user||!$user->canDelete()) $name
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
wasWarnedLocked(string $name)
Log a read-only warning if the name is read-only.
__get(string $name)
Get an Elgg configuration value if it's been set or loaded during the boot process.
hasValue(string $name)
Test if we have a set value.
__set(string $name, $value)
Set an Elgg configuration value.
__construct(array $values=[])
Constructor.
$config
Advanced site settings, debugging section.
trait Loggable
Enables adding a logger.
static fromFile($path)
Build a config from a file.
__unset(string $name)
Handle unset()
__isset(string $name)
Handle isset()
isLocked(string $name)
Is this value locked?
getLogger()
Returns logger.
getCookieConfig()
Set up and return the cookie configuration array resolved from settings.
getValues()
Get all values.
getInitialValue(string $name)
Get a value set at construction time.
_elgg_services()
Get the global service provider.
$CONFIG wwwroot
The installation root URL of the site.
static factory(string $settings_path= '')
Build a config from default settings locations.