当前位置: 首页>>代码示例>>PHP>>正文


PHP Matcher\UrlMatcherInterface类代码示例

本文整理汇总了PHP中Symfony\Component\Routing\Matcher\UrlMatcherInterface的典型用法代码示例。如果您正苦于以下问题:PHP UrlMatcherInterface类的具体用法?PHP UrlMatcherInterface怎么用?PHP UrlMatcherInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了UrlMatcherInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 /**
  * Constructor.
  *
  * RequestStack will become required in 3.0.
  *
  * @param UrlMatcherInterface|RequestMatcherInterface $matcher      The Url or Request matcher
  * @param RequestStack                                $requestStack A RequestStack instance
  * @param RequestContext|null                         $context      The RequestContext (can be null when $matcher implements RequestContextAwareInterface)
  * @param LoggerInterface|null                        $logger       The logger
  *
  * @throws \InvalidArgumentException
  */
 public function __construct($matcher, $requestStack = null, $context = null, $logger = null)
 {
     if ($requestStack instanceof RequestContext || $context instanceof LoggerInterface || $logger instanceof RequestStack) {
         $tmp = $requestStack;
         $requestStack = $logger;
         $logger = $context;
         $context = $tmp;
         @trigger_error('The ' . __METHOD__ . ' method now requires a RequestStack to be given as second argument as ' . __CLASS__ . '::setRequest method will not be supported anymore in 3.0.', E_USER_DEPRECATED);
     } elseif (!$requestStack instanceof RequestStack) {
         @trigger_error('The ' . __METHOD__ . ' method now requires a RequestStack instance as ' . __CLASS__ . '::setRequest method will not be supported anymore in 3.0.', E_USER_DEPRECATED);
     }
     if (null !== $requestStack && !$requestStack instanceof RequestStack) {
         throw new \InvalidArgumentException('RequestStack instance expected.');
     }
     if (null !== $context && !$context instanceof RequestContext) {
         throw new \InvalidArgumentException('RequestContext instance expected.');
     }
     if (null !== $logger && !$logger instanceof LoggerInterface) {
         throw new \InvalidArgumentException('Logger must implement LoggerInterface.');
     }
     if (!$matcher instanceof UrlMatcherInterface && !$matcher instanceof RequestMatcherInterface) {
         throw new \InvalidArgumentException('Matcher must either implement UrlMatcherInterface or RequestMatcherInterface.');
     }
     if (null === $context && !$matcher instanceof RequestContextAwareInterface) {
         throw new \InvalidArgumentException('You must either pass a RequestContext or the matcher must implement RequestContextAwareInterface.');
     }
     $this->matcher = $matcher;
     $this->context = $context ?: $matcher->getContext();
     $this->requestStack = $requestStack;
     $this->logger = $logger;
 }
开发者ID:Kyra2778,项目名称:AMR,代码行数:43,代码来源:RouterListener.php

示例2: __construct

 public function __construct(Profiler $profiler = null, \Twig_Environment $twig, UrlMatcherInterface $matcher = null, RouteCollection $routes = null)
 {
     $this->profiler = $profiler;
     $this->twig = $twig;
     $this->matcher = $matcher;
     $this->routes = null === $routes && $matcher instanceof RouterInterface ? $matcher->getRouteCollection() : $routes;
 }
开发者ID:Ener-Getick,项目名称:symfony,代码行数:7,代码来源:RouterController.php

示例3:

 function it_throws_an_exception_if_neither_create_nor_update_key_word_has_been_found(Session $session, SymfonyPageInterface $createPage, SymfonyPageInterface $updatePage, UrlMatcherInterface $urlMatcher)
 {
     $session->getCurrentUrl()->willReturn('https://sylius.com/resource/show');
     $urlMatcher->match('/resource/show')->willReturn(['_route' => 'sylius_resource_show']);
     $createPage->getRouteName()->willReturn('sylius_resource_create');
     $updatePage->getRouteName()->willReturn('sylius_resource_update');
     $this->shouldThrow(\LogicException::class)->during('getCurrentPageWithForm', [[$createPage, $updatePage]]);
 }
