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


PHP UrlMatcherInterface::match方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: handleMessage

 /**
  * @override
  * @inheritDoc
  */
 public function handleMessage(IoConnectionInterface $conn, IoMessageInterface $message)
 {
     if (!$message instanceof HttpRequestInterface) {
         $conn->controller->handleMessage($conn, $message);
         return;
     }
     if (($header = $message->getHeaderLine('Origin')) !== '') {
         $origin = parse_url($header, PHP_URL_HOST) ?: $header;
         if ($origin !== '' && $this->isBlocked($origin)) {
             return $this->close($conn, 403);
         }
     }
     $context = $this->matcher->getContext();
     $context->setMethod($message->getMethod());
     $context->setHost($message->getUri()->getHost());
     $route = [];
     try {
         $route = $this->matcher->match($message->getUri()->getPath());
     } catch (Error $ex) {
         return $this->close($conn, 500);
     } catch (MethodNotAllowedException $nae) {
         return $this->close($conn, 403);
     } catch (ResourceNotFoundException $nfe) {
         return $this->close($conn, 404);
     }
     $conn->controller = $route['_controller'];
     try {
         $conn->controller->handleConnect($conn);
         $conn->controller->handleMessage($conn, $message);
     } catch (Error $ex) {
         $conn->controller->handleError($conn, $ex);
     } catch (Exception $ex) {
         $conn->controller->handleError($conn, $ex);
     }
 }
开发者ID:khelle,项目名称:surume,代码行数:39,代码来源:HttpRouter.php

示例6: isAdminPath

 /**
  * Checks whether the given path is an administrative one.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The request object.
  *
  * @return bool
  *   TRUE if the path is administrative, FALSE otherwise.
  */
 protected function isAdminPath(Request $request)
 {
     $result = FALSE;
     if ($request && $this->adminContext) {
         // If called from an event subscriber, the request may not have the route
         // object yet (it is still being built), so use the router to look up
         // based on the path.
         $route_match = $this->stackedRouteMatch->getRouteMatchFromRequest($request);
         if ($route_match && !($route_object = $route_match->getRouteObject())) {
             try {
                 // Process the path as an inbound path. This will remove any language
                 // prefixes and other path components that inbound processing would
                 // clear out, so we can attempt to load the route clearly.
                 $path = $this->pathProcessorManager->processInbound(urldecode(rtrim($request->getPathInfo(), '/')), $request);
                 $attributes = $this->router->match($path);
             } catch (ResourceNotFoundException $e) {
                 return FALSE;
             } catch (AccessDeniedHttpException $e) {
                 return FALSE;
             }
             $route_object = $attributes[RouteObjectInterface::ROUTE_OBJECT];
         }
         $result = $this->adminContext->isAdminRoute($route_object);
     }
     return $result;
 }
开发者ID:HakS,项目名称:drupal8_training,代码行数:35,代码来源:LanguageNegotiationUserAdmin.php

示例7:

 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

示例8: isAdminPath

 /**
  * Checks whether the given path is an administrative one.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The request object.
  *
  * @return bool
  *   TRUE if the path is administrative, FALSE otherwise.
  */
 public function isAdminPath(Request $request)
 {
     $result = FALSE;
     if ($request && $this->adminContext) {
         // If called from an event subscriber, the request may not the route info
         // yet, so use the router to look up the path first.
         if (!($route_object = $request->attributes->get(RouteObjectInterface::ROUTE_OBJECT))) {
             $attributes = $this->router->match('/' . urldecode(trim($request->getPathInfo(), '/')));
             $route_object = $attributes[RouteObjectInterface::ROUTE_OBJECT];
         }
         $result = $this->adminContext->isAdminRoute($route_object);
     }
     return $result;
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:23,代码来源:LanguageNegotiationUserAdmin.php

示例9: onKernelRequest

 public function onKernelRequest(KernelEvent $event)
 {
     if (strtoupper($event->getRequest()->getMethod()) !== 'LINK' && strtoupper($event->getRequest()->getMethod()) !== 'UNLINK') {
         return;
     }
     if (!$event->getRequest()->headers->has('link')) {
         throw new BadRequestHttpException('Please specify at least one Link.');
     }
     $requestMethod = $this->urlMatcher->getContext()->getMethod();
     $this->urlMatcher->getContext()->setMethod('GET');
     $links = [];
     /*
      * Due to limitations, multiple same-name headers are sent as comma
      * separated values.
      *
      * This breaks those headers into Link headers following the format
      * http://tools.ietf.org/html/rfc2068#section-19.6.2.4
      */
     foreach (explode(',', $event->getRequest()->headers->get('link')) as $header) {
         $header = trim($header);
         $link = new LinkHeader($header);
         try {
             if ($urlParameters = $this->urlMatcher->match($link->getValue())) {
                 $link->setUrlParameters($urlParameters);
             }
         } catch (ResourceNotFoundException $exception) {
         }
         try {
             $link->setResource($this->resourceTransformer->getResourceProxy($link->getValue()));
         } catch (InvalidArgumentException $e) {
         }
         $links[] = $link;
     }
     $this->urlMatcher->getContext()->setMethod($requestMethod);
     $event->getRequest()->attributes->set('links', $links);
 }
开发者ID:ibrows,项目名称:rest-bundle,代码行数:36,代码来源:LinkHeaderListener.php

示例10: 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');
     }
     $conn->controller = $route['_controller'];
     $conn->controller->onOpen($conn, $request);
 }
