本文整理汇总了PHP中Symfony\Component\HttpFoundation\Request::setDefaultLocale方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::setDefaultLocale方法的具体用法?PHP Request::setDefaultLocale怎么用?PHP Request::setDefaultLocale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\Request
的用法示例。
在下文中一共展示了Request::setDefaultLocale方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onKernelException
/**
* Event handler that renders custom pages in case of a NotFoundHttpException (404)
* or a AccessDeniedHttpException (403).
*
* @param GetResponseForExceptionEvent $event
*/
public function onKernelException(GetResponseForExceptionEvent $event)
{
if ('dev' == $this->kernel->getEnvironment()) {
return;
}
$exception = $event->getException();
$this->request->setLocale($this->defaultLocale);
$this->request->setDefaultLocale($this->defaultLocale);
if ($exception instanceof NotFoundHttpException) {
$section = $this->getExceptionSection(404, '404 Error');
$this->core->addNavigationElement($section);
$unifikRequest = $this->generateUnifikRequest($section);
$this->setUnifikRequestAttributes($unifikRequest);
$this->request->setLocale($this->request->attributes->get('_locale', $this->defaultLocale));
$this->request->setDefaultLocale($this->request->attributes->get('_locale', $this->defaultLocale));
$this->entityManager->getRepository('UnifikSystemBundle:Section')->setLocale($this->request->attributes->get('_locale'));
$response = $this->templating->renderResponse('UnifikSystemBundle:Frontend/Exception:404.html.twig', array('section' => $section));
$response->setStatusCode(404);
$event->setResponse($response);
} elseif ($exception instanceof AccessDeniedHttpException) {
$section = $this->getExceptionSection(403, '403 Error');
$this->core->addNavigationElement($section);
$unifikRequest = $this->generateUnifikRequest($section);
$this->setUnifikRequestAttributes($unifikRequest);
$response = $this->templating->renderResponse('UnifikSystemBundle:Frontend/Exception:403.html.twig', array('section' => $section));
$response->setStatusCode(403);
$event->setResponse($response);
}
}
示例2: testLocale
public function testLocale()
{
$getLocale = self::getMethod('getLocale');
$setLocale = self::getMethod('setLocale');
$this->request->setDefaultLocale('fr');
$this->actionKernel->method('getApplication')->willReturn(array('locale' => 'fr'));
// Source from the default space in the application
$this->assertEquals('fr', $getLocale->invokeArgs($this->action, array($this->request)));
// Source from the session if set
$setLocale->invokeArgs($this->action, array($this->request, 'gb'));
$this->assertEquals('gb', $getLocale->invokeArgs($this->action, array($this->request)));
$setLocale->invokeArgs($this->action, array($this->request, null));
$this->assertEquals('fr', $getLocale->invokeArgs($this->action, array($this->request)));
}
示例3: testOnKernelRequest
/**
* @param mixed $installed
* @param bool $isSetLocale
* @dataProvider onKernelRequestDataProvider
*/
public function testOnKernelRequest($installed, $isSetLocale)
{
$customLanguage = 'ru';
$customLocale = 'fr';
$request = new Request();
$context = new RequestContext();
$request->setDefaultLocale($this->defaultLocale);
if ($isSetLocale) {
$this->localeSettings->expects($this->once())->method('getLanguage')->will($this->returnValue($customLanguage));
$this->localeSettings->expects($this->once())->method('getLocale')->will($this->returnValue($customLocale));
$this->router->expects($this->once())->method('getContext')->willReturn($context);
} else {
$this->localeSettings->expects($this->never())->method('getLanguage');
$this->localeSettings->expects($this->never())->method('getLocale');
}
$this->container->expects($this->any())->method('getParameter')->with('installed')->willReturn($installed);
$this->listener = new LocaleListener($this->container);
$this->listener->onKernelRequest($this->createGetResponseEvent($request));
if ($isSetLocale) {
$this->assertEquals($customLanguage, $request->getLocale());
$this->assertEquals($customLanguage, $context->getParameter('_locale'));
$this->assertEquals($customLocale, \Locale::getDefault());
} else {
$this->assertEquals($this->defaultLocale, $request->getLocale());
$this->assertEquals($this->defaultLocale, \Locale::getDefault());
}
}
示例4: initialize
protected function initialize(InputInterface $input, OutputInterface $output)
{
// The mailer service needs the default locale
$locale = $this->getContainer()->get('translator')->getLocale();
// We build a fake request with the default locale
$request = new Request();
$request->setDefaultLocale($locale);
$this->getContainer()->get('request_stack')->push($request);
}
示例5: testOnKernelRequest
public function testOnKernelRequest()
{
$customLocale = 'fr';
$request = new Request(['locale' => $customLocale]);
$request->server->set('REQUEST_URI', '/api/rest/test');
$request->setDefaultLocale($this->defaultLocale);
$this->listener = new LocaleListener();
$this->listener->onKernelRequest($this->createGetResponseEvent($request));
$this->assertEquals($customLocale, $request->getLocale());
}
示例6: testOnKernelRequest
public function testOnKernelRequest()
{
$customLocale = 'fr';
$request = new Request(['locale' => $customLocale]);
$request->server->set('REQUEST_URI', '/api/rest/test');
$request->setDefaultLocale($this->defaultLocale);
$translationListener = new TranslatableListener();
$container = $this->getMockBuilder('Symfony\\Component\\DependencyInjection\\Container')->setMethods(['get'])->getMock();
$container->expects($this->any())->method('get')->willReturn($translationListener);
$this->listener = new LocaleListener($container);
$this->listener->onKernelRequest($this->createGetResponseEvent($request));
$this->assertEquals($customLocale, $request->getLocale());
$this->assertEquals($customLocale, $translationListener->getListenerLocale());
}
示例7: testOnKernelRequest
/**
* @param mixed $installed
* @param bool $isSetLocale
* @dataProvider onKernelRequestDataProvider
*/
public function testOnKernelRequest($installed, $isSetLocale)
{
$customLanguage = 'ru';
$customLocale = 'fr';
$request = new Request();
$request->setDefaultLocale($this->defaultLocale);
if ($isSetLocale) {
$this->localeSettings->expects($this->exactly(2))->method('getLanguage')->will($this->returnValue($customLanguage));
$this->localeSettings->expects($this->once())->method('getLocale')->will($this->returnValue($customLocale));
} else {
$this->localeSettings->expects($this->never())->method('getLanguage');
$this->localeSettings->expects($this->never())->method('getLocale');
}
$this->listener = new LocaleListener($this->localeSettings, $this->transListener, $installed);
$this->listener->onKernelRequest($this->createGetResponseEvent($request));
if ($isSetLocale) {
$this->assertEquals($customLanguage, $request->getLocale());
$this->assertEquals($customLocale, \Locale::getDefault());
} else {
$this->assertEquals($this->defaultLocale, $request->getLocale());
$this->assertEquals($this->defaultLocale, \Locale::getDefault());
}
}
示例8: testIntlLocale
public function testIntlLocale()
{
if (!extension_loaded('intl')) {
$this->markTestSkipped('The intl extension is needed to run this test.');
}
$request = new Request();
$request->setDefaultLocale('fr');
$this->assertEquals('fr', $request->getLocale());
$this->assertEquals('fr', \Locale::getDefault());
$request->setLocale('en');
$this->assertEquals('en', $request->getLocale());
$this->assertEquals('en', \Locale::getDefault());
$request->setDefaultLocale('de');
$this->assertEquals('en', $request->getLocale());
$this->assertEquals('en', \Locale::getDefault());
}
示例9: testIntlLocale
/**
* @requires extension intl
*/
public function testIntlLocale()
{
$request = new Request();
$request->setDefaultLocale('fr');
$this->assertEquals('fr', $request->getLocale());
$this->assertEquals('fr', \Locale::getDefault());
$request->setLocale('en');
$this->assertEquals('en', $request->getLocale());
$this->assertEquals('en', \Locale::getDefault());
$request->setDefaultLocale('de');
$this->assertEquals('en', $request->getLocale());
$this->assertEquals('en', \Locale::getDefault());
}
示例10: setRequestLocale
private function setRequestLocale(Request $request, $locale)
{
$request->setDefaultLocale($this->defaultLocale);
$request->setLocale($locale);
}