You are here

class Variable in Service Container 7.2

Same name in this branch
  1. 7.2 src/Variable.php \Drupal\service_container\Variable
  2. 7.2 lib/Drupal/Component/Utility/Variable.php \Drupal\Component\Utility\Variable
  3. 7.2 modules/providers/service_container_symfony/lib/Symfony/Component/DependencyInjection/Variable.php \Symfony\Component\DependencyInjection\Variable
Same name and namespace in other branches
  1. 7 src/Variable.php \Drupal\service_container\Variable

Provides a injectable version of variable_set() / variable_get().

Note: The main reason why this is not mapped to config is that config has a different thought process: configs + variables inside each config file.

In order to port code from d7 to d8, you would need additional effort here anyway.

@codeCoverageIgnore

Hierarchy

  • class \Drupal\service_container\Variable

Expanded class hierarchy of Variable

1 file declares its use of Variable
Account.php in src/Session/Account.php
Contains \Drupal\service_container\Session\Account.

File

src/Variable.php, line 23
Contains \Drupal\service_container\Variable.

Namespace

Drupal\service_container
View source
class Variable {

  /**
   * The Drupal7 service.
   *
   * @var \Drupal\service_container\Legacy\Drupal7
   */
  protected $drupal7;

  /**
   * Constructs a new Variable instance.
   *
   * @param \Drupal\service_container\Legacy\Drupal7 $drupal7
   *   The Drupal7 service.
   */
  public function __construct(Drupal7 $drupal7) {
    $this->drupal7 = $drupal7;
  }
  public function get($name, $default = NULL) {
    return $this->drupal7
      ->variable_get($name, $default);
  }
  public function set($name, $value) {
    $this->drupal7
      ->variable_set($name, $value);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Variable::$drupal7 protected property The Drupal7 service.
Variable::get public function
Variable::set public function
Variable::__construct public function Constructs a new Variable instance.