本文整理匯總了PHP中Thelia\Tools\URL::setRequestContext方法的典型用法代碼示例。如果您正苦於以下問題:PHP URL::setRequestContext方法的具體用法?PHP URL::setRequestContext怎麽用?PHP URL::setRequestContext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Thelia\Tools\URL
的用法示例。
在下文中一共展示了URL::setRequestContext方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testMatchRequestWithDifferentLocaleAndDomain
/**
* covers RewritingRouter::matchRequest
*/
public function testMatchRequestWithDifferentLocaleAndDomain()
{
ConfigQuery::write('rewriting_enable', 1);
ConfigQuery::write('one_domain_foreach_lang', 1);
$defaultLang = LangQuery::create()->findOneByLocale('en_US');
$defaultLang->setUrl('http://test_en.com');
$frenchLang = LangQuery::create()->findOneByLocale('fr_FR');
$saveUrl = $frenchLang->getUrl();
$frenchLang->setUrl('http://test.com')->save();
$product = ProductQuery::create()->findOne();
$product->setLocale($defaultLang->getLocale());
$rewriting = RewritingUrlQuery::create()->filterByView('product')->filterByViewId($product->getId())->filterByViewLocale('fr_FR')->filterByRedirected(null)->findOne();
$request = Request::create('http://test_en.com/' . $rewriting->getUrl());
$session = new Session(new MockArraySessionStorage());
$session->setLang($defaultLang);
$request->setSession($session);
$url = new URL();
$requestContext = new RequestContext();
$requestContext->fromRequest($request);
$url->setRequestContext($requestContext);
try {
$rewritingRouter = new RewritingRouter();
$parameters = $rewritingRouter->matchRequest($request);
} catch (RedirectException $e) {
$this->assertRegExp("/http:\\/\\/test\\.com\\/.*/", $e->getUrl());
return;
}
$this->fail('->matchRequest must throw a RedirectException');
}
示例2: initRequest
/**
* For init an Request, if your command has need an Request
* @param Lang|null $lang
* @since 2.3
*/
protected function initRequest(Lang $lang = null)
{
$container = $this->getContainer();
$request = Request::create($this->getBaseUrl($lang));
$request->setSession(new Session(new MockArraySessionStorage()));
$container->set("request_stack", new RequestStack());
$container->get('request_stack')->push($request);
$requestContext = new RequestContext();
$requestContext->fromRequest($request);
$url = new URL($container);
$url->setRequestContext($requestContext);
}