本文整理汇总了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;
}
示例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;
}
示例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);
}
示例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;
}