You are here

RouterBase.php in Drupal 7 to 8/9 Module Upgrader 8

File

src/Routing/RouterBase.php
View source
<?php

namespace Drupal\drupalmoduleupgrader\Routing;

use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\EventDispatcher\EventDispatcher;

/**
 * Base class for RouterInterface implementations.
 */
class RouterBase extends ArrayCollection implements RouterInterface {

  /**
   * @var \Symfony\Component\EventDispatcher\EventDispatcher
   */
  protected $dispatcher;

  /**
   * Constructs a RouterBase.
   */
  public function __construct(array $elements = []) {
    parent::__construct($elements);
    $this->dispatcher = new EventDispatcher();
  }

  /**
   * {@inheritdoc}
   */
  public function addRoute(RouteWrapperInterface $route) {
    $this
      ->set($route
      ->getIdentifier(), $route);
    $this->dispatcher
      ->addListener('router.built', [
      $route,
      'onRouterBuilt',
    ]);
  }

  /**
   * {@inheritdoc}
   */
  public function finalize() {
    $this->dispatcher
      ->dispatch('router.built', new RouterBuiltEvent($this));
  }

}

Classes

Namesort descending Description
RouterBase Base class for RouterInterface implementations.