当前位置: 首页>>代码示例>>PHP>>正文


PHP Request::setDefaultLocale方法代码示例

本文整理汇总了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);
     }
 }
开发者ID:pmdc,项目名称:UnifikSystemBundle,代码行数:35,代码来源:ExceptionListener.php

示例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)));
 }
开发者ID:cammanderson,项目名称:phruts,代码行数:14,代码来源:ActionTest.php

示例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());
     }
 }
开发者ID:startupz,项目名称:platform-1,代码行数:32,代码来源:LocaleListenerTest.php

示例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);
 }
开发者ID:aulasoftwarelibre,项目名称:seta,代码行数:9,代码来源:CronCommand.php

示例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());
 }
开发者ID:nmallare,项目名称:platform,代码行数:10,代码来源:LocaleListenerTest.php

示例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());
 }
开发者ID:ramunasd,项目名称:platform,代码行数:14,代码来源:LocaleListenerTest.php

示例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());
     }
 }
开发者ID:xamin123,项目名称:platform,代码行数:28,代码来源:LocaleListenerTest.php

示例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());
 }
开发者ID:anderson-abc,项目名称:sf2_kowee,代码行数:16,代码来源:RequestTest.php

示例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());
 }
开发者ID:sapwoo,项目名称:portfolio,代码行数:16,代码来源:RequestTest.php

示例10: setRequestLocale

 private function setRequestLocale(Request $request, $locale)
 {
     $request->setDefaultLocale($this->defaultLocale);
     $request->setLocale($locale);
 }
开发者ID:andreaswarnaar,项目名称:openl10n,代码行数:5,代码来源:LocaleListener.php


注:本文中的Symfony\Component\HttpFoundation\Request::setDefaultLocale方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。