开发者ID:loic425,项目名称:Sylius,代码行数:8,代码来源:CurrentPageResolverSpec.php

示例4: __construct

 /**
  * Constructor.
  *
  * @param UrlMatcherInterface|RequestMatcherInterface $matcher The Url or Request matcher
  * @param RequestContext|null                         $context The RequestContext (can be null when $matcher implements RequestContextAwareInterface)
  * @param LoggerInterface|null                        $logger  The logger
  *
  * @throws \InvalidArgumentException
  */
 public function __construct($matcher, RequestContext $context = null, LoggerInterface $logger = null)
 {
     if (!$matcher instanceof UrlMatcherInterface && !$matcher instanceof RequestMatcherInterface) {
         throw new \InvalidArgumentException('Matcher must either implement UrlMatcherInterface or RequestMatcherInterface.');
     }
     if (null === $context && !$matcher instanceof RequestContextAwareInterface) {
         throw new \InvalidArgumentException('You must either pass a RequestContext or the matcher must implement RequestContextAwareInterface.');
     }
     $this->matcher = $matcher;
     $this->context = $context ?: $matcher->getContext();
     $this->logger = $logger;
 }
开发者ID:nfabre,项目名称:symfony,代码行数:21,代码来源:RouterListener.php

示例5: setUp

 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $this->configFactory = $this->getConfigFactoryStub(['system.site' => ['page.403' => '/access-denied-page', 'page.404' => '/not-found-page']]);
     $this->kernel = $this->getMock('Symfony\\Component\\HttpKernel\\HttpKernelInterface');
     $this->logger = $this->getMock('Psr\\Log\\LoggerInterface');
     $this->redirectDestination = $this->getMock('\\Drupal\\Core\\Routing\\RedirectDestinationInterface');
     $this->redirectDestination->expects($this->any())->method('getAsArray')->willReturn(['destination' => 'test']);
     $this->accessUnawareRouter = $this->getMock('Symfony\\Component\\Routing\\Matcher\\UrlMatcherInterface');
     $this->accessUnawareRouter->expects($this->any())->method('match')->willReturn(['_controller' => 'mocked']);
     $this->customPageSubscriber = new CustomPageExceptionHtmlSubscriber($this->configFactory, $this->kernel, $this->logger, $this->redirectDestination, $this->accessUnawareRouter);
     // You can't create an exception in PHP without throwing it. Store the
     // current error_log, and disable it temporarily.
     $this->errorLog = ini_set('error_log', file_exists('/dev/null') ? '/dev/null' : 'nul');
 }
开发者ID:sojo,项目名称:d8_friendsofsilence,代码行数:17,代码来源:CustomPageExceptionHtmlSubscriberTest.php

示例6: getMatcher

 /**
  * Gets the UrlMatcher instance associated with this Router.
  *
  * @return UrlMatcherInterface A UrlMatcherInterface instance
  */
 public function getMatcher()
 {
     if (null !== $this->matcher) {
         return $this->matcher;
     }
     if (null === $this->options['cache_dir'] || null === $this->options['matcher_cache_class']) {
         $this->matcher = new $this->options['matcher_class']($this->getRouteCollection(), $this->context);
         if (method_exists($this->matcher, 'addExpressionLanguageProvider')) {
             foreach ($this->expressionLanguageProviders as $provider) {
                 $this->matcher->addExpressionLanguageProvider($provider);
             }
         }
         return $this->matcher;
     }
     $class = $this->options['matcher_cache_class'];
     $baseClass = $this->options['matcher_base_class'];
     $expressionLanguageProviders = $this->expressionLanguageProviders;
     $that = $this;
     // required for PHP 5.3 where "$this" cannot be use()d in anonymous functions. Change in Symfony 3.0.
     $cache = $this->getConfigCacheFactory()->cache($this->options['cache_dir'] . '/' . $class . '.php', function (ConfigCacheInterface $cache) use($that, $class, $baseClass, $expressionLanguageProviders) {
         $dumper = $that->getMatcherDumperInstance();
         if (method_exists($dumper, 'addExpressionLanguageProvider')) {
             foreach ($expressionLanguageProviders as $provider) {
                 $dumper->addExpressionLanguageProvider($provider);
             }
         }
         $options = array('class' => $class, 'base_class' => $baseClass);
         $cache->write($dumper->dump($options), $that->getRouteCollection()->getResources());
     });
     require_once $cache->getPath();
     return $this->matcher = new $class($this->context);
 }
