From 9c76790ee81da45803a5f6b0398684aae0857cfb Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Thu, 27 Jun 2019 09:45:05 +0545 Subject: [PATCH 1/7] Catch JsonException and rethrow in JsonEncode --- .../Component/Serializer/Encoder/JsonEncode.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Serializer/Encoder/JsonEncode.php b/src/Symfony/Component/Serializer/Encoder/JsonEncode.php index 76e532c4b7..71f6950394 100644 --- a/src/Symfony/Component/Serializer/Encoder/JsonEncode.php +++ b/src/Symfony/Component/Serializer/Encoder/JsonEncode.php @@ -35,14 +35,19 @@ class JsonEncode implements EncoderInterface public function encode($data, $format, array $context = []) { $context = $this->resolveContext($context); + $options = $context['json_encode_options']; - $encodedJson = json_encode($data, $context['json_encode_options']); + try { + $encodedJson = json_encode($data, $options); + } catch (\JsonException $e) { + throw new NotEncodableValueException($e->getMessage(), 0, $e); + } - if (\PHP_VERSION_ID >= 70300 && (JSON_THROW_ON_ERROR & $context['json_encode_options'])) { + if (\PHP_VERSION_ID >= 70300 && (JSON_THROW_ON_ERROR & $options)) { return $encodedJson; } - if (JSON_ERROR_NONE !== json_last_error() && (false === $encodedJson || !($context['json_encode_options'] & JSON_PARTIAL_OUTPUT_ON_ERROR))) { + if (JSON_ERROR_NONE !== json_last_error() && (false === $encodedJson || !($options & JSON_PARTIAL_OUTPUT_ON_ERROR))) { throw new NotEncodableValueException(json_last_error_msg()); } From 901fe0d7c54d675ca2d68435bb075587855cf630 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 28 Jun 2019 09:31:23 +0200 Subject: [PATCH 2/7] pass error code as a string --- .../Component/Validator/Tests/Validator/AbstractTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Validator/Tests/Validator/AbstractTest.php b/src/Symfony/Component/Validator/Tests/Validator/AbstractTest.php index 2bc3d11ef6..c9c05a0edf 100644 --- a/src/Symfony/Component/Validator/Tests/Validator/AbstractTest.php +++ b/src/Symfony/Component/Validator/Tests/Validator/AbstractTest.php @@ -511,7 +511,7 @@ abstract class AbstractTest extends AbstractValidatorTest ->setParameter('%param%', 'value') ->setInvalidValue('Invalid value') ->setPlural(2) - ->setCode(42) + ->setCode('42') ->addViolation(); }; @@ -528,7 +528,7 @@ abstract class AbstractTest extends AbstractValidatorTest $this->assertSame($entity, $violations[0]->getRoot()); $this->assertSame('Invalid value', $violations[0]->getInvalidValue()); $this->assertSame(2, $violations[0]->getPlural()); - $this->assertSame(42, $violations[0]->getCode()); + $this->assertSame('42', $violations[0]->getCode()); } public function testNoDuplicateValidationIfClassConstraintInMultipleGroups() From 02ee4d0b059ff7c253733c1b5987a9548f917903 Mon Sep 17 00:00:00 2001 From: smoench Date: Fri, 28 Jun 2019 10:02:59 +0200 Subject: [PATCH 3/7] [Finder] docblock fixes --- src/Symfony/Component/Finder/Finder.php | 2 +- .../Finder/Iterator/ExcludeDirectoryFilterIterator.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Finder/Finder.php b/src/Symfony/Component/Finder/Finder.php index 133c4b8c50..e933f07841 100644 --- a/src/Symfony/Component/Finder/Finder.php +++ b/src/Symfony/Component/Finder/Finder.php @@ -528,7 +528,7 @@ class Finder implements \IteratorAggregate, \Countable /** * Searches files and directories which match defined rules. * - * @param string|array $dirs A directory path or an array of directories + * @param string|string[] $dirs A directory path or an array of directories * * @return $this * diff --git a/src/Symfony/Component/Finder/Iterator/ExcludeDirectoryFilterIterator.php b/src/Symfony/Component/Finder/Iterator/ExcludeDirectoryFilterIterator.php index bc0e6fc1e1..60bc4e814c 100644 --- a/src/Symfony/Component/Finder/Iterator/ExcludeDirectoryFilterIterator.php +++ b/src/Symfony/Component/Finder/Iterator/ExcludeDirectoryFilterIterator.php @@ -25,7 +25,7 @@ class ExcludeDirectoryFilterIterator extends FilterIterator implements \Recursiv /** * @param \Iterator $iterator The Iterator to filter - * @param array $directories An array of directories to exclude + * @param string[] $directories An array of directories to exclude */ public function __construct(\Iterator $iterator, array $directories) { From 5d55b91faebc9690fe58ea213cd291b73fdfd916 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 27 Jun 2019 23:36:22 +0200 Subject: [PATCH 4/7] [Cache] work aroung PHP memory leak --- .../Component/Cache/Traits/PhpFilesTrait.php | 57 ++++++++++++++++--- 1 file changed, 48 insertions(+), 9 deletions(-) diff --git a/src/Symfony/Component/Cache/Traits/PhpFilesTrait.php b/src/Symfony/Component/Cache/Traits/PhpFilesTrait.php index 6afdd8c3a5..5ed4d6023e 100644 --- a/src/Symfony/Component/Cache/Traits/PhpFilesTrait.php +++ b/src/Symfony/Component/Cache/Traits/PhpFilesTrait.php @@ -50,12 +50,15 @@ trait PhpFilesTrait { $time = time(); $pruned = true; + $getExpiry = true; set_error_handler($this->includeHandler); try { foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->directory, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::LEAVES_ONLY) as $file) { try { - list($expiresAt) = include $file; + if (\is_array($expiresAt = include $file)) { + $expiresAt = $expiresAt[0]; + } } catch (\ErrorException $e) { $expiresAt = $time; } @@ -87,15 +90,21 @@ trait PhpFilesTrait $values = []; begin: + $getExpiry = false; + foreach ($ids as $id) { if (null === $value = $this->values[$id] ?? null) { $missingIds[] = $id; } elseif ('N;' === $value) { $values[$id] = null; - } elseif ($value instanceof \Closure) { - $values[$id] = $value(); - } else { + } elseif (!\is_object($value)) { $values[$id] = $value; + } elseif (!$value instanceof LazyValue) { + // calling a Closure is for @deprecated BC and should be removed in Symfony 5.0 + $values[$id] = $value(); + } elseif (false === $values[$id] = include $value->file) { + unset($values[$id], $this->values[$id]); + $missingIds[] = $id; } if (!$this->appendOnly) { unset($this->values[$id]); @@ -108,10 +117,18 @@ trait PhpFilesTrait set_error_handler($this->includeHandler); try { + $getExpiry = true; + foreach ($missingIds as $k => $id) { try { $file = $this->files[$id] ?? $this->files[$id] = $this->getFile($id); - list($expiresAt, $this->values[$id]) = include $file; + + if (\is_array($expiresAt = include $file)) { + [$expiresAt, $this->values[$id]] = $expiresAt; + } elseif ($now < $expiresAt) { + $this->values[$id] = new LazyValue($file); + } + if ($now >= $expiresAt) { unset($this->values[$id], $missingIds[$k]); } @@ -140,7 +157,13 @@ trait PhpFilesTrait set_error_handler($this->includeHandler); try { $file = $this->files[$id] ?? $this->files[$id] = $this->getFile($id); - list($expiresAt, $value) = include $file; + $getExpiry = true; + + if (\is_array($expiresAt = include $file)) { + [$expiresAt, $value] = $expiresAt; + } elseif ($this->appendOnly) { + $value = new LazyValue($file); + } } catch (\ErrorException $e) { return false; } finally { @@ -189,13 +212,16 @@ trait PhpFilesTrait } if (!$isStaticValue) { - $value = str_replace("\n", "\n ", $value); - $value = "static function () {\n\n return {$value};\n\n}"; + // We cannot use a closure here because of https://bugs.php.net/76982 + $value = str_replace('\Symfony\Component\VarExporter\Internal\\', '', $value); + $value = "files[$key] = $this->getFile($key, true); // Since OPcache only compiles files older than the script execution start, set the file's mtime in the past - $ok = $this->write($file, "write($file, $value, self::$startTime - 10) && $ok; if ($allowCompile) { @opcache_invalidate($file, true); @@ -241,3 +267,16 @@ trait PhpFilesTrait return @unlink($file); } } + +/** + * @internal + */ +class LazyValue +{ + public $file; + + public function __construct($file) + { + $this->file = $file; + } +} From 379bbee37074b330053f2406ed1c42b6ec40e16e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Thu, 27 Jun 2019 19:20:54 +0200 Subject: [PATCH 5/7] [Serializer] Fixed PHP of DenormalizableInterface::denormalize It can return an array of objects --- .../Component/Serializer/Normalizer/DenormalizableInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Serializer/Normalizer/DenormalizableInterface.php b/src/Symfony/Component/Serializer/Normalizer/DenormalizableInterface.php index 31e27a85cb..3e7021b130 100644 --- a/src/Symfony/Component/Serializer/Normalizer/DenormalizableInterface.php +++ b/src/Symfony/Component/Serializer/Normalizer/DenormalizableInterface.php @@ -34,7 +34,7 @@ interface DenormalizableInterface * differently based on different input formats * @param array $context Options for denormalizing * - * @return object + * @return object|object[] */ public function denormalize(DenormalizerInterface $denormalizer, $data, $format = null, array $context = []); } From d1261e78a48046657ace2e337a380f70b125a041 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 28 Jun 2019 12:14:37 +0200 Subject: [PATCH 6/7] remove invalid test cases --- .../AbstractComparisonValidatorTestCase.php | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/Symfony/Component/Validator/Tests/Constraints/AbstractComparisonValidatorTestCase.php b/src/Symfony/Component/Validator/Tests/Constraints/AbstractComparisonValidatorTestCase.php index 2f27974a80..3a84694cc7 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/AbstractComparisonValidatorTestCase.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/AbstractComparisonValidatorTestCase.php @@ -148,20 +148,6 @@ abstract class AbstractComparisonValidatorTestCase extends ConstraintValidatorTe $this->assertNoViolation(); } - /** - * @dataProvider provideValidComparisonsToPropertyPath - */ - public function testValidComparisonToPropertyPathOnArray($comparedValue) - { - $constraint = $this->createConstraint(['propertyPath' => '[root][value]']); - - $this->setObject(['root' => ['value' => 5]]); - - $this->validator->validate($comparedValue, $constraint); - - $this->assertNoViolation(); - } - public function testNoViolationOnNullObjectWithPropertyPath() { $constraint = $this->createConstraint(['propertyPath' => 'propertyPath']); From b0c663071b247f86c4e34a83b9a5635be67493ff Mon Sep 17 00:00:00 2001 From: Valentin Udaltsov Date: Thu, 27 Jun 2019 13:35:22 +0300 Subject: [PATCH 7/7] [HttpFoundation] Throw exception when the \"session\" extension is not loaded --- .../DependencyInjection/FrameworkExtension.php | 4 ++++ .../HttpFoundation/Session/Storage/NativeSessionStorage.php | 4 ++++ .../Session/Storage/PhpBridgeSessionStorage.php | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 4e792ded2e..a75402d6c1 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -233,6 +233,10 @@ class FrameworkExtension extends Extension } if ($this->isConfigEnabled($container, $config['session'])) { + if (!\extension_loaded('session')) { + throw new \LogicException('PHP extension "session" is required.'); + } + $this->sessionConfigEnabled = true; $this->registerSessionConfiguration($config['session'], $container, $loader); } diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php b/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php index c4dbe75868..809d7002cf 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php @@ -100,6 +100,10 @@ class NativeSessionStorage implements SessionStorageInterface */ public function __construct(array $options = [], $handler = null, MetadataBag $metaBag = null) { + if (!\extension_loaded('session')) { + throw new \LogicException('PHP extension "session" is required.'); + } + $options += [ 'cache_limiter' => '', 'cache_expire' => 0, diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/PhpBridgeSessionStorage.php b/src/Symfony/Component/HttpFoundation/Session/Storage/PhpBridgeSessionStorage.php index 662ed5015a..8969e609aa 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/PhpBridgeSessionStorage.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/PhpBridgeSessionStorage.php @@ -24,6 +24,10 @@ class PhpBridgeSessionStorage extends NativeSessionStorage */ public function __construct($handler = null, MetadataBag $metaBag = null) { + if (!\extension_loaded('session')) { + throw new \LogicException('PHP extension "session" is required.'); + } + $this->setMetadataBag($metaBag); $this->setSaveHandler($handler); }