本文整理汇总了PHP中Symfony\Component\Routing\RequestContext::setParameters方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestContext::setParameters方法的具体用法?PHP RequestContext::setParameters怎么用?PHP RequestContext::setParameters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Routing\RequestContext
的用法示例。
在下文中一共展示了RequestContext::setParameters方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetParameter
public function testGetParameter()
{
$requestContext = new RequestContext();
$requestContext->setParameters(array('foo' => 'bar'));
$this->assertEquals('bar', $requestContext->getParameter('foo'));
$this->assertNull($requestContext->getParameter('baz'));
}
示例2: generate
public function generate($name, array $parameters = array(), $referenceType = self::ABSOLUTE_PATH, $scheme = null)
{
$contextParameters = array_deep_merge($this->sessionDefaultParameters, $this->defaultParameters, $this->context->getParameters());
$oldContextParameters = $this->context->getParameters();
$this->context->setParameters($contextParameters);
$oldScheme = null;
if ($scheme) {
$oldScheme = $this->context->getScheme();
$this->context->setScheme($scheme);
}
$oldHost = $this->context->getHost();
$context = $this->context;
$finalize = new OutOfScopeFinalize(function () use($oldContextParameters, $oldScheme, $oldHost, $context, $scheme) {
if ($scheme) {
$context->setScheme($oldScheme);
}
$context->setHost($oldHost);
$context->setParameters($oldContextParameters);
});
$cultures = $this->getCultures(array_merge($contextParameters, $parameters));
$route = null;
foreach ($cultures as $culture) {
$routeName = $this->getI18nRouteName($name, $culture);
if ($this->routeCollection->get($routeName)) {
try {
$host = $this->getHostForCulture($culture == '' ? 'default' : $culture);
$this->context->setHost($host);
if ($host != $oldHost) {
$referenceType = self::ABSOLUTE_URL;
}
} catch (NoHostFoundForCultureException $e) {
//We do nothing with the exception, it will use the request domain
}
$route = $this->urlGenerator->generate($routeName, $parameters, $referenceType);
break;
}
}
if (is_null($route)) {
$route = $this->urlGenerator->generate($name, $parameters);
}
return $route;
}