You are here

abstract class AbstractEventVariables in Hook Event Dispatcher 8.2

Same name and namespace in other branches
  1. 3.x modules/preprocess_event_dispatcher/src/Variables/AbstractEventVariables.php \Drupal\preprocess_event_dispatcher\Variables\AbstractEventVariables

Class AbstractEventVariables.

Plugin annotation

@SuppressWarnings(PHPMD . NumberOfChildren);

Hierarchy

Expanded class hierarchy of AbstractEventVariables

6 files declare their use of AbstractEventVariables
AbstractPreprocessEvent.php in modules/preprocess_event_dispatcher/src/Event/AbstractPreprocessEvent.php
ExampleEventVariables.php in examples/preprocess_example_module/src/Variables/ExampleEventVariables.php
FakeEventVariables.php in modules/preprocess_event_dispatcher/tests/src/Unit/Helpers/FakeEventVariables.php
OtherEventVariablesTest.php in modules/preprocess_event_dispatcher/tests/src/Unit/OtherEventVariablesTest.php
PreprocessEntityEventInterface.php in modules/preprocess_event_dispatcher/src/Event/PreprocessEntityEventInterface.php

... See full list

File

modules/preprocess_event_dispatcher/src/Variables/AbstractEventVariables.php, line 12

Namespace

Drupal\preprocess_event_dispatcher\Variables
View source
abstract class AbstractEventVariables {

  /**
   * Variables.
   *
   * @var array
   */
  protected $variables;

  /**
   * Event Variables constructor.
   *
   * @param array $variables
   *   Event variables.
   */
  public function __construct(array &$variables) {
    $this->variables =& $variables;
  }

  /**
   * Get a variable with a given name, return default if it does not exist.
   *
   * @param string $name
   *   Variable name.
   * @param mixed|null $default
   *   Default value.
   *
   * @return mixed
   *   Value for variable BY VALUE.
   */
  public function get(string $name, $default = NULL) {
    return array_key_exists($name, $this->variables) ? $this->variables[$name] : $default;
  }

  /**
   * Set a variable to a given value.
   *
   * @param string $name
   *   Variable name.
   * @param mixed $value
   *   Variable value.
   */
  public function set(string $name, $value = NULL) : void {
    $this->variables[$name] = $value;
  }

  /**
   * Remove a given variable.
   *
   * @param string $name
   *   Variable name.
   */
  public function remove(string $name) : void {
    unset($this->variables[$name]);
  }

  /**
   * Get a variable with a given name by reference.
   *
   * @param string $name
   *   Variable name.
   *
   * @return mixed
   *   Reference for the variable.
   */
  public function &getByReference(string $name) {
    return $this->variables[$name];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AbstractEventVariables::$variables protected property Variables.
AbstractEventVariables::get public function Get a variable with a given name, return default if it does not exist. 1
AbstractEventVariables::getByReference public function Get a variable with a given name by reference. 1
AbstractEventVariables::remove public function Remove a given variable. 1
AbstractEventVariables::set public function Set a variable to a given value. 1
AbstractEventVariables::__construct public function Event Variables constructor.