當前位置: 首頁>>代碼示例>>PHP>>正文


PHP RouterInterface::match方法代碼示例

本文整理匯總了PHP中Symfony\Component\Routing\RouterInterface::match方法的典型用法代碼示例。如果您正苦於以下問題:PHP RouterInterface::match方法的具體用法?PHP RouterInterface::match怎麽用?PHP RouterInterface::match使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\Routing\RouterInterface的用法示例。


在下文中一共展示了RouterInterface::match方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: getActionForCurrentController

 public function getActionForCurrentController(string $action) : string
 {
     $currentPath = $this->getRouterRequestContext()->getPathInfo();
     $currentRoute = $this->router->match($currentPath);
     list($mode, $controller) = explode('.', $currentRoute['_route'], 3);
     $route = sprintf('%s.%s.%s', $mode, $controller, $action);
     return $route;
 }
開發者ID:WellCommerce,項目名稱:CoreBundle,代碼行數:8,代碼來源:RouterHelper.php

示例2: getRefererParams

 private function getRefererParams(Request $request)
 {
     $referer = $request->headers->get('referer');
     $matchBasePath = $this->router->match('');
     $baseUrl = $this->router->generate($matchBasePath['_route'], [], true);
     $lastPath = substr($referer, strpos($referer, $baseUrl) + strlen($baseUrl));
     return $this->router->match('/' . $lastPath);
 }
開發者ID:ojs,項目名稱:ojs,代碼行數:8,代碼來源:ExceptionListener.php

示例3: getPathInfoFromMetaTagKey

 /**
  * @param $key
  *
  * @return array An array of parameters
  */
 public function getPathInfoFromMetaTagKey($key)
 {
     $info = $this->keyGenerator->generatePathInfoFromMetaTagKey($key);
     $this->router->getContext()->setMethod('GET');
     if ($this->keyGenerator->isAddQueryString()) {
         $info = substr($info, 0, strpos($info, '?'));
         $match = $this->router->match($info);
         return $match;
     } else {
         return $this->router->match($info);
     }
 }
開發者ID:vstm,項目名稱:IbrowsSimpleSeoBundle,代碼行數:17,代碼來源:AliasHandler.php

示例4: getItemFromIri

 /**
  * {@inheritdoc}
  */
 public function getItemFromIri($iri, $fetchData = false)
 {
     try {
         $parameters = $this->router->match($iri);
     } catch (ResourceNotFoundException $e) {
         return;
     }
     if (!isset($parameters['_resource']) || !isset($parameters['id']) || !($resource = $this->resourceCollection->getResourceForShortName($parameters['_resource']))) {
         throw new \InvalidArgumentException(sprintf('No resource associated with the IRI "%s".', $iri));
     }
     return $this->dataProvider->getItem($resource, $parameters['id'], $fetchData);
 }
開發者ID:bein-sports,項目名稱:DunglasApiBundle,代碼行數:15,代碼來源:IriConverter.php

示例5: match

 public function match($pathInfo)
 {
     $baseContext = $this->router->getContext();
     $request = Request::create($pathInfo);
     $context = (new RequestContext())->fromRequest($request);
     $context->setPathInfo($pathInfo);
     try {
         $this->router->setContext($context);
         return $this->router->match($request->getPathInfo());
     } finally {
         $this->router->setContext($baseContext);
     }
 }
開發者ID:reminec,項目名稱:DunglasApiBundle,代碼行數:13,代碼來源:Router.php

示例6: reverseTransform

 /**
  * @param string $value
  *
  * @return NodeTranslation|null
  */
 public function reverseTransform($value)
 {
     if ("" === $value || null === $value) {
         return null;
     }
     try {
         $route = $this->router->match($value);
         if (false === isset($route['_nodeTranslation']) || false === $route['_nodeTranslation'] instanceof NodeTranslation) {
             throw new TransformationFailedException('Matched route has no nodeTranslation');
         }
         return $route['_nodeTranslation'];
     } catch (RouteNotFoundException $e) {
         throw new TransformationFailedException('Cannot match URL to a nodeTranslation', 0, $e);
     }
 }
開發者ID:arsthanea,項目名稱:kunstmaan-extra-bundle,代碼行數:20,代碼來源:NodeTranslationToUrlTransformer.php

