Skip to content

Commit bf175ee

Browse files
Merge branch '3.4'
* 3.4: [Bridge\Doctrine][FrameworkBundle] Deprecate some remaining uses of ContainerAwareTrait [FrameworkBundle] Fix bad interface hint in AbstractController [VarDumper] deprecate MongoCaster [HttpFoundation] deprecate using with the legacy mongo extension; use it with the mongodb/mongodb package and ext-mongodb instead Fix BC layer Reset profiler. [DI] Improve some deprecation messages [DI] remove inheritdoc from dumped container [Config] Fix dumped files invalidation by OPCache [Security] Add Guard authenticator <supports> method [Cache] Fix race condition in TagAwareAdapter [DI] Allow setting any public non-initialized services [Yaml] parse references on merge keys treat trailing backslashes in multi-line strings [FrameworkBundle] Expose dotenv in bin/console about fix refreshing line numbers for the inline parser fix version in changelog [FrameworkBundle] Make Controller helpers final [DoctrineBridge] Deprecate DbalSessionHandler
2 parents 4e08955 + 73606a6 commit bf175ee

File tree

12 files changed

+278
-75
lines changed

12 files changed

+278
-75
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ CHANGELOG
8181
and `YamlLintCommand` classes have been marked as final
8282
* Added `asset.request_context.base_path` and `asset.request_context.secure` parameters
8383
to provide a default request context in case the stack is empty (similar to `router.request_context.*` parameters)
84+
* Display environment variables managed by `Dotenv` in `AboutCommand`
8485

8586
3.3.0
8687
-----

Command/AboutCommand.php

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,19 @@ class AboutCommand extends Command
3636
*/
3737
protected function configure()
3838
{
39-
$this->setDescription('Displays information about the current project');
39+
$this
40+
->setDescription('Displays information about the current project')
41+
->setHelp(<<<'EOT'
42+
The <info>%command.name%</info> command displays information about the current Symfony project.
43+
44+
The <info>PHP</info> section displays important configuration that could affect your application. The values might
45+
be different between web and CLI.
46+
47+
The <info>Environment</info> section displays the current environment variables managed by Symfony Dotenv. It will not
48+
be shown if no variables were found. The values might be different between web and CLI.
49+
EOT
50+
)
51+
;
4052
}
4153

4254
/**
@@ -49,7 +61,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
4961
/** @var $kernel KernelInterface */
5062
$kernel = $this->getApplication()->getKernel();
5163

52-
$io->table(array(), array(
64+
$rows = array(
5365
array('<info>Symfony</>'),
5466
new TableSeparator(),
5567
array('Version', Kernel::VERSION),
@@ -76,7 +88,19 @@ protected function execute(InputInterface $input, OutputInterface $output)
7688
array('OPcache', extension_loaded('Zend OPcache') && ini_get('opcache.enable') ? 'true' : 'false'),
7789
array('APCu', extension_loaded('apcu') && ini_get('apc.enabled') ? 'true' : 'false'),
7890
array('Xdebug', extension_loaded('xdebug') ? 'true' : 'false'),
79-
));
91+
);
92+
93+
if ($dotenv = self::getDotEnvVars()) {
94+
$rows = array_merge($rows, array(
95+
new TableSeparator(),
96+
array('<info>Environment (.env)</>'),
97+
new TableSeparator(),
98+
), array_map(function ($value, $name) {
99+
return array($name, $value);
100+
}, $dotenv, array_keys($dotenv)));
101+
}
102+
103+
$io->table(array(), $rows);
80104
}
81105

82106
private static function formatPath($path, $baseDir = null)
@@ -104,4 +128,16 @@ private static function isExpired($date)
104128

105129
return false !== $date && new \DateTime() > $date->modify('last day of this month 23:59:59');
106130
}
131+
132+
private static function getDotEnvVars()
133+
{
134+
$vars = array();
135+
foreach (explode(',', getenv('SYMFONY_DOTENV_VARS')) as $name) {
136+
if ('' !== $name && false !== $value = getenv($name)) {
137+
$vars[$name] = $value;
138+
}
139+
}
140+
141+
return $vars;
142+
}
107143
}

Controller/Controller.php

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,6 @@ abstract class Controller implements ContainerAwareInterface
2626
use ContainerAwareTrait;
2727
use ControllerTrait;
2828

