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


PHP Router::matchRequest方法代码示例

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


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

示例1: match

 /**
  * @param Request $request
  * @return mixed
  * @throws RestException
  */
 public function match(Request $request = null)
 {
     if (is_null($request)) {
         $request = Request::createFromGlobals();
     }
     try {
         $matchedRoute = $this->symfonyRouter->matchRequest($request);
     } catch (ResourceNotFoundException $e) {
         throw new RestException('The requested url could not be handled', 404);
     } catch (MethodNotAllowedException $e) {
         throw new RestException('The requested url does not respond to the given HTTP method', 405);
     }
     $routeName = $matchedRoute['_route'];
     unset($matchedRoute['_route']);
     $routeData = $this->routes[$routeName];
     $routeData['params'] = array_merge($matchedRoute, $routeData['params']);
     return $routeData;
 }
开发者ID:pmill,项目名称:doctrine-rest-api,代码行数:23,代码来源:Router.php

示例2: generateRequestUriForLocale

 /**
  * @param Request $redirectRequest
  * @param string $locale
  * @return string
  */
 private function generateRequestUriForLocale(Request $redirectRequest, $locale)
 {
     $parameters = $this->router->matchRequest($redirectRequest);
     if (isset($parameters['locale'])) {
         $parameters['locale'] = $locale;
     }
     $route = $parameters['_route'];
     unset($parameters['_route']);
     unset($parameters['_controller']);
     $requestUri = $this->router->generate($route, $parameters, UrlGeneratorInterface::ABSOLUTE_PATH);
     if ($redirectRequest->getQueryString()) {
         $requestUri .= '?' . $redirectRequest->getQueryString();
     }
     return $requestUri;
 }
开发者ID:szymach,项目名称:admin-translatable-bundle,代码行数:20,代码来源:TranslationLocaleMenuListener.php

示例3: let

 function let(TranslatorInterface $translator, Router $router, LocaleManager $localeManager, RequestStack $requestStack, Request $request, ParameterBag $query, ParameterBag $server)
 {
     $localeManager->getLocale()->willReturn('en');
     $request->getLocale()->willReturn('en');
     $request->get('_route_params')->willReturn(array('element' => 'event', 'locale' => 'en'));
     $request->get('_route')->willReturn('admin_translatable_list');
     $requestStack->getCurrentRequest()->willReturn($request);
     $query->all()->willReturn(array('param1' => 'val1', 'redirect_uri' => '/admin/en/list/element?param=value'));
     $request->query = $query;
     $router->matchRequest(Argument::that(function ($argument) {
         return $argument->server->get('REQUEST_URI') === '/admin/en/list/element' && $argument->server->get('QUERY_STRING') === 'param=value';
     }))->willReturn(array('_route' => 'some_admin_route', 'locale' => 'en', 'element' => 'element'));
     $request->server = $server;
     $localeManager->getLocales()->willReturn(array('pl', 'en', 'de'));
     $translator->trans('admin.locale.dropdown.title', array('%locale%' => 'en'), 'FSiAdminTranslatableBundle')->willReturn('Menu label');
     $this->beConstructedWith($translator, $router, $localeManager, $requestStack);
 }
开发者ID:szymach,项目名称:admin-translatable-bundle,代码行数:17,代码来源:TranslationLocaleMenuListenerSpec.php

示例4: getControllerResponse

 /**
  * @param Request $request
  *
  * @return Response
  */
 public function getControllerResponse(Request $request)
 {
     // build the context from the Request that was passed
     $this->context->fromRequest($request);
     // instantiate the router with the correct settings so it can automatically perform caching
     $router = new Router($this->loader, Configuration::instance()->setting('base', 'routeFile', 'routes.php'), ['cache_dir' => Configuration::instance()->setting('base', 'routeCacheDir')], $this->context);
     // TODO make this configurable
     // default controller
     $match = ["_controller" => '\\Controllers\\HomeController', "_action" => "index"];
     try {
         $match = $router->matchRequest($request);
     } catch (\Exception $ex) {
         if ($ex instanceof ResourceNotFoundException) {
             // TODO improve this
             return new Response("404 Not Found", 404);
         } elseif ($ex instanceof MethodNotAllowedException) {
             // TODO improve this
             return new Response("Current request method is not allowed for this route", 401);
         }
     }
     // dynamically instantiate a new controller and pass it the Request object
     $controller = new $match['_controller']($request);
     $action = $match['_action'];
     // parse out all parameters (those keys that do not start with an underscore)
     $parameters = $this->getParameters($match);
     // we pass $match as last parameter because it also contains all key-value pairs for the arguments of the action
     $responseText = call_user_func_array([$controller, $action], $parameters);
     // wrap the response that was generated by the controller
     $response = new Response($responseText);
     return $response;
 }
开发者ID:rickvanbodegraven,项目名称:project-mandy,代码行数:36,代码来源:Routing.php


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