开发者ID:ngitimfoyo,项目名称:Nyari-AppPHP,代码行数:37,代码来源:Router.php

示例7: __construct

 /**
  * Constructor.
  *
  * RequestStack will become required in 3.0.
  *
  * @param UrlMatcherInterface|RequestMatcherInterface $matcher      The Url or Request matcher
  * @param RequestContext|null                         $context      The RequestContext (can be null when $matcher implements RequestContextAwareInterface)
  * @param LoggerInterface|null                        $logger       The logger
  * @param RequestStack|null                           $requestStack A RequestStack instance
  *
  * @throws \InvalidArgumentException
  */
 public function __construct($matcher, RequestContext $context = null, LoggerInterface $logger = null, RequestStack $requestStack = null)
 {
     if (!$matcher instanceof UrlMatcherInterface && !$matcher instanceof RequestMatcherInterface) {
         throw new \InvalidArgumentException('Matcher must either implement UrlMatcherInterface or RequestMatcherInterface.');
     }
     if (null === $context && !$matcher instanceof RequestContextAwareInterface) {
         throw new \InvalidArgumentException('You must either pass a RequestContext or the matcher must implement RequestContextAwareInterface.');
     }
     if (!$requestStack instanceof RequestStack) {
         @trigger_error('The ' . __METHOD__ . ' method now requires a RequestStack instance as ' . __CLASS__ . '::setRequest method will not be supported anymore in 3.0.', E_USER_DEPRECATED);
     }
     $this->matcher = $matcher;
     $this->context = $context ?: $matcher->getContext();
     $this->requestStack = $requestStack;
     $this->logger = $logger;
 }
开发者ID:EnmanuelCode,项目名称:backend-laravel,代码行数:28,代码来源:RouterListener.php

示例8: getMatcher

 /**
  * Gets the UrlMatcher instance associated with this Router.
  *
  * @return UrlMatcherInterface A UrlMatcherInterface instance
  */
 public function getMatcher()
 {
     if (null !== $this->matcher) {
         return $this->matcher;
     }
     if (null === $this->options['cache_dir'] || null === $this->options['matcher_cache_class']) {
         $this->matcher = new $this->options['matcher_class']($this->getRouteCollection(), $this->context);
         if (method_exists($this->matcher, 'addExpressionLanguageProvider')) {
             foreach ($this->expressionLanguageProviders as $provider) {
                 $this->matcher->addExpressionLanguageProvider($provider);
             }
         }
         return $this->matcher;
     }
     $class = $this->options['matcher_cache_class'];
     $cache = new ConfigCache($this->options['cache_dir'] . '/' . $class . '.php', $this->options['debug']);
     if (!$cache->isFresh()) {
         $dumper = $this->getMatcherDumperInstance();
         if (method_exists($dumper, 'addExpressionLanguageProvider')) {
             foreach ($this->expressionLanguageProviders as $provider) {
                 $dumper->addExpressionLanguageProvider($provider);
             }
         }
         $options = array('class' => $class, 'base_class' => $this->options['matcher_base_class']);
         $cache->write($dumper->dump($options), $this->getRouteCollection()->getResources());
     }
     require_once $cache;
     return $this->matcher = new $class($this->context);
 }
开发者ID:EnmanuelCode,项目名称:backend-laravel,代码行数:34,代码来源:Router.php

