Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 85f03e1

Browse filesBrowse files
Merge branch '3.3' into 3.4
* 3.3: [Dotenv] Get env using $_SERVER to work with fastcgi_param and workaround thread safety issues [Dotenv][WebServerBundle] Override previously loaded variables [DI] Use GlobResource for non-tracked directories [WebProfilerBundle] Re add missing link to the controller
2 parents 3946812 + 420f089 commit 85f03e1
Copy full SHA for 85f03e1

File tree

8 files changed

+127
-17
lines changed
Filter options

8 files changed

+127
-17
lines changed

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1441,7 +1441,7 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
14411441
$fileRecorder('yml', $file);
14421442
}
14431443

1444-
if ($container->fileExists($dir = $dirname.'/Resources/config/serialization')) {
1444+
if ($container->fileExists($dir = $dirname.'/Resources/config/serialization', '/^$/')) {
14451445
$this->registerMappingFilesFromDir($dir, $fileRecorder);
14461446
}
14471447
}

‎src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php
+7-3Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Bridge\Twig\Extension\WebLinkExtension;
1515
use Symfony\Component\Config\FileLocator;
16+
use Symfony\Component\Config\Resource\FileExistenceResource;
1617
use Symfony\Component\Console\Application;
1718
use Symfony\Component\DependencyInjection\ContainerBuilder;
1819
use Symfony\Component\DependencyInjection\Reference;
@@ -124,9 +125,10 @@ public function load(array $configs, ContainerBuilder $container)
124125
}
125126
}
126127

127-
if ($container->fileExists($dir = $container->getParameter('kernel.root_dir').'/Resources/views', false)) {
128+
if (file_exists($dir = $container->getParameter('kernel.root_dir').'/Resources/views')) {
128129
$twigFilesystemLoaderDefinition->addMethodCall('addPath', array($dir));
129130
}
131+
$container->addResource(new FileExistenceResource($dir));
130132

131133
if (!empty($config['globals'])) {
132134
$def = $container->getDefinition('twig');
@@ -185,13 +187,15 @@ private function getBundleHierarchy(ContainerBuilder $container)
185187
);
186188
}
187189

