本文整理匯總了PHP中Symfony\Component\Routing\RouterInterface::matchRequest方法的典型用法代碼示例。如果您正苦於以下問題:PHP RouterInterface::matchRequest方法的具體用法?PHP RouterInterface::matchRequest怎麽用?PHP RouterInterface::matchRequest使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\Routing\RouterInterface
的用法示例。
在下文中一共展示了RouterInterface::matchRequest方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: matchRequest
/**
* {@inheritdoc}
*/
public function matchRequest(Request $request)
{
if (!$this->router instanceof RequestMatcherInterface) {
throw new \BadMethodCallException('Router has to implement the ' . RequestMatcherInterface::class);
}
return $this->router->matchRequest($request);
}
示例2: getTranslationRoute
/**
* Returns the corresponding route of the given URL for the locale supplied
* If none is found it returns the original route object
*
* @param $oldUrl
* @param $locale
* @return array|\Networking\InitCmsBundle\Component\Routing\Route
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
*/
public function getTranslationRoute($oldUrl, $locale)
{
$cookies = $this->request->cookies ? $this->request->cookies->all() : array();
$oldRequest = Request::create($oldUrl, 'GET', array(), $cookies);
if ($this->request->getSession()) {
$oldRequest->setSession($this->request->getSession());
}
try {
$request = $this->pageHelper->matchContentRouteRequest($oldRequest);
} catch (ResourceNotFoundException $e) {
$request = $oldRequest;
}
if (!($content = $request->get('_content', false))) {
try {
$route = $this->router->matchRequest(Request::create($oldUrl));
} catch (ResourceNotFoundException $e) {
if ($route = $this->router->matchRequest(Request::create('/404'))) {
return $route;
}
throw new NotFoundHttpException(sprintf('Could not find a translation to "%s" for this request"', $locale));
}
if (!array_key_exists('_content', $route)) {
return $route;
}
if (!($content = $route['_content'])) {
return $route;
}
}
if ($content instanceof PageInterface) {
$translation = $content->getAllTranslations()->get($locale);
if (is_null($translation)) {
//@todo does this make sense, or should we throw an exception
return array('_route' => 'networking_init_cms_home');
}
//return a contentRoute object
$contentRoute = $translation->getContentRoute()->setContent($translation);
return ContentRouteManager::generateRoute($contentRoute, $contentRoute->getPath(), '');
}
if ($content instanceof PageSnapshotInterface) {
$content = $this->pageHelper->unserializePageSnapshotData($content);
$translation = $content->getAllTranslations()->get($locale);
if ($translation && ($snapshotId = $translation->getId())) {
/** @var $snapshot PageSnapshotInterface */
$snapshot = $this->om->getRepository($content->getSnapshotClassType())->findOneBy(array('resourceId' => $snapshotId));
if ($snapshot) {
$contentRoute = $snapshot->getRoute();
return ContentRouteManager::generateRoute($contentRoute, $contentRoute->getPath(), '');
}
}
}
if ($this->fallbackRoute) {
return $this->fallbackRoute;
}
if ($route = $this->router->matchRequest(Request::create('/404'))) {
return $route;
}
//no valid translation found
throw new NotFoundHttpException(sprintf('Could not find a translation to "%s" for content "%s"', $locale, $content->__toString()));
}
示例3: getTranslationRoute
/**
* Returns the corresponding route of the given URL for the locale supplied
* If none is found it returns the original route object
*
* @param $oldUrl
* @param $locale
* @return array|\Networking\InitCmsBundle\Entity\ContentRoute
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
*/
public function getTranslationRoute($oldUrl, $locale)
{
/** @var $router RouterInterface */
$route = $this->router->matchRequest(Request::create($oldUrl));
if (!array_key_exists('_content', $route)) {
return $route;
}
$content = $route['_content'];
if ($content instanceof PageInterface) {
$translation = $content->getAllTranslations()->get($locale);
if (is_null($translation)) {
//@todo does this make sense, or should we throw an exception
return array('_route' => 'networking_init_cms_home');
}
//return a contentRoute object
return $translation->getContentRoute()->setContent($translation);
}
if ($content instanceof PageSnapshotInterface) {
$content = $this->serializer->deserialize($content->getVersionedData(), $this->pageManager->getClassName(), 'json');
$translation = $content->getAllTranslations()->get($locale);
if ($translation && ($snapshotId = $translation->getId())) {
/** @var $snapshot PageSnapshotInterface */
$snapshot = $this->om->getRepository($content->getSnapshotClassType())->findOneBy(array('resourceId' => $snapshotId));
if ($snapshot) {
//return a contentRoute object
return $snapshot->getRoute();
}
}
}
if ($this->fallbackRoute) {
return $this->fallbackRoute;
}
if ($route = $this->router->matchRequest(Request::create('/404'))) {
return $route;
}
//no valid translation found
throw new NotFoundHttpException(sprintf('Could not find a translation to "%s" for content "%s"', $locale, $content->__toString()));
}