开发者ID:perfect-coin,项目名称:chat,代码行数:28,代码来源:Router.php

示例11: isRoute

 /**
  * Verify if the given path is a valid route.
  *
  * Taken from menu_execute_active_handler().
  *
  * @param string $path
  *   A string containing a relative path.
  *
  * @return bool
  *   TRUE if the path already exists.
  */
 public function isRoute($path)
 {
     if (is_file(DRUPAL_ROOT . '/' . $path) || is_dir(DRUPAL_ROOT . '/' . $path)) {
         // Do not allow existing files or directories to get assigned an automatic
         // alias. Note that we do not need to use is_link() to check for symbolic
         // links since this returns TRUE for either is_file() or is_dir() already.
         return TRUE;
     }
     try {
         $this->urlMatcher->match('/' . $path);
         return TRUE;
     } catch (ResourceNotFoundException $e) {
         return FALSE;
     }
 }
开发者ID:dev981,项目名称:gaptest,代码行数:26,代码来源:AliasUniquifier.php

示例12: makeSubrequest

 /**
  * Makes a subrequest to retrieve the default error page.
  *
  * @param \Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event
  *   The event to process.
  * @param string $url
  *   The path/url to which to make a subrequest for this error message.
  * @param int $status_code
  *   The status code for the error being handled.
  */
 protected function makeSubrequest(GetResponseForExceptionEvent $event, $url, $status_code)
 {
     $request = $event->getRequest();
     $exception = $event->getException();
     try {
         // Reuse the exact same request (so keep the same URL, keep the access
         // result, the exception, et cetera) but override the routing information.
         // This means that aside from routing, this is identical to the master
         // request. This allows us to generate a response that is executed on
         // behalf of the master request, i.e. for the original URL. This is what
         // allows us to e.g. generate a 404 response for the original URL; if we
         // would execute a subrequest with the 404 route's URL, then it'd be
         // generated for *that* URL, not the *original* URL.
         $sub_request = clone $request;
         // The routing to the 404 page should be done as GET request because it is
         // restricted to GET and POST requests only. Otherwise a DELETE request
         // would for example trigger a method not allowed exception.
         $request_context = clone $this->accessUnawareRouter->getContext();
         $request_context->setMethod('GET');
         $this->accessUnawareRouter->setContext($request_context);
         $sub_request->attributes->add($this->accessUnawareRouter->match($url));
         // Add to query (GET) or request (POST) parameters:
         // - 'destination' (to ensure e.g. the login form in a 403 response
         //   redirects to the original URL)
         // - '_exception_statuscode'
         $parameters = $sub_request->isMethod('GET') ? $sub_request->query : $sub_request->request;
         $parameters->add($this->redirectDestination->getAsArray() + ['_exception_statuscode' => $status_code]);
         $response = $this->httpKernel->handle($sub_request, HttpKernelInterface::SUB_REQUEST);
         // Only 2xx responses should have their status code overridden; any
         // other status code should be passed on: redirects (3xx), error (5xx)…
         // @see https://www.drupal.org/node/2603788#comment-10504916
         if ($response->isSuccessful()) {
             $response->setStatusCode($status_code);
         }
         // Persist any special HTTP headers that were set on the exception.
         if ($exception instanceof HttpExceptionInterface) {
             $response->headers->add($exception->getHeaders());
         }
         $event->setResponse($response);
     } catch (\Exception $e) {
         // If an error happened in the subrequest we can't do much else. Instead,
         // just log it. The DefaultExceptionSubscriber will catch the original
         // exception and handle it normally.
         $error = Error::decodeException($e);
         $this->logger->log($error['severity_level'], '%type: @message in %function (line %line of %file).', $error);
     }
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:57,代码来源:DefaultExceptionHtmlSubscriber.php

示例13: isRoute

 /**
  * Verify if the given path is a valid route.
  *
  * @param string $path
  *   A string containing a relative path.
  *
  * @return bool
  *   TRUE if the path already exists.
  *
  * @throws \InvalidArgumentException
  */
 public function isRoute($path)
 {
     if (is_file(DRUPAL_ROOT . '/' . $path) || is_dir(DRUPAL_ROOT . '/' . $path)) {
         // Do not allow existing files or directories to get assigned an automatic
         // alias. Note that we do not need to use is_link() to check for symbolic
         // links since this returns TRUE for either is_file() or is_dir() already.
         return TRUE;
     }
     try {
         $route = $this->urlMatcher->match($path);
         if ($route['_route'] == $this->lastRouteName) {
             throw new \InvalidArgumentException('The given alias pattern (' . $path . ') always matches the route ' . $this->lastRouteName);
         }
         $this->lastRouteName = $route['_route'];
         return TRUE;
     } catch (ResourceNotFoundException $e) {
         $this->lastRouteName = NULL;
         return FALSE;
     }
 }
开发者ID:aakb,项目名称:cfia,代码行数:31,代码来源:AliasUniquifier.php

示例14: match

 /**
  * @param string $pathinfo
  *
  * @return array
  */
 public function match($pathinfo)
 {
     return $this->matcher->match($pathinfo);
 }
开发者ID:evaneos,项目名称:pyrite,代码行数:9,代码来源:Router.php

示例15: onKernelRequest

 public function onKernelRequest(GetResponseEvent $event)
 {
     if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
         return;
     }
     if (!$event->getRequest()->headers->has('link')) {
         return;
     }
     $links = array();
     $header = $event->getRequest()->headers->get('link');
     /*
      * Due to limitations, multiple same-name headers are sent as comma
      * separated values.
      *
      * This breaks those headers into Link headers following the format
      * http://tools.ietf.org/html/rfc2068#section-19.6.2.4
      */
     while (preg_match('/^((?:[^"]|"[^"]*")*?),/', $header, $matches)) {
         $header = trim(substr($header, strlen($matches[0])));
         $links[] = $matches[1];
     }
     if ($header) {
         $links[] = $header;
     }
     $requestMethod = $this->urlMatcher->getContext()->getMethod();
     // Force the GET method to avoid the use of the
     // previous method (LINK/UNLINK)
     $this->urlMatcher->getContext()->setMethod('GET');
     // The controller resolver needs a request to resolve the controller.
     $stubRequest = new Request();
     foreach ($links as $idx => $link) {
         $linkHeader = $this->parseLinkHeader($link);
         $resource = $this->parseResource($linkHeader, $event->getRequest());
         try {
             $route = $this->urlMatcher->match($resource);
         } catch (\Exception $e) {
             // If we don't have a matching route we return
             // the original Link header
             continue;
         }
         $stubRequest->attributes->replace($route);
         if (false === ($controller = $this->resolver->getController($stubRequest))) {
             continue;
         }
         // Make sure @ParamConverter and some other annotations are called
         $subEvent = new FilterControllerEvent($event->getKernel(), $controller, $stubRequest, HttpKernelInterface::SUB_REQUEST);
         $event->getDispatcher()->dispatch(KernelEvents::CONTROLLER, $subEvent);
         $controller = $subEvent->getController();
         $arguments = $this->resolver->getArguments($stubRequest, $controller);
         try {
             $result = call_user_func_array($controller, $arguments);
             $value = is_array($result) ? current($result) : $result;
             if ($linkHeader->hasRel()) {
                 unset($links[$idx]);
                 $links[$linkHeader->getRel()][] = $value;
             } else {
                 $links[$idx] = $value;
             }
         } catch (\Exception $e) {
             continue;
         }
     }
     $event->getRequest()->attributes->set('links', $links);
     $this->urlMatcher->getContext()->setMethod($requestMethod);
 }
开发者ID:jmcclell,项目名称:BazingaRestExtraBundle,代码行数:65,代码来源:LinkRequestListener.php


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