Drupal investigation

UrlMatcher.php 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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\NestedMatcher;
  11. use Symfony\Component\Routing\Route;
  12. use Symfony\Component\Routing\RouteCollection;
  13. use Symfony\Component\Routing\Matcher\UrlMatcher as SymfonyUrlMatcher;
  14. use Symfony\Component\HttpFoundation\Request;
  15. use Symfony\Component\Routing\RequestContext;
  16. use Symfony\Cmf\Component\Routing\RouteObjectInterface;
  17. /**
  18. * Extended UrlMatcher to provide an additional interface and enhanced features.
  19. *
  20. * This class requires Symfony 2.2 for a refactoring done to the symfony UrlMatcher
  21. *
  22. * @author Larry Garfield
  23. */
  24. class UrlMatcher extends SymfonyUrlMatcher implements FinalMatcherInterface
  25. {
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function finalMatch(RouteCollection $collection, Request $request)
  30. {
  31. $this->routes = $collection;
  32. $context = new RequestContext();
  33. $context->fromRequest($request);
  34. $this->setContext($context);
  35. return $this->match($request->getPathInfo());
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. protected function getAttributes(Route $route, $name, array $attributes)
  41. {
  42. if ($route instanceof RouteObjectInterface && is_string($route->getRouteKey())) {
  43. $name = $route->getRouteKey();
  44. }
  45. $attributes[RouteObjectInterface::ROUTE_NAME] = $name;
  46. $attributes[RouteObjectInterface::ROUTE_OBJECT] = $route;
  47. return $this->mergeDefaults($attributes, $route->getDefaults());
  48. }
  49. }