当前位置: 首页>>代码示例>>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;未经允许,请勿转载。