From 9c76790ee81da45803a5f6b0398684aae0857cfb Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Thu, 27 Jun 2019 09:45:05 +0545 Subject: [PATCH 1/6] 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/6] 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/6] [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 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 4/6] [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 5/6] 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 6/6] [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); }