From b1ab7d0050be4f98bf1a5dc7cf386975b25dcb4a Mon Sep 17 00:00:00 2001 From: Tim Strehle Date: Thu, 30 Nov 2017 21:28:52 +0100 Subject: [PATCH 01/14] [WebProfilerBundle], [TwigBundle] Fix Profiler breaking XHTML pages (Content-Type: application/xhtml+xml) --- src/Symfony/Bundle/TwigBundle/Resources/views/base_js.html.twig | 2 +- .../Resources/views/Profiler/base_js.html.twig | 2 +- .../Resources/views/Profiler/toolbar_js.html.twig | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bundle/TwigBundle/Resources/views/base_js.html.twig b/src/Symfony/Bundle/TwigBundle/Resources/views/base_js.html.twig index ccabdc968fb2..0ac832ee0610 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/views/base_js.html.twig +++ b/src/Symfony/Bundle/TwigBundle/Resources/views/base_js.html.twig @@ -1,6 +1,6 @@ {# This file is based on WebProfilerBundle/Resources/views/Profiler/base_js.html.twig. If you make any change in this file, verify the same change is needed in the other file. #} -/*/*/*/* {{ include('@WebProfiler/Profiler/toolbar.css.twig', { 'position': position, 'floatable': true }) }} -/*/* Date: Fri, 1 Dec 2017 11:47:04 +0100 Subject: [PATCH 02/14] do not eagerly filter comment lines Trying to be clever by filtering commented lines inside `getNextEmbedBlock()` does not work as expected. The `#` may as well be part of a multi-line quoted string where it must not be treated as the beginning of a comment. Thus, we only must ensure that a comment-like line does not skip the process of getting the next line of the embed block. --- src/Symfony/Component/Yaml/Parser.php | 15 ++------------- .../Component/Yaml/Tests/ParserTest.php | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/Symfony/Component/Yaml/Parser.php b/src/Symfony/Component/Yaml/Parser.php index 5093d7cd1297..702df16f0aec 100644 --- a/src/Symfony/Component/Yaml/Parser.php +++ b/src/Symfony/Component/Yaml/Parser.php @@ -601,21 +601,10 @@ private function getNextEmbedBlock($indentation = null, $inSequence = false) continue; } - // we ignore "comment" lines only when we are not inside a scalar block - if (empty($blockScalarIndentations) && $this->isCurrentLineComment()) { - // remember ignored comment lines (they are used later in nested - // parser calls to determine real line numbers) - // - // CAUTION: beware to not populate the global property here as it - // will otherwise influence the getRealCurrentLineNb() call here - // for consecutive comment lines and subsequent embedded blocks - $this->locallySkippedLineNumbers[] = $this->getRealCurrentLineNb(); - - continue; - } - if ($indent >= $newIndent) { $data[] = substr($this->currentLine, $newIndent); + } elseif ($this->isCurrentLineComment()) { + $data[] = $this->currentLine; } elseif (0 == $indent) { $this->moveToPreviousLine(); diff --git a/src/Symfony/Component/Yaml/Tests/ParserTest.php b/src/Symfony/Component/Yaml/Tests/ParserTest.php index f98ac7f51c97..7a3c40571432 100644 --- a/src/Symfony/Component/Yaml/Tests/ParserTest.php +++ b/src/Symfony/Component/Yaml/Tests/ParserTest.php @@ -1554,6 +1554,24 @@ public function testMultiLineQuotedStringWithTrailingBackslash() $this->assertSame(array('foobar' => 'foobar'), $this->parser->parse($yaml)); } + public function testCommentCharactersInMultiLineQuotedStrings() + { + $yaml = << array( + 'foobar' => 'foo #bar', + 'bar' => 'baz', + ), + ); + + $this->assertSame($expected, $this->parser->parse($yaml)); + } + public function testParseMultiLineUnquotedString() { $yaml = << Date: Mon, 30 Oct 2017 06:23:08 +0100 Subject: [PATCH 03/14] [Validator] ExpressionValidator should use OBJECT_TO_STRING to allow value in message --- .../Constraints/ExpressionValidator.php | 4 +-- .../Constraints/ExpressionValidatorTest.php | 34 +++++++++++++++++++ .../Validator/Tests/Fixtures/ToString.php | 22 ++++++++++++ 3 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 src/Symfony/Component/Validator/Tests/Fixtures/ToString.php diff --git a/src/Symfony/Component/Validator/Constraints/ExpressionValidator.php b/src/Symfony/Component/Validator/Constraints/ExpressionValidator.php index 360ec5a8d9e8..96761f51f2c2 100644 --- a/src/Symfony/Component/Validator/Constraints/ExpressionValidator.php +++ b/src/Symfony/Component/Validator/Constraints/ExpressionValidator.php @@ -78,11 +78,11 @@ public function validate($value, Constraint $constraint) if (!$this->getExpressionLanguage()->evaluate($constraint->expression, $variables)) { if ($this->context instanceof ExecutionContextInterface) { $this->context->buildViolation($constraint->message) - ->setParameter('{{ value }}', $this->formatValue($value)) + ->setParameter('{{ value }}', $this->formatValue($value, self::OBJECT_TO_STRING)) ->addViolation(); } else { $this->buildViolation($constraint->message) - ->setParameter('{{ value }}', $this->formatValue($value)) + ->setParameter('{{ value }}', $this->formatValue($value, self::OBJECT_TO_STRING)) ->addViolation(); } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/ExpressionValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/ExpressionValidatorTest.php index 3b6de4d41258..be15967dcbd8 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/ExpressionValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/ExpressionValidatorTest.php @@ -15,6 +15,7 @@ use Symfony\Component\Validator\Constraints\Expression; use Symfony\Component\Validator\Constraints\ExpressionValidator; use Symfony\Component\Validator\Tests\Fixtures\Entity; +use Symfony\Component\Validator\Tests\Fixtures\ToString; use Symfony\Component\Validator\Validation; class ExpressionValidatorTest extends AbstractConstraintValidatorTest @@ -90,6 +91,39 @@ public function testFailingExpressionAtObjectLevel() ->assertRaised(); } + public function testSucceedingExpressionAtObjectLevelWithToString() + { + $constraint = new Expression('this.data == 1'); + + $object = new ToString(); + $object->data = '1'; + + $this->setObject($object); + + $this->validator->validate($object, $constraint); + + $this->assertNoViolation(); + } + + public function testFailingExpressionAtObjectLevelWithToString() + { + $constraint = new Expression(array( + 'expression' => 'this.data == 1', + 'message' => 'myMessage', + )); + + $object = new ToString(); + $object->data = '2'; + + $this->setObject($object); + + $this->validator->validate($object, $constraint); + + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', 'toString') + ->assertRaised(); + } + public function testSucceedingExpressionAtPropertyLevel() { $constraint = new Expression('value == this.data'); diff --git a/src/Symfony/Component/Validator/Tests/Fixtures/ToString.php b/src/Symfony/Component/Validator/Tests/Fixtures/ToString.php new file mode 100644 index 000000000000..714fdb9e98f5 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Fixtures/ToString.php @@ -0,0 +1,22 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Validator\Tests\Fixtures; + +class ToString +{ + public $data; + + public function __toString() + { + return 'toString'; + } +} From 3e7780cb908b34903f2ea82b5070c532a8e71c04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Fri, 1 Dec 2017 20:16:54 +0100 Subject: [PATCH 04/14] [link] Prevent warnings when running link with 2.7 --- link | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/link b/link index f4070998e72b..3bbc97f041a2 100755 --- a/link +++ b/link @@ -35,11 +35,14 @@ if (!is_dir("$argv[1]/vendor/symfony")) { } $sfPackages = array('symfony/symfony' => __DIR__); + +$filesystem = new Filesystem(); foreach (glob(__DIR__.'/src/Symfony/{Bundle,Bridge,Component,Component/Security}/*', GLOB_BRACE | GLOB_ONLYDIR | GLOB_NOSORT) as $dir) { - $sfPackages[json_decode(file_get_contents("$dir/composer.json"))->name] = $dir; + if ($filesystem->exists($composer = "$dir/composer.json")) { + $sfPackages[json_decode(file_get_contents($composer))->name] = $dir; + } } -$filesystem = new Filesystem(); foreach (glob("$argv[1]/vendor/symfony/*", GLOB_ONLYDIR | GLOB_NOSORT) as $dir) { $package = 'symfony/'.basename($dir); if (is_link($dir)) { From 28175767d2bbbec9fba509afd08a45cca9d63b0c Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sat, 2 Dec 2017 00:46:52 +0100 Subject: [PATCH 05/14] [DI] Trigger deprecation when setting a to-be-private synthetic service --- src/Symfony/Component/DependencyInjection/Container.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/DependencyInjection/Container.php b/src/Symfony/Component/DependencyInjection/Container.php index 7e53edd9ddd8..681ddc7024d3 100644 --- a/src/Symfony/Component/DependencyInjection/Container.php +++ b/src/Symfony/Component/DependencyInjection/Container.php @@ -174,7 +174,7 @@ public function set($id, $service) } if (isset($this->privates[$id]) || !(isset($this->fileMap[$id]) || isset($this->methodMap[$id]))) { - if (isset($this->syntheticIds[$id]) || (!isset($this->privates[$id]) && !isset($this->getRemovedIds()[$id]))) { + if (!isset($this->privates[$id]) && !isset($this->getRemovedIds()[$id])) { // no-op } elseif (null === $service) { @trigger_error(sprintf('The "%s" service is private, unsetting it is deprecated since Symfony 3.2 and will fail in 4.0.', $id), E_USER_DEPRECATED); From 05c3c81a200aabf7d16875d9019f3b89a929a247 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Fri, 1 Dec 2017 20:12:52 +0100 Subject: [PATCH 06/14] [link] clear the cache after linking --- link | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/link b/link index f4070998e72b..adba4a5a1ad7 100755 --- a/link +++ b/link @@ -57,3 +57,7 @@ foreach (glob("$argv[1]/vendor/symfony/*", GLOB_ONLYDIR | GLOB_NOSORT) as $dir) $filesystem->symlink($sfDir, $dir); echo "\"$package\" has been linked to \"$sfPackages[$package]\".".PHP_EOL; } + +foreach (glob("$argv[1]/var/cache/*") as $cacheDir) { + $filesystem->remove($cacheDir); +} From 23b575819849f523d6c86c57dc08d8034b523583 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Sat, 2 Dec 2017 16:57:48 +0100 Subject: [PATCH 07/14] [FrameworkBundle] Fix visibility of a test helper --- .../FrameworkBundle/Tests/Controller/RedirectControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/RedirectControllerTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/RedirectControllerTest.php index 14b6e4428e55..c4d6d837c6a7 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/RedirectControllerTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/RedirectControllerTest.php @@ -290,7 +290,7 @@ private function createRedirectController($httpPort = null, $httpsPort = null) return $controller; } - public function assertRedirectUrl(Response $returnResponse, $expectedUrl) + private function assertRedirectUrl(Response $returnResponse, $expectedUrl) { $this->assertTrue($returnResponse->isRedirect($expectedUrl), "Expected: $expectedUrl\nGot: ".$returnResponse->headers->get('Location')); } From 4a5a3f52ab4b5b01794bb2386cd2721f7b4333e0 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 1 Dec 2017 18:03:34 +0100 Subject: [PATCH 08/14] [Console][DI] Fail gracefully --- src/Symfony/Component/Console/Application.php | 36 ++++++++++++++----- .../DependencyInjection/Dumper/PhpDumper.php | 18 ++++++---- .../Tests/Fixtures/php/services9.php | 2 +- .../Tests/Fixtures/php/services9_as_files.txt | 14 +++++--- .../Tests/Fixtures/php/services9_compiled.php | 2 +- .../Fixtures/php/services_inline_requires.php | 14 ++++---- src/Symfony/Component/HttpKernel/Kernel.php | 24 +++++++++---- .../Component/HttpKernel/Tests/KernelTest.php | 2 +- 8 files changed, 74 insertions(+), 38 deletions(-) diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index b98365c05933..f3bc0d59641a 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -40,6 +40,7 @@ use Symfony\Component\Console\Event\ConsoleTerminateEvent; use Symfony\Component\Console\Exception\CommandNotFoundException; use Symfony\Component\Console\Exception\LogicException; +use Symfony\Component\Debug\ErrorHandler; use Symfony\Component\Debug\Exception\FatalThrowableError; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -118,6 +119,25 @@ public function run(InputInterface $input = null, OutputInterface $output = null $output = new ConsoleOutput(); } + $renderException = function ($e) use ($output) { + if (!$e instanceof \Exception) { + $e = class_exists(FatalThrowableError::class) ? new FatalThrowableError($e) : new \ErrorException($e->getMessage(), $e->getCode(), E_ERROR, $e->getFile(), $e->getLine()); + } + if ($output instanceof ConsoleOutputInterface) { + $this->renderException($e, $output->getErrorOutput()); + } else { + $this->renderException($e, $output); + } + }; + if ($phpHandler = set_exception_handler($renderException)) { + restore_exception_handler(); + if (!is_array($phpHandler) || !$phpHandler[0] instanceof ErrorHandler) { + $debugHandler = true; + } elseif ($debugHandler = $phpHandler[0]->setExceptionHandler($renderException)) { + $phpHandler[0]->setExceptionHandler($debugHandler); + } + } + if (null !== $this->dispatcher && $this->dispatcher->hasListeners(ConsoleEvents::EXCEPTION)) { @trigger_error(sprintf('The "ConsoleEvents::EXCEPTION" event is deprecated since Symfony 3.3 and will be removed in 4.0. Listen to the "ConsoleEvents::ERROR" event instead.'), E_USER_DEPRECATED); } @@ -125,21 +145,13 @@ public function run(InputInterface $input = null, OutputInterface $output = null $this->configureIO($input, $output); try { - $e = null; $exitCode = $this->doRun($input, $output); } catch (\Exception $e) { - } - - if (null !== $e) { if (!$this->catchExceptions) { throw $e; } - if ($output instanceof ConsoleOutputInterface) { - $this->renderException($e, $output->getErrorOutput()); - } else { - $this->renderException($e, $output); - } + $renderException($e); $exitCode = $e->getCode(); if (is_numeric($exitCode)) { @@ -150,6 +162,12 @@ public function run(InputInterface $input = null, OutputInterface $output = null } else { $exitCode = 1; } + } finally { + if (!$phpHandler) { + restore_exception_handler(); + } elseif (!$debugHandler) { + $phpHandler[0]->setExceptionHandler(null); + } } if ($this->autoExit) { diff --git a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php index fb933ce757f5..200c329ed853 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php @@ -217,12 +217,16 @@ public function dump(array $options = array()) {$namespaceLine} // This file has been auto-generated by the Symfony Dependency Injection Component for internal use. -if (!class_exists(\\Container{$hash}\\{$options['class']}::class, false)) { - require __DIR__.'/Container{$hash}/{$options['class']}.php'; +if (\\class_exists(\\Container{$hash}\\{$options['class']}::class, false)) { + // no-op +} elseif (!include __DIR__.'/Container{$hash}/{$options['class']}.php') { + touch(__DIR__.'/Container{$hash}.legacy'); + + return; } -if (!class_exists({$options['class']}::class, false)) { - class_alias(\\Container{$hash}\\{$options['class']}::class, {$options['class']}::class, false); +if (!\\class_exists({$options['class']}::class, false)) { + \\class_alias(\\Container{$hash}\\{$options['class']}::class, {$options['class']}::class, false); } return new \\Container{$hash}\\{$options['class']}(); @@ -428,13 +432,13 @@ private function addServiceInclude($cId, Definition $definition, \SplObjectStora } foreach (array_diff_key(array_flip($lineage), $this->inlinedRequires) as $file => $class) { - $code .= sprintf(" require_once %s;\n", $file); + $code .= sprintf(" include_once %s;\n", $file); } } foreach ($inlinedDefinitions as $def) { if ($file = $def->getFile()) { - $code .= sprintf(" require_once %s;\n", $this->dumpValue($file)); + $code .= sprintf(" include_once %s;\n", $this->dumpValue($file)); } } @@ -1233,7 +1237,7 @@ private function addInlineRequires() foreach ($lineage as $file) { if (!isset($this->inlinedRequires[$file])) { $this->inlinedRequires[$file] = true; - $code .= sprintf(" require_once %s;\n", $file); + $code .= sprintf(" include_once %s;\n", $file); } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php index 30b94d456ef6..467733f467d6 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php @@ -297,7 +297,7 @@ protected function getLazyContextIgnoreInvalidRefService() */ protected function getMethodCall1Service() { - require_once '%path%foo.php'; + include_once '%path%foo.php'; $this->services['method_call1'] = $instance = new \Bar\FooClass(); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_as_files.txt b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_as_files.txt index 6724846f8dd8..c25630d1da53 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_as_files.txt +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_as_files.txt @@ -198,7 +198,7 @@ use Symfony\Component\DependencyInjection\Argument\RewindableGenerator; // This file has been auto-generated by the Symfony Dependency Injection Component for internal use. // Returns the public 'method_call1' shared service. -require_once ($this->targetDirs[0].'/Fixtures/includes/foo.php'); +include_once ($this->targetDirs[0].'/Fixtures/includes/foo.php'); $this->services['method_call1'] = $instance = new \Bar\FooClass(); @@ -471,12 +471,16 @@ class ProjectServiceContainer extends Container // This file has been auto-generated by the Symfony Dependency Injection Component for internal use. -if (!class_exists(\Container%s\ProjectServiceContainer::class, false)) { - require __DIR__.'/Container%s/ProjectServiceContainer.php'; +if (\class_exists(\Container%s\ProjectServiceContainer::class, false)) { + // no-op +} elseif (!include __DIR__.'/Container%s/ProjectServiceContainer.php') { + touch(__DIR__.'/Container%s.legacy'); + + return; } -if (!class_exists(ProjectServiceContainer::class, false)) { - class_alias(\Container%s\ProjectServiceContainer::class, ProjectServiceContainer::class, false); +if (!\class_exists(ProjectServiceContainer::class, false)) { + \class_alias(\Container%s\ProjectServiceContainer::class, ProjectServiceContainer::class, false); } return new \Container%s\ProjectServiceContainer(); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php index ec0db041f438..1b039c5190f8 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php @@ -307,7 +307,7 @@ protected function getLazyContextIgnoreInvalidRefService() */ protected function getMethodCall1Service() { - require_once '%path%foo.php'; + include_once '%path%foo.php'; $this->services['method_call1'] = $instance = new \Bar\FooClass(); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_inline_requires.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_inline_requires.php index c888dc997d60..9969f18cc2ec 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_inline_requires.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_inline_requires.php @@ -46,10 +46,10 @@ public function __construct() $this->aliases = array(); - require_once $this->targetDirs[1].'/includes/HotPath/I1.php'; - require_once $this->targetDirs[1].'/includes/HotPath/P1.php'; - require_once $this->targetDirs[1].'/includes/HotPath/T1.php'; - require_once $this->targetDirs[1].'/includes/HotPath/C1.php'; + include_once $this->targetDirs[1].'/includes/HotPath/I1.php'; + include_once $this->targetDirs[1].'/includes/HotPath/P1.php'; + include_once $this->targetDirs[1].'/includes/HotPath/T1.php'; + include_once $this->targetDirs[1].'/includes/HotPath/C1.php'; } public function getRemovedIds() @@ -104,8 +104,8 @@ protected function getC1Service() */ protected function getC2Service() { - require_once $this->targetDirs[1].'/includes/HotPath/C2.php'; - require_once $this->targetDirs[1].'/includes/HotPath/C3.php'; + include_once $this->targetDirs[1].'/includes/HotPath/C2.php'; + include_once $this->targetDirs[1].'/includes/HotPath/C3.php'; return $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C2'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C2(${($_ = isset($this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C3']) ? $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C3'] : $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C3'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C3()) && false ?: '_'}); } @@ -117,7 +117,7 @@ protected function getC2Service() */ protected function getC3Service() { - require_once $this->targetDirs[1].'/includes/HotPath/C3.php'; + include_once $this->targetDirs[1].'/includes/HotPath/C3.php'; return $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C3'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C3(); } diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index 398599c6cf22..426fe8929cfc 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -582,7 +582,13 @@ protected function initializeContainer() $cacheDir = $this->warmupDir ?: $this->getCacheDir(); $cache = new ConfigCache($cacheDir.'/'.$class.'.php', $this->debug); if ($fresh = $cache->isFresh()) { - $this->container = require $cache->getPath(); + // Silence E_WARNING to ignore "include" failures - don't use "@" to prevent silencing fatal errors + $errorLevel = error_reporting(\E_ALL ^ \E_WARNING); + try { + $this->container = include $cache->getPath(); + } finally { + error_reporting($errorLevel); + } $fresh = \is_object($this->container); } if (!$fresh) { @@ -590,7 +596,7 @@ protected function initializeContainer() $collectedLogs = array(); $previousHandler = set_error_handler(function ($type, $message, $file, $line) use (&$collectedLogs, &$previousHandler) { if (E_USER_DEPRECATED !== $type && E_DEPRECATED !== $type) { - return $previousHandler ? $previousHandler($type, $message, $file, $line) : false; + return $previousHandler ? $previousHandler($type & ~E_WARNING, $message, $file, $line) : E_WARNING === $type; } if (isset($collectedLogs[$message])) { @@ -617,23 +623,27 @@ protected function initializeContainer() 'count' => 1, ); }); + } else { + $errorLevel = error_reporting(\E_ALL ^ \E_WARNING); } try { $container = null; $container = $this->buildContainer(); $container->compile(); + + $oldContainer = file_exists($cache->getPath()) && is_object($oldContainer = include $cache->getPath()) ? new \ReflectionClass($oldContainer) : false; } finally { if ($this->debug) { restore_error_handler(); file_put_contents($cacheDir.'/'.$class.'Deprecations.log', serialize(array_values($collectedLogs))); file_put_contents($cacheDir.'/'.$class.'Compiler.log', null !== $container ? implode("\n", $container->getCompiler()->getLog()) : ''); + } else { + error_reporting($errorLevel); } } - $oldContainer = file_exists($cache->getPath()) && is_object($oldContainer = @include $cache->getPath()) ? new \ReflectionClass($oldContainer) : false; - $this->dumpContainer($cache, $container, $class, $this->getContainerBaseClass()); $this->container = require $cache->getPath(); } @@ -649,13 +659,13 @@ protected function initializeContainer() // old container files are not removed immediately, // but on a next dump of the container. $oldContainerDir = dirname($oldContainer->getFileName()); - foreach (glob(dirname($oldContainerDir).'/*.legacyContainer') as $legacyContainer) { - if ($oldContainerDir.'.legacyContainer' !== $legacyContainer && @unlink($legacyContainer)) { + foreach (glob(dirname($oldContainerDir).'/*.legacy') as $legacyContainer) { + if ($oldContainerDir.'.legacy' !== $legacyContainer && @unlink($legacyContainer)) { (new Filesystem())->remove(substr($legacyContainer, 0, -16)); } } - touch($oldContainerDir.'.legacyContainer'); + touch($oldContainerDir.'.legacy'); } if ($this->container->has('cache_warmer')) { diff --git a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php index 6dee293ea9de..243529ed20a2 100644 --- a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php @@ -833,7 +833,7 @@ public function testKernelReset() $this->assertTrue(get_class($kernel->getContainer()) !== $containerClass); $this->assertFileExists($containerFile); - $this->assertFileExists(dirname($containerFile).'.legacyContainer'); + $this->assertFileExists(dirname($containerFile).'.legacy'); } public function testKernelPass() From 3bdeda048b7a9b56ca18551a1de14547d3e3f135 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Sat, 2 Dec 2017 15:59:45 +0100 Subject: [PATCH 09/14] Fail as early and noisily as possible Today, I tried using SYMFONY_PHPUNIT_VERSION=6 because I don't really care about the minor version. I got lots of warnings, followed by hard-to-understand error messages. This will silence the first warning and will throw an exception instead. --- src/Symfony/Bridge/PhpUnit/bin/simple-phpunit | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit b/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit index b30eaa14538d..110e57d32138 100755 --- a/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit +++ b/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit @@ -51,7 +51,12 @@ if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__ passthru(sprintf('\\' === DIRECTORY_SEPARATOR ? '(del /S /F /Q %s & rmdir %1$s) >nul': 'rm -rf %s', "phpunit-$PHPUNIT_VERSION")); } if (extension_loaded('openssl') && ini_get('allow_url_fopen') && !isset($_SERVER['http_proxy']) && !isset($_SERVER['https_proxy'])) { - stream_copy_to_stream(fopen("https://github.com/sebastianbergmann/phpunit/archive/$PHPUNIT_VERSION.zip", 'rb'), fopen("$PHPUNIT_VERSION.zip", 'wb')); + $remoteZip = "https://github.com/sebastianbergmann/phpunit/archive/$PHPUNIT_VERSION.zip"; + $remoteZipStream = @fopen($remoteZip, 'rb'); + if (!$remoteZipStream) { + throw new \RuntimeException("Could not find $remoteZip"); + } + stream_copy_to_stream($remoteZipStream, fopen("$PHPUNIT_VERSION.zip", 'wb')); } else { @unlink("$PHPUNIT_VERSION.zip"); passthru("wget https://github.com/sebastianbergmann/phpunit/archive/$PHPUNIT_VERSION.zip"); From 75b21e9c869ce21dfa74b0fc1bb709b737127a45 Mon Sep 17 00:00:00 2001 From: Samuel ROZE Date: Sun, 3 Dec 2017 13:07:37 +0000 Subject: [PATCH 10/14] Throw an exception is expression language is not installed --- .../Compiler/AnalyzeServiceReferencesPass.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Symfony/Component/DependencyInjection/Compiler/AnalyzeServiceReferencesPass.php b/src/Symfony/Component/DependencyInjection/Compiler/AnalyzeServiceReferencesPass.php index 217c7c203407..a9b812e61d10 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/AnalyzeServiceReferencesPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/AnalyzeServiceReferencesPass.php @@ -14,6 +14,7 @@ use Symfony\Component\DependencyInjection\Argument\ArgumentInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\Definition; +use Symfony\Component\DependencyInjection\Exception\RuntimeException; use Symfony\Component\DependencyInjection\ExpressionLanguage; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -155,6 +156,10 @@ private function getDefinitionId($id) private function getExpressionLanguage() { if (null === $this->expressionLanguage) { + if (!class_exists('Symfony\Component\ExpressionLanguage\ExpressionLanguage')) { + throw new RuntimeException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed.'); + } + $providers = $this->container->getExpressionLanguageProviders(); $this->expressionLanguage = new ExpressionLanguage(null, $providers, function ($arg) { if ('""' === substr_replace($arg, '', 1, -1)) { From 9fb6a885803c64139cc341c86e779c7b57715963 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sun, 3 Dec 2017 21:54:18 +0100 Subject: [PATCH 11/14] Remove rc/beta suffix from composer.json files --- src/Symfony/Bridge/Twig/composer.json | 2 +- src/Symfony/Bundle/FrameworkBundle/composer.json | 2 +- src/Symfony/Bundle/SecurityBundle/composer.json | 8 ++++---- src/Symfony/Component/Form/composer.json | 2 +- src/Symfony/Component/Security/Csrf/composer.json | 4 ++-- src/Symfony/Component/Security/composer.json | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Symfony/Bridge/Twig/composer.json b/src/Symfony/Bridge/Twig/composer.json index 0b16573768da..33ac7d5849c7 100644 --- a/src/Symfony/Bridge/Twig/composer.json +++ b/src/Symfony/Bridge/Twig/composer.json @@ -24,7 +24,7 @@ "symfony/asset": "~2.8|~3.0|~4.0", "symfony/dependency-injection": "~2.8|~3.0|~4.0", "symfony/finder": "~2.8|~3.0|~4.0", - "symfony/form": "~3.4-beta4|~4.0-beta4", + "symfony/form": "~3.4|~4.0", "symfony/http-foundation": "^3.3.11|~4.0", "symfony/http-kernel": "~3.2|~4.0", "symfony/polyfill-intl-icu": "~1.0", diff --git a/src/Symfony/Bundle/FrameworkBundle/composer.json b/src/Symfony/Bundle/FrameworkBundle/composer.json index abbc1dbef368..e2382363bebc 100644 --- a/src/Symfony/Bundle/FrameworkBundle/composer.json +++ b/src/Symfony/Bundle/FrameworkBundle/composer.json @@ -22,7 +22,7 @@ "symfony/class-loader": "~3.2", "symfony/dependency-injection": "~3.4|~4.0", "symfony/config": "~3.4|~4.0", - "symfony/event-dispatcher": "^3.4-beta4|~4.0-beta4", + "symfony/event-dispatcher": "~3.4|~4.0", "symfony/http-foundation": "^3.3.11|~4.0", "symfony/http-kernel": "~3.4|~4.0", "symfony/polyfill-mbstring": "~1.0", diff --git a/src/Symfony/Bundle/SecurityBundle/composer.json b/src/Symfony/Bundle/SecurityBundle/composer.json index 4dc3f78ad0f1..d1bf164f0a1f 100644 --- a/src/Symfony/Bundle/SecurityBundle/composer.json +++ b/src/Symfony/Bundle/SecurityBundle/composer.json @@ -18,7 +18,7 @@ "require": { "php": "^5.5.9|>=7.0.8", "ext-xml": "*", - "symfony/security": "~3.4-rc1|~4.0-rc1", + "symfony/security": "~3.4|~4.0", "symfony/dependency-injection": "~3.4|~4.0", "symfony/http-kernel": "~3.3|~4.0", "symfony/polyfill-php70": "~1.0" @@ -29,9 +29,9 @@ "symfony/console": "~3.4|~4.0", "symfony/css-selector": "~2.8|~3.0|~4.0", "symfony/dom-crawler": "~2.8|~3.0|~4.0", - "symfony/event-dispatcher": "^3.3.1|~4.0", + "symfony/event-dispatcher": "~3.4|~4.0", "symfony/form": "^3.4|~4.0", - "symfony/framework-bundle": "^3.4-rc1|~4.0-rc1", + "symfony/framework-bundle": "~3.4|~4.0", "symfony/http-foundation": "~3.3|~4.0", "symfony/security-acl": "~2.8|~3.0", "symfony/translation": "~3.4|~4.0", @@ -47,7 +47,7 @@ }, "conflict": { "symfony/var-dumper": "<3.3", - "symfony/event-dispatcher": "<3.3.1", + "symfony/event-dispatcher": "<3.4", "symfony/framework-bundle": "<3.4", "symfony/console": "<3.4" }, diff --git a/src/Symfony/Component/Form/composer.json b/src/Symfony/Component/Form/composer.json index 7afb274b4d27..f9836b8ac066 100644 --- a/src/Symfony/Component/Form/composer.json +++ b/src/Symfony/Component/Form/composer.json @@ -32,7 +32,7 @@ "symfony/http-kernel": "^3.3.5|~4.0", "symfony/security-csrf": "~2.8|~3.0|~4.0", "symfony/translation": "~2.8|~3.0|~4.0", - "symfony/var-dumper": "~3.3.11|~3.4-beta3|~4.0-beta3", + "symfony/var-dumper": "~3.3.11|~3.4|~4.0", "symfony/console": "~3.4|~4.0" }, "conflict": { diff --git a/src/Symfony/Component/Security/Csrf/composer.json b/src/Symfony/Component/Security/Csrf/composer.json index 72bef3805e2f..5b27fee3a459 100644 --- a/src/Symfony/Component/Security/Csrf/composer.json +++ b/src/Symfony/Component/Security/Csrf/composer.json @@ -22,10 +22,10 @@ "symfony/security-core": "~2.8|~3.0|~4.0" }, "require-dev": { - "symfony/http-foundation": "^2.8.31|~3.3.13|~3.4-beta5|~4.0-beta5" + "symfony/http-foundation": "^2.8.31|~3.3.13|~3.4|~4.0" }, "conflict": { - "symfony/http-foundation": "<2.8.31|~3.3,<3.3.13|~3.4,<3.4-beta5|~4.0,<4.0-beta5" + "symfony/http-foundation": "<2.8.31|~3.3,<3.3.13" }, "suggest": { "symfony/http-foundation": "For using the class SessionTokenStorage." diff --git a/src/Symfony/Component/Security/composer.json b/src/Symfony/Component/Security/composer.json index 7fee5322a24b..679208ca096b 100644 --- a/src/Symfony/Component/Security/composer.json +++ b/src/Symfony/Component/Security/composer.json @@ -18,7 +18,7 @@ "require": { "php": "^5.5.9|>=7.0.8", "symfony/event-dispatcher": "~2.8|~3.0|~4.0", - "symfony/http-foundation": "^2.8.31|~3.3.13|~3.4-beta5|~4.0-beta5", + "symfony/http-foundation": "^2.8.31|~3.3.13|~3.4|~4.0", "symfony/http-kernel": "~3.3|~4.0", "symfony/polyfill-php56": "~1.0", "symfony/polyfill-php70": "~1.0", From 56f24d08c981f6f7ddcc021c7f1941038f43c6e8 Mon Sep 17 00:00:00 2001 From: Valentin Date: Mon, 4 Dec 2017 02:10:25 +0300 Subject: [PATCH 12/14] Fixed the null value exception case. --- .../Validator/Constraints/ValidValidator.php | 4 ++++ .../Tests/Constraints/ValidValidatorTest.php | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/Symfony/Component/Validator/Constraints/ValidValidator.php b/src/Symfony/Component/Validator/Constraints/ValidValidator.php index b2f1f1c5a06b..be5fbc12660b 100644 --- a/src/Symfony/Component/Validator/Constraints/ValidValidator.php +++ b/src/Symfony/Component/Validator/Constraints/ValidValidator.php @@ -26,6 +26,10 @@ public function validate($value, Constraint $constraint) throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Valid'); } + if (null === $value) { + return; + } + $this->context ->getValidator() ->inContext($this->context) diff --git a/src/Symfony/Component/Validator/Tests/Constraints/ValidValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/ValidValidatorTest.php index f95650d359b3..c4ccf1551f2a 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/ValidValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/ValidValidatorTest.php @@ -20,6 +20,18 @@ public function testPropertyPathsArePassedToNestedContexts() $this->assertSame('fooBar.fooBarBaz.foo', $violations->get(0)->getPropertyPath()); } + public function testNullValues() + { + $validatorBuilder = new ValidatorBuilder(); + $validator = $validatorBuilder->enableAnnotationMapping()->getValidator(); + + $foo = new Foo(); + $foo->fooBar = null; + $violations = $validator->validate($foo, null, array('nested')); + + $this->assertCount(0, $violations); + } + protected function createValidator() { return new ValidValidator(); From 93441c1a850aa1d29352122d443287adad06900e Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Mon, 4 Dec 2017 10:18:44 +0100 Subject: [PATCH 13/14] Add test case for #25264 --- .../DependencyInjection/Tests/ContainerTest.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php b/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php index 8035de623088..84271ab02667 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php @@ -538,6 +538,16 @@ public function testReplacingAPreDefinedServiceIsDeprecated() $this->assertSame($bar, $c->get('bar'), '->set() replaces a pre-defined service'); } + + /** + * @group legacy + * @expectedDeprecation The "synthetic" service is private, replacing it is deprecated since Symfony 3.2 and will fail in 4.0. + */ + public function testSetWithPrivateSyntheticServiceThrowsDeprecation() + { + $c = new ProjectServiceContainer(); + $c->set('synthetic', new \stdClass()); + } } class ProjectServiceContainer extends Container @@ -565,8 +575,12 @@ public function __construct() $this->__foo_bar = new \stdClass(); $this->__foo_baz = new \stdClass(); $this->__internal = new \stdClass(); - $this->privates = array('internal' => true); + $this->privates = array( + 'internal' => true, + 'synthetic' => true, + ); $this->aliases = array('alias' => 'bar'); + $this->syntheticIds['synthetic'] = true; } protected function getInternalService() From 4d39a2d8dc3d52b19c5dc0a776bd470a4b7fbc2a Mon Sep 17 00:00:00 2001 From: Vladimir Reznichenko Date: Mon, 13 Nov 2017 21:26:24 +0100 Subject: [PATCH 14/14] SCA with Php Inspections (EA Extended) --- src/Symfony/Component/HttpKernel/Kernel.php | 2 +- src/Symfony/Component/Workflow/Definition.php | 2 +- src/Symfony/Component/Workflow/DefinitionBuilder.php | 2 +- src/Symfony/Component/Workflow/Transition.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index 3b465dc7d5b2..684529e78a98 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -423,7 +423,7 @@ public function setClassCache(array $classes) */ public function setAnnotatedClassCache(array $annotatedClasses) { - file_put_contents(($this->warmupDir ?: $this->getCacheDir()).'/annotations.map', sprintf('warmupDir ?: $this->getCacheDir()).'/annotations.map', sprintf('