示例9: setUp

 public function setUp()
 {
     $this->urlMatcher = $this->getMockForAbstractClass(UrlMatcherInterface::class);
     $this->resourceTransformer = $this->getMockForAbstractClass(TransformerInterface::class);
     $this->kernel = $this->getMockForAbstractClass(HttpKernelInterface::class);
     $this->context = $this->getMockBuilder(RequestContext::class)->disableOriginalConstructor()->getMock();
     $this->urlMatcher->method('getContext')->willReturn($this->context);
 }
开发者ID:ibrows,项目名称:rest-bundle,代码行数:8,代码来源:LinkHeaderListenerTest.php

示例10: getMatcher

 /**
  * @return RequestMatcherInterface|UrlMatcherInterface
  */
 public function getMatcher()
 {
     /* we may not set the context in DynamicRouter::setContext as this
      * would lead to symfony cache warmup problems.
      * a request matcher does not need the request context separately as it
      * can get it from the request.
      */
     if ($this->matcher instanceof RequestContextAwareInterface) {
         $this->matcher->setContext($this->getContext());
     }
     return $this->matcher;
 }
开发者ID:papillon-cendre,项目名称:d8,代码行数:15,代码来源:DynamicRouter.php

示例11: setUp

 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $this->configFactory = $this->getConfigFactoryStub(['system.site' => ['page.403' => '/access-denied-page', 'page.404' => '/not-found-page']]);
     $this->kernel = $this->getMock('Symfony\\Component\\HttpKernel\\HttpKernelInterface');
     $this->logger = $this->getMock('Psr\\Log\\LoggerInterface');
     $this->redirectDestination = $this->getMock('\\Drupal\\Core\\Routing\\RedirectDestinationInterface');
     $this->redirectDestination->expects($this->any())->method('getAsArray')->willReturn(['destination' => 'test']);
     $this->accessUnawareRouter = $this->getMock('Symfony\\Component\\Routing\\Matcher\\UrlMatcherInterface');
     $this->accessUnawareRouter->expects($this->any())->method('match')->willReturn(['_controller' => 'mocked']);
     $this->accessManager = $this->getMock('Drupal\\Core\\Access\\AccessManagerInterface');
     $this->accessManager->expects($this->any())->method('checkNamedRoute')->willReturn(AccessResult::allowed()->addCacheTags(['foo', 'bar']));
     $this->customPageSubscriber = new CustomPageExceptionHtmlSubscriber($this->configFactory, $this->kernel, $this->logger, $this->redirectDestination, $this->accessUnawareRouter, $this->accessManager);
     $path_validator = $this->getMock('Drupal\\Core\\Path\\PathValidatorInterface');
     $path_validator->expects($this->any())->method('getUrlIfValidWithoutAccessCheck')->willReturn(Url::fromRoute('foo', ['foo' => 'bar']));
     $container = new ContainerBuilder();
     $container->set('path.validator', $path_validator);
     \Drupal::setContainer($container);
     // You can't create an exception in PHP without throwing it. Store the
     // current error_log, and disable it temporarily.
     $this->errorLog = ini_set('error_log', file_exists('/dev/null') ? '/dev/null' : 'nul');
 }
开发者ID:ravibarnwal,项目名称:laraitassociate.in,代码行数:24,代码来源:CustomPageExceptionHtmlSubscriberTest.php

