diff -u b/core/includes/bootstrap.inc b/core/includes/bootstrap.inc --- b/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -954,16 +954,11 @@ * by this function. Settings should be used over configuration for read-only, * possibly low bootstrap configuration that is environment specific. * - * @param string $name - * The name of the setting to return. - * @param mixed $default - * (optional) The default value to use if this setting is not set. - * - * @return mixed - * The value of the setting, the provided default if not set. + * @return \Drupal\Component\Utility\Settings + * The settings object. */ -function settings_get($name, $default = NULL) { - return Settings::$singleton->get($name, $default); +function settings() { + return Settings::$singleton; } /** @@ -1413,7 +1408,7 @@ // response to reply to a subsequent request for a given URL without // revalidation. If a Vary header has been set in hook_boot(), it is assumed // that the module knows how to cache the page. - if (!isset($hook_boot_headers['vary']) && !settings_get('omit_vary_cookie')) { + if (!isset($hook_boot_headers['vary']) && !settings()->get('omit_vary_cookie')) { header('Vary: Cookie'); } @@ -2142,7 +2137,7 @@ break; case DRUPAL_BOOTSTRAP_SESSION: - require_once DRUPAL_ROOT . '/' . settings_get('session_inc', 'core/includes/session.inc'); + require_once DRUPAL_ROOT . '/' . settings()->get('session_inc', 'core/includes/session.inc'); drupal_session_initialize(); break; @@ -2333,7 +2328,7 @@ require_once DRUPAL_ROOT . '/' . $include; } // Check for a cache mode force from settings.php. - if (settings_get('page_cache_without_database')) { + if (settings()->get('page_cache_without_database')) { $cache_enabled = TRUE; } else { @@ -3038,12 +3033,12 @@ if (!isset($ip_address)) { $ip_address = $_SERVER['REMOTE_ADDR']; - if (settings_get('reverse_proxy', 0)) { - $reverse_proxy_header = settings_get('reverse_proxy_header', 'HTTP_X_FORWARDED_FOR'); + if (settings()->get('reverse_proxy', 0)) { + $reverse_proxy_header = settings()->get('reverse_proxy_header', 'HTTP_X_FORWARDED_FOR'); if (!empty($_SERVER[$reverse_proxy_header])) { // If an array of known reverse proxy IPs is provided, then trust // the XFF header if request really comes from one of them. - $reverse_proxy_addresses = settings_get('reverse_proxy_addresses', array()); + $reverse_proxy_addresses = settings()->get('reverse_proxy_addresses', array()); // Turn XFF header into an array. $forwarded = explode(',', $_SERVER[$reverse_proxy_header]); @@ -3073,10 +3068,15 @@ * classes, interfaces, and traits (PHP 5.4 and later). It's only dependency * is DRUPAL_ROOT. Otherwise it may be called as early as possible. * + * @param $class_loader + * The name of class loader to use. This can be used to change the class + * loader class when calling drupal_classloader() from settings.php. It is + * ignored otherwise. + * * @return Symfony\Component\ClassLoader\UniversalClassLoader * A UniversalClassLoader class instance (or extension thereof). */ -function drupal_classloader() { +function drupal_classloader($class_loader = NULL) { // By default, use the UniversalClassLoader which is best for development, // as it does not break when code is moved on the file system. However, as it // is slow, allow to use the APC class loader in production. @@ -3086,8 +3086,11 @@ // Include the Symfony ClassLoader for loading PSR-0-compatible classes. require_once DRUPAL_ROOT . '/core/vendor/symfony/class-loader/Symfony/Component/ClassLoader/UniversalClassLoader.php'; + if (!isset($class_loader) && class_exists('Drupal\Component\Utility\Settings', FALSE)) { + $class_loader = settings()->get('class_loader'); + } - switch (settings_get('class_loader')) { + switch ($class_loader) { case 'apc': if (function_exists('apc_store')) { require_once DRUPAL_ROOT . '/core/vendor/symfony/class-loader/Symfony/Component/ClassLoader/ApcUniversalClassLoader.php'; diff -u b/core/includes/common.inc b/core/includes/common.inc --- b/core/includes/common.inc +++ b/core/includes/common.inc @@ -809,7 +809,7 @@ $options['timeout'] = (float) $options['timeout']; // Use a proxy if one is defined and the host is not on the excluded list. - $proxy_server = settings_get('proxy_server', ''); + $proxy_server = settings()->get('proxy_server', ''); if ($proxy_server && _drupal_http_use_proxy($uri['host'])) { // Set the scheme so we open a socket to the proxy server. $uri['scheme'] = 'proxy'; @@ -819,13 +819,13 @@ unset($uri['query']); // Add in username and password to Proxy-Authorization header if needed. - if ($proxy_username = settings_get('proxy_username', '')) { - $proxy_password = settings_get('proxy_password', ''); + if ($proxy_username = settings()->get('proxy_username', '')) { + $proxy_password = settings()->get('proxy_password', ''); $options['headers']['Proxy-Authorization'] = 'Basic ' . base64_encode($proxy_username . (!empty($proxy_password) ? ":" . $proxy_password : '')); } // Some proxies reject requests with any User-Agent headers, while others // require a specific one. - $proxy_user_agent = settings_get('proxy_user_agent', ''); + $proxy_user_agent = settings()->get('proxy_user_agent', ''); // The default value matches neither condition. if ($proxy_user_agent === NULL) { unset($options['headers']['User-Agent']); @@ -838,7 +838,7 @@ switch ($uri['scheme']) { case 'proxy': // Make the socket connection to a proxy server. - $socket = 'tcp://' . $proxy_server . ':' . settings_get('proxy_port', 8080); + $socket = 'tcp://' . $proxy_server . ':' . settings()->get('proxy_port', 8080); // The Host header still needs to match the real request. $options['headers']['Host'] = $uri['host']; $options['headers']['Host'] .= isset($uri['port']) && $uri['port'] != 80 ? ':' . $uri['port'] : ''; @@ -1068,7 +1068,7 @@ * TRUE if a proxy should be used for this host. */ function _drupal_http_use_proxy($host) { - $proxy_exceptions = settings_get('proxy_exceptions', array('localhost', '127.0.0.1')); + $proxy_exceptions = settings()->get('proxy_exceptions', array('localhost', '127.0.0.1')); return !in_array(strtolower($host), $proxy_exceptions, TRUE); } @@ -4757,10 +4757,10 @@ * Loads code for subsystems and modules, and registers stream wrappers. */ function _drupal_bootstrap_code() { - require_once DRUPAL_ROOT . '/' . settings_get('path_inc', 'core/includes/path.inc'); + require_once DRUPAL_ROOT . '/' . settings()->get('path_inc', 'core/includes/path.inc'); require_once DRUPAL_ROOT . '/core/includes/theme.inc'; require_once DRUPAL_ROOT . '/core/includes/pager.inc'; - require_once DRUPAL_ROOT . '/' . settings_get('menu_inc', 'core/includes/menu.inc'); + require_once DRUPAL_ROOT . '/' . settings()->get('menu_inc', 'core/includes/menu.inc'); require_once DRUPAL_ROOT . '/core/includes/tablesort.inc'; require_once DRUPAL_ROOT . '/core/includes/file.inc'; require_once DRUPAL_ROOT . '/core/includes/unicode.inc'; diff -u b/core/includes/database.inc b/core/includes/database.inc --- b/core/includes/database.inc +++ b/core/includes/database.inc @@ -905,7 +905,7 @@ // Five minutes is long enough to allow the slave to break and resume // interrupted replication without causing problems on the Drupal site from // the old data. - $duration = settings_get('maximum_replication_lag', 300); + $duration = settings()->get('maximum_replication_lag', 300); // Set session variable with amount of time to delay before using slave. $_SESSION['ignore_slave_server'] = REQUEST_TIME + $duration; } diff -u b/core/includes/install.core.inc b/core/includes/install.core.inc --- b/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -279,7 +279,7 @@ require_once DRUPAL_ROOT . '/core/includes/file.inc'; require_once DRUPAL_ROOT . '/core/includes/install.inc'; require_once DRUPAL_ROOT . '/core/includes/schema.inc'; - require_once DRUPAL_ROOT . '/' . settings_get('path_inc', 'core/includes/path.inc'); + require_once DRUPAL_ROOT . '/' . settings()->get('path_inc', 'core/includes/path.inc'); // Load module basics (needed for hook invokes). include_once DRUPAL_ROOT . '/core/includes/module.inc'; diff -u b/core/includes/theme.maintenance.inc b/core/includes/theme.maintenance.inc --- b/core/includes/theme.maintenance.inc +++ b/core/includes/theme.maintenance.inc @@ -22,7 +22,7 @@ return; } - require_once DRUPAL_ROOT . '/' . settings_get('path_inc', 'core/includes/path.inc'); + require_once DRUPAL_ROOT . '/' . settings()->get('path_inc', 'core/includes/path.inc'); require_once DRUPAL_ROOT . '/core/includes/theme.inc'; require_once DRUPAL_ROOT . '/core/includes/common.inc'; require_once DRUPAL_ROOT . '/core/includes/unicode.inc'; diff -u b/core/lib/Drupal/Component/Utility/Settings.php b/core/lib/Drupal/Component/Utility/Settings.php --- b/core/lib/Drupal/Component/Utility/Settings.php +++ b/core/lib/Drupal/Component/Utility/Settings.php @@ -5,14 +5,60 @@ class Settings { + /** + * @var array + */ protected $storage; + + /** + * @var Settings + */ static $singleton; + + /** + * @param array $settings + */ function __construct(array $settings) { $this->storage = $settings; self::$singleton = $this; } + + /** + * Trying to set a property is not allowed. + * + * @param $name + * @param $value + * @throws \Exception + */ function __set($name, $value) { throw new \Exception('Nope.'); } - function get($name, $default = NULL) { + + /** + * Returns a setting. + * + * Settings can be set in settings.php in the $settings array and requested + * by this function. Settings should be used over configuration for read-only, + * possibly low bootstrap configuration that is environment specific. + * + * @param string $name + * The name of the setting to return. + * @param mixed $default + * (optional) The default value to use if this setting is not set. + * + * @return mixed + * The value of the setting, the provided default if not set. + */ + public function get($name, $default = NULL) { return isset($this->storage[$name]) ? $this->storage[$name] : $default; } + + /** + * Returns all the settings. This is only used for testing purposes. + * + * @return array + * All the settings. + */ + public function getAll() { + return $this->storage; + } + } diff -u b/core/modules/system/lib/Drupal/system/Tests/Bootstrap/IpAddressTest.php b/core/modules/system/lib/Drupal/system/Tests/Bootstrap/IpAddressTest.php --- b/core/modules/system/lib/Drupal/system/Tests/Bootstrap/IpAddressTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Bootstrap/IpAddressTest.php @@ -58,14 +58,14 @@ ); // Proxy forwarding on but no proxy addresses defined. - $GLOBALS['settings']['reverse_proxy'] = 1; + $this->settingsSet('reverse_proxy', 1); $this->assertTrue( ip_address() == $this->remote_ip, 'Proxy forwarding without trusted proxies got remote IP address.' ); // Proxy forwarding on and proxy address not trusted. - $GLOBALS['settings']['reverse_proxy_addresses'] = array($this->proxy_ip, $this->proxy2_ip); + $this->settingsSet('reverse_proxy_addresses', array($this->proxy_ip, $this->proxy2_ip)); drupal_static_reset('ip_address'); $_SERVER['REMOTE_ADDR'] = $this->untrusted_ip; $this->assertTrue( @@ -92,7 +92,7 @@ ); // Custom client-IP header. - $GLOBALS['settings']['reverse_proxy_header'] = 'HTTP_X_CLUSTER_CLIENT_IP'; + $this->settingsSet('reverse_proxy_header', 'HTTP_X_CLUSTER_CLIENT_IP'); $_SERVER['HTTP_X_CLUSTER_CLIENT_IP'] = $this->cluster_ip; drupal_static_reset('ip_address'); $this->assertTrue( diff -u b/core/modules/system/system.install b/core/modules/system/system.install --- b/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -416,7 +416,7 @@ // Verify the update.php access setting if ($phase == 'runtime') { - if (settings_get('update_free_access')) { + if (settings()->get('update_free_access')) { $requirements['update access'] = array( 'value' => $t('Not protected'), 'severity' => REQUIREMENT_ERROR, diff -u b/core/update.php b/core/update.php --- b/core/update.php +++ b/core/update.php @@ -209,7 +209,7 @@ $output .= '
'; } - if (settings_get('update_free_access')) { + if (settings()->get('update_free_access')) { $output .= "Reminder: don't forget to set the \$settings['update_free_access'] value in your settings.php file back to FALSE.