vendor/silex/silex/src/Silex/Provider/Routing/LazyRequestMatcher.php line 53

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Silex framework.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  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 Silex\Provider\Routing;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\Routing\Matcher\RequestMatcherInterface;
  13. use Symfony\Component\Routing\Matcher\UrlMatcherInterface;
  14. /**
  15.  * Implements a lazy UrlMatcher.
  16.  *
  17.  * @author Igor Wiedler <igor@wiedler.ch>
  18.  * @author Jérôme Tamarelle <jerome@tamarelle.net>
  19.  */
  20. class LazyRequestMatcher implements RequestMatcherInterface
  21. {
  22.     private $factory;
  23.     public function __construct(\Closure $factory)
  24.     {
  25.         $this->factory $factory;
  26.     }
  27.     /**
  28.      * Returns the corresponding RequestMatcherInterface instance.
  29.      *
  30.      * @return UrlMatcherInterface
  31.      */
  32.     public function getRequestMatcher()
  33.     {
  34.         $matcher call_user_func($this->factory);
  35.         if (!$matcher instanceof RequestMatcherInterface) {
  36.             throw new \LogicException("Factory supplied to LazyRequestMatcher must return implementation of Symfony\Component\Routing\RequestMatcherInterface.");
  37.         }
  38.         return $matcher;
  39.     }
  40.     /**
  41.      * {@inheritdoc}
  42.      */
  43.     public function matchRequest(Request $request)
  44.     {
  45.         return $this->getRequestMatcher()->matchRequest($request);
  46.     }
  47. }