Skip to content
Browse files

fix #14

  • Loading branch information...
1 parent 16ee2f5 commit 6f44cd91b211ff45b79ec6e4f782cf16c9be0789 @viliam-husar viliam-husar committed Mar 27, 2012
Showing with 9 additions and 8 deletions.
  1. +8 −7 Locale/RequestDetector.php
  2. +1 −1 Resources/config/intl.xml
View
15 Locale/RequestDetector.php
@@ -14,25 +14,26 @@
use Sonata\IntlBundle\SonataIntlBundle;
use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Kernel;
class RequestDetector implements LocaleDetectorInterface
{
- protected $request;
+ protected $container;
protected $defaultLocale;
/**
- * @param \Symfony\Component\HttpFoundation\Request $request
+ * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
* @param string $defaultLocale
*/
- public function __construct(Request $request, $defaultLocale)
+ public function __construct(ContainerInterface $container, $defaultLocale)
{
if (version_compare(SonataIntlBundle::getSymfonyVersion(Kernel::VERSION), '2.1.0', '<')) {
throw new \RuntimeException('Invalid Symfony2 version, please use Symfony 2.1.x series');
}
- $this->request = $request;
+ $this->container = $container;
$this->defaultLocale = $defaultLocale;
}
@@ -41,10 +42,10 @@ public function __construct(Request $request, $defaultLocale)
*/
public function getLocale()
{
- if ($this->request) {
- return $this->request->getLocale();
+ if ($request = $this->container->get('request', ContainerInterface::NULL_ON_INVALID_REFERENCE)) {
+ return $request->getLocale();
}
return $this->defaultLocale;
}
-}
+}
View
2 Resources/config/intl.xml
@@ -21,7 +21,7 @@
<services>
<service id="sonata.intl.locale_detector.request" class='%sonata.intl.locale_detector.request.class%' >
- <argument type="service" id="request" strict="false" />
+ <argument type="service" id="service_container" strict="false" />
<argument />
</service>

0 comments on commit 6f44cd9

Please sign in to comment.
Something went wrong with that request. Please try again.