|
|
@@ -2,22 +2,26 @@
|
|
2
|
2
|
|
|
3
|
3
|
namespace PhpBenchmarksSymfony\RestApiBundle\EventListener;
|
|
4
|
4
|
|
|
5
|
|
-use Symfony\Component\HttpFoundation\RequestStack;
|
|
|
5
|
+use Symfony\Component\DependencyInjection\ContainerInterface;
|
|
|
6
|
+use Symfony\Component\HttpFoundation\Request;
|
|
6
|
7
|
use Symfony\Component\Translation\TranslatorInterface;
|
|
7
|
8
|
|
|
8
|
9
|
class DefineLocaleEventListener
|
|
9
|
10
|
{
|
|
10
|
11
|
const EVENT_NAME = 'defineLocale';
|
|
11
|
12
|
|
|
12
|
|
- /** @var RequestStack */
|
|
13
|
|
- protected $requestStack;
|
|
|
13
|
+ /**
|
|
|
14
|
+ * request_stack don't exist on <= 2.3, so use container to retrieve request, as mentionned in documentation
|
|
|
15
|
+ * @var ContainerInterface
|
|
|
16
|
+ */
|
|
|
17
|
+ protected $container;
|
|
14
|
18
|
|
|
15
|
19
|
/** @var TranslatorInterface */
|
|
16
|
20
|
protected $translator;
|
|
17
|
21
|
|
|
18
|
|
- public function __construct(RequestStack $requestStack, TranslatorInterface $translator)
|
|
|
22
|
+ public function __construct(ContainerInterface $container, TranslatorInterface $translator)
|
|
19
|
23
|
{
|
|
20
|
|
- $this->requestStack = $requestStack;
|
|
|
24
|
+ $this->container = $container;
|
|
21
|
25
|
$this->translator = $translator;
|
|
22
|
26
|
}
|
|
23
|
27
|
|
|
|
@@ -26,7 +30,7 @@ class DefineLocaleEventListener
|
|
26
|
30
|
$locales = ['fr_FR', 'en_GB', 'aa_BB'];
|
|
27
|
31
|
$locale = $locales[rand(0, 2)];
|
|
28
|
32
|
|
|
29
|
|
- $this->requestStack->getCurrentRequest()->setLocale($locale);
|
|
|
33
|
+ $this->container->get('request')->setLocale($locale);
|
|
30
|
34
|
$this->translator->setLocale($locale);
|
|
31
|
35
|
}
|
|
32
|
36
|
}
|