Skip to content
This repository was archived by the owner on Jan 1, 2023. It is now read-only.

Commit 6705ea4

Browse files
committed
bug #402 fix request in DefaultValueSupplier (albert-gonzalez)
This PR was squashed before being merged into the 2.7-dev branch (closes #402). Discussion ---------- fix request in DefaultValueSupplier In Symfony 3 the service 'request' has been removed from the container, and the function isScopeActive doesn't exist anymore. With this fix the Request Stack is injected in DefaultValueSupplier to get the request. Commits ------- 29198ae fix request in DefaultValueSupplier
2 parents d444bd0 + 29198ae commit 6705ea4

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

DefaultValueSupplier.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,32 @@ public function __construct(ContainerInterface $container)
3030

3131
public function getValues()
3232
{
33-
if (!$this->container->isScopeActive('request')) {
33+
$request = $this->getCurrentRequest();
34+
35+
if (!$request) {
3436
return array();
3537
}
3638

37-
$request = $this->container->get('request');
38-
3939
return array(
4040
'locale' => $request->getLocale(),
4141
'env' => $this->container->getParameter('kernel.environment'),
4242
);
4343
}
44+
45+
/**
46+
* @return null|\Symfony\Component\HttpFoundation\Request
47+
*/
48+
private function getCurrentRequest()
49+
{
50+
$request = null;
51+
$requestStack = $this->container->get('request_stack', ContainerInterface::NULL_ON_INVALID_REFERENCE);
52+
53+
if ($requestStack) {
54+
$request = $requestStack->getCurrentRequest();
55+
} elseif ($this->container->isScopeActive('request')) {
56+
$request = $this->container->get('request');
57+
}
58+
59+
return $request;
60+
}
4461
}

0 commit comments

Comments
 (0)