本文整理汇总了PHP中Thelia\Model\ConfigQuery::isRewritingEnable方法的典型用法代码示例。如果您正苦于以下问题:PHP ConfigQuery::isRewritingEnable方法的具体用法?PHP ConfigQuery::isRewritingEnable怎么用?PHP ConfigQuery::isRewritingEnable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Thelia\Model\ConfigQuery
的用法示例。
在下文中一共展示了ConfigQuery::isRewritingEnable方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: noAction
/**
*
* set the default value for thelia
*
* In this case there is no action so we have to verify if some needed params are not missing
*
* @param \Symfony\Component\HttpFoundation\Request $request
*/
public function noAction(Request $request)
{
$view = null;
if (!($view = $request->query->get('view'))) {
if ($request->request->has('view')) {
$view = $request->request->get('view');
}
}
if (null !== $view) {
$request->attributes->set('_view', $view);
}
if (null === $view && null === $request->attributes->get("_view")) {
$request->attributes->set("_view", "index");
}
if (ConfigQuery::isRewritingEnable()) {
if ($request->attributes->get('_rewritten', false) === false) {
/* Does the query GET parameters match a rewritten URL ? */
$rewrittenUrl = URL::getInstance()->retrieveCurrent($request);
if ($rewrittenUrl->rewrittenUrl !== null) {
/* 301 redirection to rewritten URL */
return $this->generateRedirect($rewrittenUrl, 301);
}
}
}
}
示例2: matchRequest
/**
* Tries to match a request with a set of routes.
*
* If the matcher can not find information, it must throw one of the exceptions documented
* below.
*
* @param Request $request The request to match
*
* @throws \Exception|\Thelia\Exception\UrlRewritingException
* @throws \Symfony\Component\Routing\Exception\ResourceNotFoundException
* @return array An array of parameters
*
*/
public function matchRequest(Request $request)
{
if (ConfigQuery::isRewritingEnable()) {
$urlTool = URL::getInstance();
$pathInfo = $request instanceof TheliaRequest ? $request->getRealPathInfo() : $request->getPathInfo();
try {
$rewrittenUrlData = $urlTool->resolve($pathInfo);
} catch (UrlRewritingException $e) {
switch ($e->getCode()) {
case UrlRewritingException::URL_NOT_FOUND:
throw new ResourceNotFoundException();
break;
default:
throw $e;
}
}
// If we have a "lang" parameter, whe have to check if the found URL has the proper locale
// If it's not the case, find the rewritten URL with the requested locale, and redirect to it.
if (null == !($requestedLocale = $request->get('lang'))) {
if (null !== ($requestedLang = LangQuery::create()->findOneByLocale($requestedLocale))) {
if ($requestedLang->getLocale() != $rewrittenUrlData->locale) {
$localizedUrl = $urlTool->retrieve($rewrittenUrlData->view, $rewrittenUrlData->viewId, $requestedLang->getLocale())->toString();
$this->redirect($urlTool->absoluteUrl($localizedUrl), 301);
}
}
}
/* is the URL redirected ? */
if (null !== $rewrittenUrlData->redirectedToUrl) {
$this->redirect($urlTool->absoluteUrl($rewrittenUrlData->redirectedToUrl), 301);
}
/* define GET arguments in request */
if (null !== $rewrittenUrlData->view) {
$request->attributes->set('_view', $rewrittenUrlData->view);
if (null !== $rewrittenUrlData->viewId) {
$request->query->set($rewrittenUrlData->view . '_id', $rewrittenUrlData->viewId);
}
}
if (null !== $rewrittenUrlData->locale) {
$this->manageLocale($rewrittenUrlData, $request);
}
foreach ($rewrittenUrlData->otherParameters as $parameter => $value) {
$request->query->set($parameter, $value);
}
return array('_controller' => 'Thelia\\Controller\\Front\\DefaultController::noAction', '_route' => 'rewrite', '_rewritten' => true);
}
throw new ResourceNotFoundException();
}
示例3: matchRequest
/**
* Tries to match a request with a set of routes.
*
* If the matcher can not find information, it must throw one of the exceptions documented
* below.
*
* @param Request $request The request to match
*
* @throws \Exception|\Thelia\Exception\UrlRewritingException
* @throws \Symfony\Component\Routing\Exception\ResourceNotFoundException
* @return array An array of parameters
*
*/
public function matchRequest(Request $request)
{
if (ConfigQuery::isRewritingEnable()) {
try {
$rewrittenUrlData = URL::getInstance()->resolve($request->getPathInfo());
} catch (UrlRewritingException $e) {
switch ($e->getCode()) {
case UrlRewritingException::URL_NOT_FOUND:
throw new ResourceNotFoundException();
break;
default:
throw $e;
}
}
/* is the URL redirected ? */
if (null !== $rewrittenUrlData->redirectedToUrl) {
$this->redirect($rewrittenUrlData->redirectedToUrl, 301);
}
/* define GET arguments in request */
if (null !== $rewrittenUrlData->view) {
$request->attributes->set('_view', $rewrittenUrlData->view);
if (null !== $rewrittenUrlData->viewId) {
$request->query->set($rewrittenUrlData->view . '_id', $rewrittenUrlData->viewId);
}
}
if (null !== $rewrittenUrlData->locale) {
$request->query->set('locale', $rewrittenUrlData->locale);
}
foreach ($rewrittenUrlData->otherParameters as $parameter => $value) {
$request->query->set($parameter, $value);
}
return array('_controller' => 'Thelia\\Controller\\Front\\DefaultController::noAction', '_route' => 'rewrite', '_rewritten' => true);
}
throw new ResourceNotFoundException();
}
示例4: retrieveCurrent
/**
* Retrieve a rewritten URL from the current GET parameters
*
* @param Request $request
*
* @return RewritingRetriever You can access $url and $rewrittenUrl properties or use toString method
*/
public function retrieveCurrent(Request $request)
{
if (ConfigQuery::isRewritingEnable()) {
$view = $request->attributes->get('_view', null);
$viewLocale = $request->query->get('locale', null);
$viewId = $view === null ? null : $request->query->get($view . '_id', null);
$allOtherParameters = $request->query->all();
if ($view !== null) {
unset($allOtherParameters['view']);
if ($viewId !== null) {
unset($allOtherParameters[$view . '_id']);
}
}
if ($viewLocale !== null) {
unset($allOtherParameters['locale']);
}
$this->retriever->loadSpecificUrl($view, $viewLocale, $viewId, $allOtherParameters);
} else {
$allParametersWithoutView = $request->query->all();
$view = $request->attributes->get('_view');
if (isset($allOtherParameters['view'])) {
unset($allOtherParameters['view']);
}
$this->retriever->rewrittenUrl = null;
$this->retriever->url = URL::getInstance()->viewUrl($view, $allParametersWithoutView);
}
return $this->retriever;
}