Skip to content

Commit 8a58d96

Browse files
Merge branch '3.4'
* 3.4: [VarDumper] Fix tests with phpredis 3.1.3 [Routing] Use "controller" keyword for configuring routes controllers [VarDumper] Fix interval caster with PT3600S-like spec [DI] Fix reading env vars from fastcgi params [HttpKernel] Remove old container files Allow phpdocumentor/reflection-docblock 4. [VarDumper] play nice with open_basedir when looking for composer.json
2 parents befad63 + 16d34eb commit 8a58d96

31 files changed

+399
-37
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
"symfony/phpunit-bridge": "~3.2",
9696
"symfony/polyfill-apcu": "~1.1",
9797
"symfony/security-acl": "~2.8|~3.0",
98-
"phpdocumentor/reflection-docblock": "^3.0"
98+
"phpdocumentor/reflection-docblock": "^3.0|^4.0"
9999
},
100100
"conflict": {
101101
"phpdocumentor/reflection-docblock": "<3.0||>=3.2.0,<3.2.2",

src/Symfony/Bundle/FrameworkBundle/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"symfony/property-info": "~3.4|~4.0",
5656
"symfony/web-link": "~3.4|~4.0",
5757
"doctrine/annotations": "~1.0",
58-
"phpdocumentor/reflection-docblock": "^3.0",
58+
"phpdocumentor/reflection-docblock": "^3.0|^4.0",
5959
"twig/twig": "~1.34|~2.4"
6060
},
6161
"conflict": {

src/Symfony/Component/DependencyInjection/Compiler/ServiceLocatorTagPass.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,17 @@ protected function processValue($value, $isRoot = false)
5454

5555
$value->setArguments($arguments);
5656

57-
if ($public = $value->isPublic()) {
58-
$value->setPublic(false);
59-
}
6057
$id = 'service_locator.'.ContainerBuilder::hash($value);
6158

6259
if ($isRoot) {
6360
if ($id !== $this->currentId) {
64-
$this->container->setAlias($id, new Alias($this->currentId, $public));
61+
$this->container->setAlias($id, new Alias($this->currentId, false));
6562
}
6663

6764
return $value;
6865
}
6966

70-
$this->container->setDefinition($id, $value);
67+
$this->container->setDefinition($id, $value->setPublic(false));
7168

7269
return new Reference($id);
7370
}

src/Symfony/Component/DependencyInjection/Container.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ protected function load($file)
332332
*
333333
* @param string $name The name of the environment variable
334334
*
335-
* @return scalar The value to use for the provided environment variable name
335+
* @return mixed The value to use for the provided environment variable name
336336
*
337337
* @throws EnvNotFoundException When the environment variable is not found and has no default value
338338
*/
@@ -341,6 +341,9 @@ protected function getEnv($name)
341341
if (isset($this->envCache[$name]) || array_key_exists($name, $this->envCache)) {
342342
return $this->envCache[$name];
343343
}
344+
if (0 !== strpos($name, 'HTTP_') && isset($_SERVER[$name])) {
345+
return $this->envCache[$name] = $_SERVER[$name];
346+
}
344347
if (isset($_ENV[$name])) {
345348
return $this->envCache[$name] = $_ENV[$name];
346349
}

src/Symfony/Component/DependencyInjection/ContainerBuilder.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -682,9 +682,10 @@ public function compile(bool $resolveEnvPlaceholders = false)
682682
$bag = $this->getParameterBag();
683683

684684
if ($resolveEnvPlaceholders && $bag instanceof EnvPlaceholderParameterBag) {
685-
$this->parameterBag = new ParameterBag($this->resolveEnvPlaceholders($bag->all(), true));
685+
$bag->resolveEnvReferences();
686+
$this->parameterBag = new ParameterBag($bag->all());
686687
$this->envPlaceholders = $bag->getEnvPlaceholders();
687-
$this->parameterBag = $bag = new ParameterBag($this->resolveEnvPlaceholders($this->parameterBag->all()));
688+
$this->parameterBag = $bag = new ParameterBag($this->resolveEnvPlaceholders($bag->all(), true));
688689
}
689690

690691
$compiler->compile($this);
@@ -699,7 +700,9 @@ public function compile(bool $resolveEnvPlaceholders = false)
699700

700701
parent::compile();
701702

702-
$this->envPlaceholders = $bag instanceof EnvPlaceholderParameterBag ? $bag->getEnvPlaceholders() : array();
703+
if ($bag instanceof EnvPlaceholderParameterBag) {
704+
$this->envPlaceholders = $bag->getEnvPlaceholders();
705+
}
703706
}
704707

