You are here

final class PreprocessEventFactoryMapper in Hook Event Dispatcher 3.x

Same name and namespace in other branches
  1. 8.2 modules/preprocess_event_dispatcher/src/Service/PreprocessEventFactoryMapper.php \Drupal\preprocess_event_dispatcher\Service\PreprocessEventFactoryMapper

Class PreprocessEventFactoryMapper.

Hierarchy

Expanded class hierarchy of PreprocessEventFactoryMapper

1 file declares its use of PreprocessEventFactoryMapper
YamlDefinitionsLoader.php in modules/preprocess_event_dispatcher/tests/src/Unit/Helpers/YamlDefinitionsLoader.php
1 string reference to 'PreprocessEventFactoryMapper'
preprocess_event_dispatcher.services.yml in modules/preprocess_event_dispatcher/preprocess_event_dispatcher.services.yml
modules/preprocess_event_dispatcher/preprocess_event_dispatcher.services.yml
1 service uses PreprocessEventFactoryMapper
preprocess_event.factory_mapper in modules/preprocess_event_dispatcher/preprocess_event_dispatcher.services.yml
Drupal\preprocess_event_dispatcher\Service\PreprocessEventFactoryMapper

File

modules/preprocess_event_dispatcher/src/Service/PreprocessEventFactoryMapper.php, line 10

Namespace

Drupal\preprocess_event_dispatcher\Service
View source
final class PreprocessEventFactoryMapper {

  /**
   * Map that binds a hook to a factory.
   *
   * @var \Drupal\preprocess_event_dispatcher\Factory\PreprocessEventFactoryInterface[]
   */
  private $hookToFactoryMap = [];

  /**
   * Add Factory to the mapper.
   *
   * @param \Drupal\preprocess_event_dispatcher\Factory\PreprocessEventFactoryInterface $factory
   *   Provided factory to add.
   */
  public function addFactory(PreprocessEventFactoryInterface $factory) : void {
    $hook = $factory
      ->getEventHook();
    $this->hookToFactoryMap[$hook] = $factory;
  }

  /**
   * Get a factory with the provided hook or the default factory.
   *
   * @param string $hook
   *   The hook name.
   *
   * @return \Drupal\preprocess_event_dispatcher\Factory\PreprocessEventFactoryInterface|null
   *   PreprocessEventFactory.
   */
  public function getFactory(string $hook) : ?PreprocessEventFactoryInterface {
    return $this->hookToFactoryMap[$hook] ?? NULL;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PreprocessEventFactoryMapper::$hookToFactoryMap private property Map that binds a hook to a factory.
PreprocessEventFactoryMapper::addFactory public function Add Factory to the mapper.
PreprocessEventFactoryMapper::getFactory public function Get a factory with the provided hook or the default factory.