You are here

final class PreprocessEventFactoryMapper in Hook Event Dispatcher 8

Class PreprocessEventFactoryMapper.

Hierarchy

Expanded class hierarchy of PreprocessEventFactoryMapper

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

File

src/Service/PreprocessEventFactoryMapper.php, line 10

Namespace

Drupal\hook_event_dispatcher\Service
View source
final class PreprocessEventFactoryMapper {

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

  /**
   * Add Factory to the mapper.
   *
   * @param \Drupal\hook_event_dispatcher\Event\Preprocess\Factory\PreprocessEventFactoryInterface $factory
   *   Provided factory to add.
   */
  public function addFactory(PreprocessEventFactoryInterface $factory) {
    $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\hook_event_dispatcher\Event\Preprocess\Factory\PreprocessEventFactoryInterface|null
   *   PreprocessEventFactory.
   */
  public function getFactory($hook) {
    if (isset($this->hookToFactoryMap[$hook])) {
      return $this->hookToFactoryMap[$hook];
    }
    return 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.