705708
/**
@@ -1251,10 +1254,10 @@ public function resolveEnvPlaceholders($value, $format = null, array &$usedEnvs
12511254
foreach ($envPlaceholders as $env => $placeholders) {
12521255
foreach ($placeholders as $placeholder) {
12531256
if (false !== stripos($value, $placeholder)) {
1254-
if (true === $format) {
1255-
$resolved = $bag->escapeValue($this->getEnv($env));
1256-
} else {
1257+
if (true !== $format) {
12571258
$resolved = sprintf($format, $env);
1259+
} elseif ($placeholder === $resolved = $bag->escapeValue($this->getEnv($env))) {
1260+
$resolved = $bag->all()[strtolower("env($env)")];
12581261
}
12591262
$value = str_ireplace($placeholder, $resolved, $value);
12601263
$usedEnvs[$env] = $env;

src/Symfony/Component/DependencyInjection/ParameterBag/EnvPlaceholderParameterBag.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
class EnvPlaceholderParameterBag extends ParameterBag
2121
{
2222
private $envPlaceholders = array();
23+
private $resolveEnvReferences = false;
2324

2425
/**
2526
* {@inheritdoc}
@@ -101,4 +102,29 @@ public function resolve()
101102
}
102103
}
103104
}
105+
106+
/**
107+
* Replaces "%env(FOO)%" references by their placeholder, keeping regular "%parameters%" references as is.
108+
*/
109+
public function resolveEnvReferences()
110+
{
111+
$this->resolveEnvReferences = true;
112+
try {
113+
$this->resolve();
114+
} finally {
115+
$this->resolveEnvReferences = false;
116+
}
117+
}
118+
119+
/**
120+
* {@inheritdoc}
121+
*/
122+
public function resolveString($value, array $resolving = array())
123+
{
124+
if ($this->resolveEnvReferences) {
125+
return preg_replace_callback('/%%|%(env\([^%\s]+\))%/', function ($match) { return isset($match[1]) ? $this->get($match[1]) : '%%'; }, $value);
126+
}
127+
128+
return parent::resolveString($value, $resolving);
129+
}
104130
}

src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -603,29 +603,37 @@ public function testMergeThrowsExceptionForDuplicateAutomaticInstanceofDefinitio
603603
public function testResolveEnvValues()
604604
{
605605
$_ENV['DUMMY_ENV_VAR'] = 'du%%y';
606+
$_SERVER['DUMMY_SERVER_VAR'] = 'ABC';
607+
$_SERVER['HTTP_DUMMY_VAR'] = 'DEF';
606608

607609
$container = new ContainerBuilder();
608-
$container->setParameter('bar', '%% %env(DUMMY_ENV_VAR)%');
610+
$container->setParameter('bar', '%% %env(DUMMY_ENV_VAR)% %env(DUMMY_SERVER_VAR)% %env(HTTP_DUMMY_VAR)%');
611+
$container->setParameter('env(HTTP_DUMMY_VAR)', '123');
609612

610-
$this->assertSame('%% du%%%%y', $container->resolveEnvPlaceholders('%bar%', true));
613+
$this->assertSame('%% du%%%%y ABC 123', $container->resolveEnvPlaceholders('%bar%', true));
611614

612-
unset($_ENV['DUMMY_ENV_VAR']);
615+
unset($_ENV['DUMMY_ENV_VAR'], $_SERVER['DUMMY_SERVER_VAR'], $_SERVER['HTTP_DUMMY_VAR']);
613616
}
614617

615618
public function testCompileWithResolveEnv()
616619
{
617-
$_ENV['DUMMY_ENV_VAR'] = 'du%%y';
620+
putenv('DUMMY_ENV_VAR=du%%y');
621+
$_SERVER['DUMMY_SERVER_VAR'] = 'ABC';
622+
$_SERVER['HTTP_DUMMY_VAR'] = 'DEF';
618623

619624
$container = new ContainerBuilder();
620625
$container->setParameter('env(FOO)', 'Foo');
621-
$container->setParameter('bar', '%% %env(DUMMY_ENV_VAR)%');
626+
$container->setParameter('bar', '%% %env(DUMMY_ENV_VAR)% %env(DUMMY_SERVER_VAR)% %env(HTTP_DUMMY_VAR)%');
622627
$container->setParameter('foo', '%env(FOO)%');
628+
$container->setParameter('baz', '%foo%');
629+
$container->setParameter('env(HTTP_DUMMY_VAR)', '123');
623630
$container->compile(true);
624631

625-
$this->assertSame('% du%%y', $container->getParameter('bar'));
626-
$this->assertSame('Foo', $container->getParameter('foo'));
632+
$this->assertSame('% du%%y ABC 123', $container->getParameter('bar'));
633+
$this->assertSame('Foo', $container->getParameter('baz'));
627634

628-
unset($_ENV['DUMMY_ENV_VAR']);
635+
unset($_SERVER['DUMMY_SERVER_VAR'], $_SERVER['HTTP_DUMMY_VAR']);
636+
putenv('DUMMY_ENV_VAR');
629637
}
630638

