Drupal investigation

RegisterRouteEnhancersPass.php 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /*
  3. * This file is part of the Symfony CMF package.
  4. *
  5. * (c) 2011-2015 Symfony CMF
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Cmf\Component\Routing\DependencyInjection\Compiler;
  11. use Symfony\Component\DependencyInjection\ContainerBuilder;
  12. use Symfony\Component\DependencyInjection\Reference;
  13. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  14. /**
  15. * This compiler pass adds additional route enhancers
  16. * to the dynamic router.
  17. *
  18. * @author Daniel Leech <dan.t.leech@gmail.com>
  19. * @author Nathaniel Catchpole (catch)
  20. */
  21. class RegisterRouteEnhancersPass implements CompilerPassInterface
  22. {
  23. /**
  24. * @var string
  25. */
  26. protected $dynamicRouterService;
  27. protected $enhancerTag;
  28. public function __construct($dynamicRouterService = 'cmf_routing.dynamic_router', $enhancerTag = 'dynamic_router_route_enhancer')
  29. {
  30. $this->dynamicRouterService = $dynamicRouterService;
  31. $this->enhancerTag = $enhancerTag;
  32. }
  33. public function process(ContainerBuilder $container)
  34. {
  35. if (!$container->hasDefinition($this->dynamicRouterService)) {
  36. return;
  37. }
  38. $router = $container->getDefinition($this->dynamicRouterService);
  39. foreach ($container->findTaggedServiceIds($this->enhancerTag) as $id => $attributes) {
  40. $priority = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0;
  41. $router->addMethodCall('addRouteEnhancer', array(new Reference($id), $priority));
  42. }
  43. }
  44. }