188-
if ($container->fileExists($dir = $container->getParameter('kernel.root_dir').'/Resources/'.$name.'/views', false)) {
190+
if (file_exists($dir = $container->getParameter('kernel.root_dir').'/Resources/'.$name.'/views')) {
189191
$bundleHierarchy[$name]['paths'][] = $dir;
190192
}
193+
$container->addResource(new FileExistenceResource($dir));
191194

192-
if ($container->fileExists($dir = $bundle['path'].'/Resources/views', false)) {
195+
if (file_exists($dir = $bundle['path'].'/Resources/views')) {
193196
$bundleHierarchy[$name]['paths'][] = $dir;
194197
}
198+
$container->addResource(new FileExistenceResource($dir));
195199

196200
if (null === $bundle['parent']) {
197201
continue;

‎src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/request.html.twig

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/request.html.twig
+8-4Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
{% extends '@WebProfiler/Profiler/layout.html.twig' %}
22

33
{% block toolbar %}
4+
{% import _self as helper %}
45
{% set request_handler %}
5-
{% import _self as helper %}
66
{{ helper.set_handler(collector.controller) }}
77
{% endset %}
88

99
{% if collector.redirect %}
1010
{% set redirect_handler %}
11-
{% import _self as helper %}
1211
{{ helper.set_handler(collector.redirect.controller, collector.redirect.route, 'GET' != collector.redirect.method ? collector.redirect.method) }}
1312
{% endset %}
1413
{% endif %}
1514

1615
{% if collector.forward|default(false) %}
1716
{% set forward_handler %}
18-
{% import _self as helper %}
1917
{{ helper.set_handler(collector.forward.controller) }}
2018
{% endset %}
2119
{% endif %}
@@ -108,6 +106,12 @@
108106
{% endblock %}
109107

110108
{% block panel %}
109+
{% import _self as helper %}
110+
111+
<h2>
112+
{{ helper.set_handler(collector.controller) }}
113+
</h2>
114+
111115
<div class="sf-tabs">
112116
<div class="tab">
113117
<h3 class="tab-title">Request</h3>
@@ -268,7 +272,7 @@
268272
{% for child in profile.children %}
269273
<h3>
270274
<a href="{{ path('_profiler', { token: child.token }) }}">
271-
{{- child.getcollector('request').identifier -}}
275+
{{ helper.set_handler(child.getcollector('request').controller) }}
272276
</a>
273277
<small>(token = {{ child.token }})</small>
274278
</h3>

‎src/Symfony/Bundle/WebServerBundle/WebServer.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/WebServerBundle/WebServer.php
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ private function createServerProcess(WebServerConfig $config)
154154
$process->setWorkingDirectory($config->getDocumentRoot());
155155
$process->setTimeout(null);
156156

157+
if (in_array('APP_ENV', explode(',', getenv('SYMFONY_DOTENV_VARS')))) {
158+
$process->setEnv(array('APP_ENV' => false));
159+
$process->inheritEnvironmentVariables();
160+
}
161+
157162
return $process;
158163
}
159164

‎src/Symfony/Component/DependencyInjection/Container.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Container.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,13 +452,13 @@ protected function getEnv($name)
452452
if (isset($this->envCache[$name]) || array_key_exists($name, $this->envCache)) {
453453
return $this->envCache[$name];
454454
}
455-
if (0 !== strpos($name, 'HTTP_') && isset($_SERVER[$name])) {
455+
if (isset($_SERVER[$name]) && 0 !== strpos($name, 'HTTP_')) {
456456
return $this->envCache[$name] = $_SERVER[$name];
457457
}
458458
if (isset($_ENV[$name])) {
459459
return $this->envCache[$name] = $_ENV[$name];
460460
}
461-
if (false !== $env = getenv($name)) {
461+
if (false !== ($env = getenv($name)) && null !== $env) { // null is a possible value because of thread safety issues
462462
return $this->envCache[$name] = $env;
463463
}
464464
if (!$this->hasParameter("env($name)")) {

‎src/Symfony/Component/DependencyInjection/ContainerBuilder.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/ContainerBuilder.php
+7-3Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,13 @@ public function fileExists($path, $trackContents = true)
408408
return $exists;
409409
}
410410

411-
if ($trackContents && is_dir($path)) {
412-
$this->addResource(new DirectoryResource($path, is_string($trackContents) ? $trackContents : null));
413-
} elseif ($trackContents || is_dir($path)) {
411+
if (is_dir($path)) {
412+
if ($trackContents) {
413+
$this->addResource(new DirectoryResource($path, is_string($trackContents) ? $trackContents : null));
414+
} else {
415+
$this->addResource(new GlobResource($path, '/*', false));
416+
}
417+
} elseif ($trackContents) {
414418
$this->addResource(new FileResource($path));
415419
}
416420

‎src/Symfony/Component/Dotenv/Dotenv.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Dotenv/Dotenv.php
+28-4Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,36 @@ public function load($path/*, ...$paths*/)
6060
/**
6161
* Sets values as environment variables (via putenv, $_ENV, and $_SERVER).
6262
*
63-
* Note that existing environment variables are never overridden.
63+
* Note that existing environment variables are not overridden.
6464
*
6565
* @param array $values An array of env variables
6666
*/
6767
public function populate($values)
6868
{
69+
$loadedVars = array_flip(explode(',', getenv('SYMFONY_DOTENV_VARS')));
70+
unset($loadedVars['']);
71+
6972
foreach ($values as $name => $value) {
70-
if (isset($_ENV[$name]) || isset($_SERVER[$name]) || false !== getenv($name)) {
73+
$notHttpName = 0 !== strpos($name, 'HTTP_');
74+
// don't check existence with getenv() because of thread safety issues
75+
if (!isset($loadedVars[$name]) && (isset($_ENV[$name]) || (isset($_SERVER[$name]) && $notHttpName))) {
7176
continue;
7277
}
7378

7479
putenv("$name=$value");
7580
$_ENV[$name] = $value;
76-
$_SERVER[$name] = $value;
81+
if ($notHttpName) {
82+
$_SERVER[$name] = $value;
83+
}
84+
85+
$loadedVars[$name] = true;
86+
}
87+
88+
if ($loadedVars) {
89+
$loadedVars = implode(',', array_keys($loadedVars));
90+
putenv("SYMFONY_DOTENV_VARS=$loadedVars");
91+
$_ENV['SYMFONY_DOTENV_VARS'] = $loadedVars;
92+
$_SERVER['SYMFONY_DOTENV_VARS'] = $loadedVars;
7793
}
7894
}
7995

@@ -351,7 +367,15 @@ private function resolveVariables($value)
351367
}
352368

353369
$name = $matches[3];
354-
$value = isset($this->values[$name]) ? $this->values[$name] : (isset($_ENV[$name]) ? $_ENV[$name] : (string) getenv($name));
370+
if (isset($this->values[$name])) {
371+
$value = $this->values[$name];
372+
} elseif (isset($_SERVER[$name]) && 0 !== strpos($name, 'HTTP_')) {
373+
$value = $_SERVER[$name];
374+
} elseif (isset($_ENV[$name])) {
375+
$value = $_ENV[$name];
376+
} else {
377+
$value = (string) getenv($name);
378+
}
355379

356380
if (!$matches[2] && isset($matches[4])) {
357381
$value .= '}';

‎src/Symfony/Component/Dotenv/Tests/DotenvTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Dotenv/Tests/DotenvTest.php
+69Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,79 @@ public function testServerSuperglobalIsNotOverriden()
208208
public function testEnvVarIsNotOverriden()
209209
{
210210
putenv('TEST_ENV_VAR=original_value');
211+
$_SERVER['TEST_ENV_VAR'] = 'original_value';
211212

212213
$dotenv = new DotEnv();
213214
$dotenv->populate(array('TEST_ENV_VAR' => 'new_value'));
214215

215216
$this->assertSame('original_value', getenv('TEST_ENV_VAR'));
216217
}
218+
219+
public function testHttpVarIsPartiallyOverriden()
220+
{
221+
$_SERVER['HTTP_TEST_ENV_VAR'] = 'http_value';
222+
223+
$dotenv = new DotEnv();
224+
$dotenv->populate(array('HTTP_TEST_ENV_VAR' => 'env_value'));
225+
226+
$this->assertSame('env_value', getenv('HTTP_TEST_ENV_VAR'));
227+
$this->assertSame('env_value', $_ENV['HTTP_TEST_ENV_VAR']);
228+
$this->assertSame('http_value', $_SERVER['HTTP_TEST_ENV_VAR']);
229+
}
230+
231+
public function testMemorizingLoadedVarsNamesInSpecialVar()
232+
{
233+
// Special variable not exists
234+
unset($_ENV['SYMFONY_DOTENV_VARS']);
235+
unset($_SERVER['SYMFONY_DOTENV_VARS']);
236+
putenv('SYMFONY_DOTENV_VARS');
237+
238+
unset($_ENV['APP_DEBUG']);
239+
unset($_SERVER['APP_DEBUG']);
240+
putenv('APP_DEBUG');
241+
unset($_ENV['DATABASE_URL']);
242+
unset($_SERVER['DATABASE_URL']);
243+
putenv('DATABASE_URL');
244+
245+
$dotenv = new DotEnv();
246+
$dotenv->populate(array('APP_DEBUG' => '1', 'DATABASE_URL' => 'mysql://root@localhost/db'));
247+
248+
$this->assertSame('APP_DEBUG,DATABASE_URL', getenv('SYMFONY_DOTENV_VARS'));
249+
250+
// Special variable has a value
251+
$_ENV['SYMFONY_DOTENV_VARS'] = 'APP_ENV';
252+
$_SERVER['SYMFONY_DOTENV_VARS'] = 'APP_ENV';
253+
putenv('SYMFONY_DOTENV_VARS=APP_ENV');
254+
255+
$_ENV['APP_DEBUG'] = '1';
256+
$_SERVER['APP_DEBUG'] = '1';
257+
putenv('APP_DEBUG=1');
258+
unset($_ENV['DATABASE_URL']);
259+
unset($_SERVER['DATABASE_URL']);
260+
putenv('DATABASE_URL');
261+
262+
$dotenv = new DotEnv();
263+
$dotenv->populate(array('APP_DEBUG' => '0', 'DATABASE_URL' => 'mysql://root@localhost/db'));
264+
$dotenv->populate(array('DATABASE_URL' => 'sqlite:///somedb.sqlite'));
265+
266+
$this->assertSame('APP_ENV,DATABASE_URL', getenv('SYMFONY_DOTENV_VARS'));
267+
}
268+
269+
public function testOverridingEnvVarsWithNamesMemorizedInSpecialVar()
270+
{
271+
putenv('SYMFONY_DOTENV_VARS=FOO,BAR,BAZ');
272+
273+
putenv('FOO=foo');
274+
putenv('BAR=bar');
275+
putenv('BAZ=baz');
276+
putenv('DOCUMENT_ROOT=/var/www');
277+
278+
$dotenv = new DotEnv();
279+
$dotenv->populate(array('FOO' => 'foo1', 'BAR' => 'bar1', 'BAZ' => 'baz1', 'DOCUMENT_ROOT' => '/boot'));
280+
281+
$this->assertSame('foo1', getenv('FOO'));
282+
$this->assertSame('bar1', getenv('BAR'));
283+
$this->assertSame('baz1', getenv('BAZ'));
284+
$this->assertSame('/var/www', getenv('DOCUMENT_ROOT'));
285+
}
217286
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.