29-
/**
30-
* Returns true if the service id is defined.
31-
*
32-
* @param string $id The service id
33-
*
34-
* @return bool true if the service id is defined, false otherwise
35-
*/
36-
protected function has($id)
37-
{
38-
return $this->container->has($id);
39-
}
40-
41-
/**
42-
* Gets a container service by its id.
43-
*
44-
* @param string $id The service id
45-
*
46-
* @return object The service
47-
*/
48-
protected function get($id)
49-
{
50-
return $this->container->get($id);
51-
}
52-
5329
/**
5430
* Gets a container configuration parameter by its name.
5531
*

Controller/ControllerResolver.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,7 @@ protected function createController($controller)
4848
$resolvedController = parent::createController($controller);
4949

5050
if (1 === substr_count($controller, ':') && is_array($resolvedController)) {
51-
if ($resolvedController[0] instanceof ContainerAwareInterface) {
52-
$resolvedController[0]->setContainer($this->container);
53-
}
54-
55-
if ($resolvedController[0] instanceof AbstractController && null !== $previousContainer = $resolvedController[0]->setContainer($this->container)) {
56-
$resolvedController[0]->setContainer($previousContainer);
57-
}
51+
$resolvedController[0] = $this->configureController($resolvedController[0]);
5852
}
5953

6054
return $resolvedController;
@@ -65,9 +59,19 @@ protected function createController($controller)
6559
*/
6660
protected function instantiateController($class)
6761
{
68-
$controller = parent::instantiateController($class);
62+
return $this->configureController(parent::instantiateController($class));
63+
}
6964

