本文整理匯總了PHP中Symfony\Component\Routing\Matcher\UrlMatcherInterface::matchRequest方法的典型用法代碼示例。如果您正苦於以下問題:PHP UrlMatcherInterface::matchRequest方法的具體用法?PHP UrlMatcherInterface::matchRequest怎麽用?PHP UrlMatcherInterface::matchRequest使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\Routing\Matcher\UrlMatcherInterface
的用法示例。
在下文中一共展示了UrlMatcherInterface::matchRequest方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: 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);
}
}