示例12: match

 /**
  * @param Request $request
  */
 public function match(Request $request)
 {
     // Initialize the context that is also used by the generator (assuming matcher and generator share the same
     // context instance).
     $this->context->fromRequest($request);
     if ($request->attributes->has('_controller')) {
         // Routing is already done.
         return;
     }
     // Add attributes based on the request (routing).
     try {
         // Matching a request is more powerful than matching a URL path + context, so try that first.
         if ($this->matcher instanceof RequestMatcherInterface) {
             $parameters = $this->matcher->matchRequest($request);
         } else {
             $parameters = $this->matcher->match($request->getPathInfo());
         }
         if (null !== $this->logger) {
             $this->logger->info(sprintf('Matched route "%s" (parameters: %s)', $parameters['_route'], $this->parametersToString($parameters)));
         }
         $request->attributes->add($parameters);
         unset($parameters['_route']);
         unset($parameters['_controller']);
         $request->attributes->set('_route_params', $parameters);
     } catch (ResourceNotFoundException $e) {
         $message = sprintf('No route found for "%s %s"', $request->getMethod(), $request->getPathInfo());
         throw new NotFoundHttpException($message, $e);
     } catch (MethodNotAllowedException $e) {
         $message = sprintf('No route found for "%s %s": Method Not Allowed (Allow: %s)', $request->getMethod(), $request->getPathInfo(), strtoupper(implode(', ', $e->getAllowedMethods())));
         throw new MethodNotAllowedException($e->getAllowedMethods(), $message);
     }
 }
开发者ID:code-ph0y,项目名称:framework,代码行数:35,代码来源:RouterListener.php

示例13: onOpen

 /**
  * {@inheritdoc}
  * @throws \UnexpectedValueException If a controller is not \Ratchet\Http\HttpServerInterface
  */
 public function onOpen(ConnectionInterface $conn, RequestInterface $request = null)
 {
     if (null === $request) {
         throw new \UnexpectedValueException('$request can not be null');
     }
     $context = $this->_matcher->getContext();
     $context->setMethod($request->getMethod());
     $context->setHost($request->getHost());
     try {
         $route = $this->_matcher->match($request->getPath());
     } catch (MethodNotAllowedException $nae) {
         return $this->close($conn, 403);
     } catch (ResourceNotFoundException $nfe) {
         return $this->close($conn, 404);
     }
     if (is_string($route['_controller']) && class_exists($route['_controller'])) {
         $route['_controller'] = new $route['_controller']();
     }
     if (!$route['_controller'] instanceof HttpServerInterface) {
         throw new \UnexpectedValueException('All routes must implement Ratchet\\Http\\HttpServerInterface');
     }
     $parameters = array();
     foreach ($route as $key => $value) {
         if (is_string($key) && '_' !== substr($key, 0, 1)) {
             $parameters[$key] = $value;
         }
     }
     $url = Url::factory($request->getPath());
     $url->setQuery($parameters);
     $request->setUrl($url);
     $conn->controller = $route['_controller'];
     $conn->controller->onOpen($conn, $request);
 }
开发者ID:igez,项目名称:gaiaehr,代码行数:37,代码来源:Router.php

示例14: getCurrentPageWithForm

 /**
  * {@inheritdoc}
  * 
  * @throws \LogicException
  */
 public function getCurrentPageWithForm(array $pages)
 {
     $routeParameters = $this->urlMatcher->match(parse_url($this->session->getCurrentUrl(), PHP_URL_PATH));
     Assert::allIsInstanceOf($pages, SymfonyPageInterface::class);
     foreach ($pages as $page) {
         if ($routeParameters['_route'] === $page->getRouteName()) {
             return $page;
         }
     }
     throw new \LogicException('Route name could not be matched to provided pages.');
 }
开发者ID:ReissClothing,项目名称:Sylius,代码行数:16,代码来源:CurrentPageResolver.php

示例15: getCurrentPageWithForm

 /**
  * {@inheritdoc}
  * 
  * @throws \LogicException
  */
 public function getCurrentPageWithForm(CreatePageInterface $createPage, UpdatePageInterface $updatePage)
 {
     $routeParameters = $this->urlMatcher->match($this->session->getCurrentUrl());
     if (false !== strpos($routeParameters['_route'], 'create')) {
         return $createPage;
     }
     if (false !== strpos($routeParameters['_route'], 'update')) {
         return $updatePage;
     }
     throw new \LogicException('Route name does not have any of "update" or "create" keyword, so matcher was unable to match proper page.');
 }
开发者ID:ahmadrabie,项目名称:Sylius,代码行数:16,代码来源:CurrentPageResolver.php


注:本文中的Symfony\Component\Routing\Matcher\UrlMatcherInterface类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。