65+
private function configureController($controller)
66+
{
7067
if ($controller instanceof ContainerAwareInterface) {
68+
// @deprecated switch, to be removed in 4.0 where these classes
69+
// won't implement ContainerAwareInterface anymore
70+
switch (\get_class($controller)) {
71+
case RedirectController::class:
72+
case TemplateController::class:
73+
return $controller;
74+
}
7175
$controller->setContainer($this->container);
7276
}
7377
if ($controller instanceof AbstractController && null !== $previousContainer = $controller->setContainer($this->container)) {

Controller/ControllerTrait.php

Lines changed: 71 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,34 @@
3939
*/
4040
trait ControllerTrait
4141
{
42+
/**
43+
* Returns true if the service id is defined.
44+
*
45+
* @param string $id The service id
46+
*
47+
* @return bool true if the service id is defined, false otherwise
48+
*
49+
* @final since version 3.4
50+
*/
51+
protected function has($id)
52+
{
53+
return $this->container->has($id);
54+
}
55+
56+
/**
57+
* Gets a container service by its id.
58+
*
59+
* @param string $id The service id
60+
*
61+
* @return object The service
62+
*
63+
* @final since version 3.4
64+
*/
65+
protected function get($id)
66+
{
67+
return $this->container->get($id);
68+
}
69+
4270
/**
4371
* Generates a URL from the given parameters.
4472
*
@@ -49,6 +77,8 @@ trait ControllerTrait
4977
* @return string The generated URL
5078
*
5179
* @see UrlGeneratorInterface
80+
*
81+
* @final since version 3.4
5282
*/
5383
protected function generateUrl($route, $parameters = array(), $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH)
5484
{
@@ -63,6 +93,8 @@ protected function generateUrl($route, $parameters = array(), $referenceType = U
6393
* @param array $query An array of query parameters
6494
*
6595
* @return Response A Response instance
96+
*
97+
* @final since version 3.4
6698
*/
6799
protected function forward($controller, array $path = array(), array $query = array())
68100
{
@@ -81,6 +113,8 @@ protected function forward($controller, array $path = array(), array $query = ar
81113
* @param int $status The status code to use for the Response
82114
*
83115
* @return RedirectResponse
116+
*
117+
* @final since version 3.4
84118
*/
85119
protected function redirect($url, $status = 302)
86120
{
@@ -95,6 +129,8 @@ protected function redirect($url, $status = 302)
95129
* @param int $status The status code to use for the Response
96130
*
97131
* @return RedirectResponse
132+
*
133+
* @final since version 3.4
98134
*/
99135
protected function redirectToRoute($route, array $parameters = array(), $status = 302)
100136
{
@@ -110,6 +146,8 @@ protected function redirectToRoute($route, array $parameters = array(), $status
110146
* @param array $context Context to pass to serializer when using serializer component
111147
*
112148
* @return JsonResponse
149+
*
150+
* @final since version 3.4
113151
*/
114152
protected function json($data, $status = 200, $headers = array(), $context = array())
115153
{
@@ -132,6 +170,8 @@ protected function json($data, $status = 200, $headers = array(), $context = arr
132170
* @param string $disposition Disposition of response ("attachment" is default, other type is "inline")
133171
*
134172
* @return BinaryFileResponse
173+
*
174+
* @final since version 3.4
135175
*/
136176
protected function file($file, $fileName = null, $disposition = ResponseHeaderBag::DISPOSITION_ATTACHMENT)
137177
{
@@ -148,6 +188,8 @@ protected function file($file, $fileName = null, $disposition = ResponseHeaderBa
148188
* @param string $message The message
149189
*
150190
* @throws \LogicException
191+
*
192+
* @final since version 3.4
151193
*/
152194
protected function addFlash($type, $message)
153195
{
@@ -167,6 +209,8 @@ protected function addFlash($type, $message)
167209
* @return bool
168210
*
169211
* @throws \LogicException
212+
*
213+
* @final since version 3.4
170214
*/
171215
protected function isGranted($attributes, $subject = null)
172216
{
@@ -186,6 +230,8 @@ protected function isGranted($attributes, $subject = null)
186230
* @param string $message The message passed to the exception
187231
*
188232
* @throws AccessDeniedException
233+
*
234+
* @final since version 3.4
189235
*/
190236
protected function denyAccessUnlessGranted($attributes, $subject = null, $message = 'Access Denied.')
191237
{
@@ -205,6 +251,8 @@ protected function denyAccessUnlessGranted($attributes, $subject = null, $messag
205251
* @param array $parameters An array of parameters to pass to the view
206252
*
207253
* @return string The rendered view
254+
*
255+
* @final since version 3.4
208256
*/
209257
protected function renderView($view, array $parameters = array())
210258
{
@@ -227,22 +275,24 @@ protected function renderView($view, array $parameters = array())
227275
* @param Response $response A response instance
228276
*
229277
* @return Response A Response instance
278+
*
279+
* @final since version 3.4
230280
*/
231281
protected function render($view, array $parameters = array(), Response $response = null)
232282
{
233283
if ($this->container->has('templating')) {
234-
return $this->container->get('templating')->renderResponse($view, $parameters, $response);
235-
}
236-
237-
if (!$this->container->has('twig')) {
284+
$content = $this->container->get('templating')->render($view, $parameters);
285+
} elseif ($this->container->has('twig')) {
286+
$content = $this->container->get('twig')->render($view, $parameters);
287+
} else {
238288
throw new \LogicException('You can not use the "render" method if the Templating Component or the Twig Bundle are not available.');
239289
}
240290

241291
if (null === $response) {
242292
$response = new Response();
243293
}
244294

245-
$response->setContent($this->container->get('twig')->render($view, $parameters));
295+
$response->setContent($content);
246296

247297
return $response;
248298
}
@@ -255,6 +305,8 @@ protected function render($view, array $parameters = array(), Response $response
255305
* @param StreamedResponse $response A response instance
256306
*
257307
* @return StreamedResponse A StreamedResponse instance
308+
*
309+
* @final since version 3.4
258310
*/
259311
protected function stream($view, array $parameters = array(), StreamedResponse $response = null)
260312
{
@@ -294,6 +346,8 @@ protected function stream($view, array $parameters = array(), StreamedResponse $
294346
* @param \Exception|null $previous The previous exception
295347
*
296348
* @return NotFoundHttpException
349+
*
350+
* @final since version 3.4
297351
*/
298352
protected function createNotFoundException($message = 'Not Found', \Exception $previous = null)
299353
{
@@ -311,6 +365,8 @@ protected function createNotFoundException($message = 'Not Found', \Exception $p
311365
* @param \Exception|null $previous The previous exception
312366
*
313367
* @return AccessDeniedException
368+
*
369+
* @final since version 3.4
314370
*/
315371
protected function createAccessDeniedException($message = 'Access Denied.', \Exception $previous = null)
316372
{
@@ -325,6 +381,8 @@ protected function createAccessDeniedException($message = 'Access Denied.', \Exc
325381
* @param array $options Options for the form
326382
*
327383
* @return Form
384+
*
385+
* @final since version 3.4
328386
*/
329387
protected function createForm($type, $data = null, array $options = array())
330388
{
@@ -338,6 +396,8 @@ protected function createForm($type, $data = null, array $options = array())
338396
* @param array $options Options for the form
339397
*
340398
* @return FormBuilder
399+
*
400+
* @final since version 3.4
341401
*/
342402
protected function createFormBuilder($data = null, array $options = array())
343403
{
@@ -350,6 +410,8 @@ protected function createFormBuilder($data = null, array $options = array())
350410
* @return Registry
351411
*
352412
* @throws \LogicException If DoctrineBundle is not available
413+
*
414+
* @final since version 3.4
353415
*/
354416
protected function getDoctrine()
355417
{
@@ -368,6 +430,8 @@ protected function getDoctrine()
368430
* @throws \LogicException If SecurityBundle is not available
369431
*
370432
* @see TokenInterface::getUser()
433+
*
434+
* @final since version 3.4
371435
*/
372436
protected function getUser()
373437
{
@@ -394,6 +458,8 @@ protected function getUser()
394458
* @param string $token The actual token sent with the request that should be validated
395459
*
396460
* @return bool
461+
*
462+
* @final since version 3.4
397463
*/
398464
protected function isCsrfTokenValid($id, $token)
399465
{

0 commit comments

Comments
 (0)