631639
/**

src/Symfony/Component/HttpKernel/Kernel.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,11 @@ protected function initializeContainer()
527527
file_put_contents($this->getCacheDir().'/'.$class.'Compiler.log', null !== $container ? implode("\n", $container->getCompiler()->getLog()) : '');
528528
}
529529
}
530+
531+
if ($oldContainer = file_exists($cache->getPath()) ? @include $cache->getPath() : false) {
532+
$oldContainer = new \ReflectionClass($oldContainer);
533+
}
534+
530535
$this->dumpContainer($cache, $container, $class, $this->getContainerBaseClass());
531536

532537
$fresh = false;
@@ -535,7 +540,15 @@ protected function initializeContainer()
535540
$this->container = require $cache->getPath();
536541
$this->container->set('kernel', $this);
537542

538-
if (!$fresh && $this->container->has('cache_warmer')) {
543+
if ($fresh) {
544+
return;
545+
}
546+
547+
if ($oldContainer && get_class($this->container) !== $oldContainer->name) {
548+
(new Filesystem())->remove(dirname($oldContainer->getFileName()));
549+
}
550+
551+
if ($this->container->has('cache_warmer')) {
539552
$this->container->get('cache_warmer')->warmUp($this->container->getParameter('kernel.cache_dir'));
540553
}
541554
}
@@ -687,6 +700,9 @@ protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container
687700
@chmod($dir.$file, 0666 & ~umask());
688701
}
689702

703+
// track changes made to the container directory
704+
$container->fileExists(dirname($dir.$file));
705+
690706
$cache->write($rootCode, $container->getResources());
691707
}
692708

src/Symfony/Component/HttpKernel/Tests/KernelTest.php

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,40 @@ public function testKernelRootDirNameStartingWithANumber()
725725
$this->assertEquals('_123', $kernel->getName());
726726
}
727727

728+
public function testProjectDirExtension()
729+
{
730+
$kernel = new CustomProjectDirKernel();
731+
$kernel->boot();
732+
733+
$this->assertSame('foo', $kernel->getProjectDir());
734+
$this->assertSame('foo', $kernel->getContainer()->getParameter('kernel.project_dir'));
735+
}
736+
737+
public function testKernelReset()
738+
{
739+
(new Filesystem())->remove(__DIR__.'/Fixtures/cache');
740+
741+
$kernel = new CustomProjectDirKernel();
742+
$kernel->boot();
743+
744+
$containerClass = get_class($kernel->getContainer());
745+
$containerFile = (new \ReflectionClass($kernel->getContainer()))->getFileName();
746+
unlink(__DIR__.'/Fixtures/cache/custom/FixturesCustomDebugProjectContainer.php.meta');
747+
748+
$kernel = new CustomProjectDirKernel();
749+
$kernel->boot();
750+
751+
$this->assertSame($containerClass, get_class($kernel->getContainer()));
752+
$this->assertFileExists($containerFile);
753+
unlink(__DIR__.'/Fixtures/cache/custom/FixturesCustomDebugProjectContainer.php.meta');
754+
755+
$kernel = new CustomProjectDirKernel(function ($container) { $container->register('foo', 'stdClass'); });
756+
$kernel->boot();
757+
758+
$this->assertTrue(get_class($kernel->getContainer()) !== $containerClass);
759+
$this->assertFileNotExists($containerFile);
760+
}
761+
728762
/**
729763
* Returns a mock for the BundleInterface.
730764
*
@@ -825,12 +859,14 @@ public function handle(Request $request, $type = self::MASTER_REQUEST, $catch =
825859
class CustomProjectDirKernel extends Kernel
826860
{
827861
private $baseDir;
862+
private $buildContainer;
828863

829-
public function __construct()
864+
public function __construct(\Closure $buildContainer = null)
830865
{
831-
parent::__construct('test', false);
866+
parent::__construct('custom', true);
832867

833868
$this->baseDir = 'foo';
869+
$this->buildContainer = $buildContainer;
834870
}
835871

836872
public function registerBundles()
@@ -851,4 +887,11 @@ public function getRootDir()
851887
{
852888
return __DIR__.'/Fixtures';
853889
}
890+
891+
protected function build(ContainerBuilder $container)
892+
{
893+
if ($build = $this->buildContainer) {
894+
$build($container);
895+
}
896+
}
854897
}

src/Symfony/Component/PropertyInfo/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"symfony/serializer": "~3.4|~4.0",
3131
"symfony/cache": "~3.4|~4.0",
3232
"symfony/dependency-injection": "~3.4|~4.0",
33-
"phpdocumentor/reflection-docblock": "^3.0",
33+
"phpdocumentor/reflection-docblock": "^3.0|^4.0",
3434
"doctrine/annotations": "~1.0"
3535
},
3636
"conflict": {

0 commit comments

Comments
 (0)