示例7: getItemFromIri

 /**
  * {@inheritdoc}
  */
 public function getItemFromIri($iri, $fetchData = false)
 {
     try {
         $parameters = $this->router->match($iri);
     } catch (ExceptionInterface $e) {
         throw new InvalidArgumentException(sprintf('No route matches "%s".', $iri), $e->getCode(), $e);
     }
     if (!isset($parameters['_resource']) || !isset($parameters['id']) || !($resource = $this->resourceCollection->getResourceForShortName($parameters['_resource']))) {
         throw new InvalidArgumentException(sprintf('No resource associated to "%s".', $iri));
     }
     if ($item = $this->dataProvider->getItem($resource, $parameters['id'], $fetchData)) {
         return $item;
     }
     throw new InvalidArgumentException(sprintf('Item not found for "%s".', $iri));
 }
開發者ID:GuillaumeDoury,項目名稱:DunglasApiBundle,代碼行數:18,代碼來源:IriConverter.php

示例8: findResourceInformationFromRouter

 /**
  * @param $path
  * @return array|null
  */
 private function findResourceInformationFromRouter($path)
 {
     // store and reset the request method
     $requestMethod = $this->getRequestMethod();
     $this->setRequestMethod(Request::METHOD_GET);
     try {
         $parameters = $this->router->match($path);
         $this->setRequestMethod($requestMethod);
     } catch (ResourceNotFoundException $e) {
         $this->setRequestMethod($requestMethod);
         return null;
     } catch (MethodNotAllowedException $e) {
         $this->setRequestMethod($requestMethod);
         return null;
     }
     if (!isset($parameters['_route'])) {
         return null;
     }
     $route = $this->router->getRouteCollection()->get($parameters['_route']);
     if (null === $route) {
         return null;
     }
     if (!$route->hasOption(self::RESOURCE_ENTITY_CLASS_OPTION) || !$route->hasOption(self::RESOURCE_ENTITY_ID_OPTION)) {
         return null;
     }
     if (!isset($parameters[$route->getOption(self::RESOURCE_ENTITY_ID_OPTION)])) {
         return null;
     }
     $converter = $this->defaultConverter;
     if ($route->hasOption(self::RESOURCE_CONVERTER_OPTION)) {
         $converter = $route->getOption(self::RESOURCE_CONVERTER_OPTION);
     }
     return [$route->getOption(self::RESOURCE_ENTITY_CLASS_OPTION), $parameters[$route->getOption(self::RESOURCE_ENTITY_ID_OPTION)], $converter];
 }
開發者ID:ibrows,項目名稱:rest-bundle,代碼行數:38,代碼來源:ResourceTransformer.php

示例9: canonical

 public function canonical($pathinfo, $uri = null)
 {
     if ($uri) {
         if (!$this->keyGenerator->isAddQueryString()) {
             //remove query string
             if ($pos = strpos($uri, '?')) {
                 $uri = substr($uri, 0, $pos);
             }
         }
         //remove if rewrite not used
         $uri = str_replace('app_dev.php/', '', $uri);
         $uri = str_replace('app.php/', '', $uri);
         return $uri;
     }
     try {
         $infos = $this->router->match($pathinfo);
     } catch (ResourceNotFoundException $e) {
         $infos = false;
     } catch (MethodNotAllowedException $e) {
         $infos = false;
     }
     if ($infos === false) {
         return;
     }
     if (strpos($infos['_route'], RouteLoader::ROUTE_BEGIN) === 0) {
         $infos = RouteLoader::getPathinfo($infos['_route']);
     }
     $route = $infos['_route'];
     unset($infos['_route']);
     unset($infos['_controller']);
     return $this->router->generate($route, $infos, true);
 }
開發者ID:vstm,項目名稱:IbrowsSimpleSeoBundle,代碼行數:32,代碼來源:TwigExtension.php

示例10: action

 public function action(RouterInterface $router, RequestContext $context)
 {
     $request = Request::createFromGlobals();
     $bPath = $context->getPathInfo();
     try {
         $parameters = $router->match($bPath);
         var_dump($parameters);
         $_controller = $parameters["_controller"];
         $_controller = explode(":", $_controller);
         $class = $_controller[0];
         $action = strtolower($_controller[1]) . "Action";
         $class = new $class();
         ob_start();
         if (method_exists($class, $action)) {
             $class->{$action}($request, new JsonResponse());
             $response = new Response(ob_get_clean());
         } else {
             $response = new Response('Not Found', 404);
         }
     } catch (ResourceNotFoundException $e) {
         $response = new Response('Not Found', 404);
     } catch (Exception $e) {
         $response = new Response('An error occurred', 500);
     }
     $response->send();
 }
