UrlMatcher.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. }