Further modules included.
[yaffs-website] / web / modules / contrib / drupalmoduleupgrader / src / Routing / RouterBase.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\drupalmoduleupgrader\Converter\Routing\RouterBase.
6  */
7
8 namespace Drupal\drupalmoduleupgrader\Routing;
9
10 use Doctrine\Common\Collections\ArrayCollection;
11 use Symfony\Component\EventDispatcher\EventDispatcher;
12
13 /**
14  * Base class for RouterInterface implementations.
15  */
16 class RouterBase extends ArrayCollection implements RouterInterface {
17
18   /**
19    * @var \Symfony\Component\EventDispatcher\EventDispatcher
20    */
21   protected $dispatcher;
22
23   /**
24    * Constructs a RouterBase.
25    */
26   public function __construct(array $elements = []) {
27     parent::__construct($elements);
28     $this->dispatcher = new EventDispatcher();
29   }
30
31   /**
32    * {@inheritdoc}
33    */
34   public function addRoute(RouteWrapperInterface $route) {
35     $this->set($route->getIdentifier(), $route);
36     $this->dispatcher->addListener('router.built', [ $route, 'onRouterBuilt' ]);
37   }
38
39   /**
40    * {@inheritdoc}
41    */
42   public function finalize() {
43     $this->dispatcher->dispatch('router.built', new RouterBuiltEvent($this));
44   }
45
46 }