開發者ID:mbabenko21,項目名稱:likedimion-server,代碼行數:26,代碼來源:RoutingBootstrap.php

示例11: addRootRelations

 public function addRootRelations(Root $root, ClassMetadataInterface $classMetadata)
 {
     $prefix = $root->getPrefix();
     $relations = array();
     $self_args = $this->router->match($root->getPrefix());
     $relations[] = new Hateoas\Relation('self', new Hateoas\Route($self_args['_route'], array(), false));
     foreach ($root->getEntityNames() as $rel => $entityName) {
         /** @var ClassMetadata $metadata */
         $metadata = $this->entityManager->getMetadataFactory()->getMetadataFor($entityName);
         $routeName = $this->routeResolver->resolveRouteName($metadata->getName(), 'cgetAction');
         if ($routeName) {
             $arguments = array();
             foreach (self::$COLLECTION_ARGUMENTS as $argument) {
                 $arguments[$argument] = '{' . $argument . '}';
             }
             $relations[] = new Hateoas\Relation(Inflector::pluralize($rel), new Hateoas\Route($routeName, $arguments, false));
         }
         $routeName = $this->routeResolver->resolveRouteName($metadata->getName(), 'getAction');
         if ($routeName) {
             $relations[] = new Hateoas\Relation($rel, new Hateoas\Route($routeName, array('id' => "{id}"), false));
         }
         $routeName = $self_args['_route'] . '_schema';
         if ($this->router->getRouteCollection()->get($routeName)) {
             $relations[] = new Hateoas\Relation('schema:' . $rel, new Hateoas\Route($routeName, array('rel' => $rel), false));
         }
     }
     $user = $root->getCurrentUser();
     if ($user instanceof User) {
         $routeName = $this->routeResolver->resolveRouteName(get_class($user), 'getAction');
         if ($routeName) {
             $relations[] = new Hateoas\Relation('currentUser', new Hateoas\Route($routeName, array('id' => $user->getId()), false));
         }
     }
     return $relations;
 }
開發者ID:uebb,項目名稱:hateoas-bundle,代碼行數:35,代碼來源:RelationProvider.php

示例12: getCurrentRoute

 public function getCurrentRoute()
 {
     try {
         return $this->router->match($this->router->getPathInfo());
     } catch (\Exception $e) {
         return array('_route' => null, '_locale' => $this->getLocale());
     }
 }
開發者ID:xoeoro,項目名稱:helper-bundle,代碼行數:8,代碼來源:HelperService.php

示例13: validate

 public function validate($value, Constraint $constraint)
 {
     if (!preg_match('#^/[/a-z0-9-_%]*#', $value->getStaticPrefix())) {
         $this->context->buildViolation($constraint->urlValidation)->setParameter('%string%', $value->getStaticPrefix())->addViolation();
     }
     $isUnique = true;
     try {
         $route = $this->router->match($value->getStaticPrefix());
         if ($value->getName() && $value->getName() != $route['_route']) {
             $isUnique = false;
         }
     } catch (ResourceNotFoundException $e) {
     }
     if (!$isUnique) {
         $this->context->buildViolation($constraint->uniqueUrlMessage)->setParameter('%string%', $value->getStaticPrefix())->addViolation();
     }
 }
開發者ID:enhavo,項目名稱:enhavo,代碼行數:17,代碼來源:RouteValidator.php

示例14: getCssIfMatchRoute

 /**
  * @param string|bool $check
  * @param string      $css
  *
  * @return null|string
  */
 public function getCssIfMatchRoute($check, $css = 'active')
 {
     if (is_string($check)) {
         $matcher = $this->router->match($this->request->getCurrentRequest()->getPathInfo());
         $check = $matcher['_route'] === $check;
     }
     return $check ? $css : null;
 }
開發者ID:liverbool,項目名稱:dos-resource-bundle,代碼行數:14,代碼來源:Page.php

示例15: getRouteInfoByUri

 /**
  * Get route info by uri
  *
  * @param  string      $uri
  * @return null|string
  */
 protected function getRouteInfoByUri($uri)
 {
     try {
         $routeInfo = $this->router->match($uri);
         return $routeInfo[self::ROUTE_CONTROLLER_KEY];
     } catch (ResourceNotFoundException $e) {
     }
     return null;
 }
開發者ID:snorchel,項目名稱:platform,代碼行數:15,代碼來源:AclAwareMenuFactoryExtension.php


注:本文中的Symfony\Component\Routing\RouterInterface::match方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。