final class Settings

Read only settings that are initialized with the class.

Hierarchy

  • class \Drupal\Component\Utility\Settings

Expanded class hierarchy of Settings

12 files declare their use of Settings
bootstrap.inc in drupal/core/includes/bootstrap.inc
Functions that need to be loaded on every Drupal request.
BootstrapConfigStorageFactory.php in drupal/core/lib/Drupal/Core/Config/BootstrapConfigStorageFactory.php
Contains Drupal\Core\Config\BootstrapConfigStorageFactory.
CacheFactory.php in drupal/core/lib/Drupal/Core/Cache/CacheFactory.php
Contains \Drupal\Core\Cache\CacheFactory.
PathProcessorLanguage.php in drupal/core/modules/language/lib/Drupal/language/HttpKernel/PathProcessorLanguage.php
Contains Drupal\language\HttpKernel\PathProcessorLanguage.
PathProcessorTest.php in drupal/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorTest.php
Contains Drupal\Tests\Core\PathProcessor\PathProcessorTest.

... See full list

20 string references to 'Settings'
aggregator_menu in drupal/core/modules/aggregator/aggregator.module
Implements hook_menu().
book_menu in drupal/core/modules/book/book.module
Implements hook_menu().
core.services.yml in drupal/core/core.services.yml
drupal/core/core.services.yml
DisplayPluginBase::optionsSummary in drupal/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php
Provide the default summary for options in the views UI.
field.schema.yml in drupal/core/modules/field/config/schema/field.schema.yml
drupal/core/modules/field/config/schema/field.schema.yml

... See full list

1 service uses Settings

File

drupal/core/lib/Drupal/Component/Utility/Settings.php, line 13
Contains \Drupal\Component\Utility\Settings.

Namespace

Drupal\Component\Utility
View source
final class Settings {

  /**
   * Array with the settings.
   *
   * @var array
   */
  private $storage = array();

  /**
   * Singleton instance.
   *
   * @var \Drupal\Component\Utility\Settings
   */
  private static $instance;

  /**
   * Returns the settings instance.
   *
   * A singleton is used because this class is used before the container is
   * available.
   *
   * @return \Drupal\Component\Utility\Settings
   */
  public static function getSingleton() {
    return self::$instance;
  }

  /**
   * Constructor.
   *
   * @param array $settings
   *   Array with the settings.
   */
  function __construct(array $settings) {
    $this->storage = $settings;
    self::$instance = $this;
  }

  /**
   * 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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Settings::$instance private static property Singleton instance.
Settings::$storage private property Array with the settings.
Settings::get public function Returns a setting.
Settings::getAll public function Returns all the settings. This is only used for testing purposes.
Settings::getSingleton public static function Returns the settings instance.
Settings::__construct function Constructor.