Test Failed
Push — master ( 8c47c2...3acf9f )
by Steve
12:37
created

engine/lib/configuration.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Elgg configuration procedural code.
4
 *
5
 * Includes functions for manipulating the configuration values stored in the database
6
 * Plugin authors should use the {@link elgg_get_config()}, {@link elgg_set_config()},
7
 * {@link elgg_save_config()}, and {@elgg_remove_config()} functions to access or update
8
 * config values.
9
 *
10
 * Elgg's configuration is split among 1 table and 1 file:
11
 * - dbprefix_config
12
 * - engine/settings.php (See {@link settings.example.php})
13
 *
14
 * Upon system boot, all values in dbprefix_config are read into $CONFIG.
15
 */
16
17
use Elgg\Filesystem\Directory;
0 ignored issues
show
This use statement conflicts with another class in this namespace, Directory.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
18
19
/**
20
 * Get the URL for the current (or specified) site
21
 *
22
 * @return string
23
 * @since 1.8.0
24
 */
25
function elgg_get_site_url() {
26 220
	return _elgg_services()->config->wwwroot;
27
}
28
29
/**
30
 * Get the plugin path for this installation
31
 *
32
 * @return string
33
 * @since 1.8.0
34
 */
35
function elgg_get_plugins_path() {
36
	return _elgg_services()->config->pluginspath;
37
}
38
39
/**
40
 * Get the data directory path for this installation
41
 *
42
 * @return string
43
 * @since 1.8.0
44
 */
45
function elgg_get_data_path() {
46
	return _elgg_services()->config->getDataPath();
47
}
48
49
/**
50
 * Get the cache directory path for this installation.
51
 *
52
 * If not set in settings.php, the data path will be returned.
53
 *
54
 * @return string
55
 */
56
function elgg_get_cache_path() {
57 1
	return _elgg_services()->config->getCachePath();
58
}
59
60
/**
61
 * Get the root directory path for this installation
62
 *
63
 * Note: This is not the same as the Elgg root! In the Elgg 1.x series, Elgg
64
 * was always at the install root, but as of 2.0, Elgg can be installed as a
65
 * composer dependency, so you cannot assume that it the install root anymore.
66
 *
67
 * @return string
68
 * @since 1.8.0
69
 */
70
function elgg_get_root_path() {
71 1
	return _elgg_services()->config->get('path');
72
}
73
74
/**
75
 * /path/to/elgg/engine
76
 *
77
 * No trailing slash
78
 *
79
 * @return string
80
 */
81
function elgg_get_engine_path() {
82
	return dirname(__DIR__);
83
}
84
85
/**
86
 * Get an Elgg configuration value
87
 *
88
 * @param string $name Name of the configuration value
89
 *
90
 * @return mixed Configuration value or null if it does not exist
91
 * @since 1.8.0
92
 */
93
function elgg_get_config($name) {
94 340
	if ($name == 'icon_sizes') {
95
		$msg = 'The config value "icon_sizes" is deprecated. Use elgg_get_icon_sizes()';
96
		elgg_deprecated_notice($msg, '2.2');
97
	}
98
99 340
	return _elgg_config()->$name;
100
}
101
102
/**
103
 * Set an Elgg configuration value
104
 *
105
 * @warning This does not persist the configuration setting. Use elgg_save_config()
106
 *
107
 * @param string $name  Name of the configuration value
108
 * @param mixed  $value Value
109
 *
110
 * @return void
111
 * @since 1.8.0
112
 */
113
function elgg_set_config($name, $value) {
114 14
	_elgg_config()->$name = $value;
115 14
}
116
117
/**
118
 * Save a configuration setting
119
 *
120
 * @param string $name  Configuration name (cannot be greater than 255 characters)
121
 * @param mixed  $value Configuration value. Should be string for installation setting
122
 *
123
 * @return bool
124
 * @since 1.8.0
125
 */
126
function elgg_save_config($name, $value) {
127
	return _elgg_config()->save($name, $value);
128
}
129
130
/**
131
 * Removes a config setting.
132
 *
133
 * @param string $name The name of the field.
134
 *
135
 * @return bool Success or failure
136
 */
137
function elgg_remove_config($name) {
138
	return _elgg_config()->remove($name);
139
}
140
141
/**
142
 * @access private
143
 */
144
function _elgg_config_test($hook, $type, $tests) {
145
	$tests[] = \Elgg\Application::elggDir()->getPath("engine/tests/ElggCoreConfigTest.php");
146
	return $tests;
147
}
148
149
/**
150
 * Returns a configuration array of icon sizes
151
 *
152
 * @param string $entity_type    Entity type
153
 * @param string $entity_subtype Entity subtype
154
 * @param string $type           The name of the icon. e.g., 'icon', 'cover_photo'
155
 * @return array
156
 */
157
function elgg_get_icon_sizes($entity_type = null, $entity_subtype = null, $type = 'icon') {
158
	return _elgg_services()->iconService->getSizes($entity_type, $entity_subtype, $type);
159
}
160
161
return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) {
162
	$hooks->registerHandler('unit_test', 'system', '_elgg_config_test');
163
};
164