Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ private function validateAndDenormalizeLegacy(array $types, string $currentClass
return (float) $data;
}

if (LegacyType::BUILTIN_TYPE_BOOL === $builtinType && \is_string($data) && ($context[self::FILTER_BOOL] ?? false)) {
if (LegacyType::BUILTIN_TYPE_BOOL === $builtinType && (\is_string($data) || \is_int($data)) && ($context[self::FILTER_BOOL] ?? false)) {
return filter_var($data, \FILTER_VALIDATE_BOOL, \FILTER_NULL_ON_FAILURE);
}

Expand Down Expand Up @@ -854,7 +854,7 @@ private function validateAndDenormalize(Type $type, string $currentClass, string
return (float) $data;
}

if (TypeIdentifier::BOOL === $typeIdentifier && \is_string($data) && ($context[self::FILTER_BOOL] ?? false)) {
if (TypeIdentifier::BOOL === $typeIdentifier && (\is_string($data) || \is_int($data)) && ($context[self::FILTER_BOOL] ?? false)) {
return filter_var($data, \FILTER_VALIDATE_BOOL, \FILTER_NULL_ON_FAILURE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1216,15 +1216,34 @@ public static function provideDenormalizeWithFilterBoolData(): array
{
return [
[['foo' => 'true'], true],
[['foo' => 'True'], true],
[['foo' => 'TRUE'], true],
[['foo' => '1'], true],
[['foo' => 1], true],
[['foo' => 'yes'], true],
[['foo' => 'Yes'], true],
[['foo' => 'YES'], true],
[['foo' => 'on'], true],
[['foo' => 'On'], true],
[['foo' => 'ON'], true],
[['foo' => 'false'], false],
[['foo' => 'False'], false],
[['foo' => 'FALSE'], false],
[['foo' => '0'], false],
[['foo' => 0], false],
[['foo' => 'no'], false],
[['foo' => 'No'], false],
[['foo' => 'NO'], false],
[['foo' => 'off'], false],
[['foo' => 'Off'], false],
[['foo' => 'OFF'], false],
[['foo' => ''], false],
[['foo' => null], null],
[['foo' => 'null'], null],
[['foo' => 'something'], null],
[['foo' => 'foo'], null],
[['foo' => 1234567890], null],
[['foo' => -1234567890], null],
];
}

Expand Down Expand Up @@ -1253,10 +1272,7 @@ protected function isAllowedAttribute($classOrObject, string $attribute, ?string

public function testTemplateTypeWhenAnObjectIsPassedToDenormalize()
{
$normalizer = new class (
classMetadataFactory: new ClassMetadataFactory(new AttributeLoader()),
propertyTypeExtractor: new PropertyInfoExtractor(typeExtractors: [new PhpStanExtractor(), new ReflectionExtractor()])
) extends AbstractObjectNormalizerDummy {
$normalizer = new class(classMetadataFactory: new ClassMetadataFactory(new AttributeLoader()), propertyTypeExtractor: new PropertyInfoExtractor(typeExtractors: [new PhpStanExtractor(), new ReflectionExtractor()])) extends AbstractObjectNormalizerDummy {
protected function isAllowedAttribute($classOrObject, string $attribute, ?string $format = null, array $context = []): bool
{
return true;
Expand All @@ -1279,10 +1295,7 @@ public function testDenormalizeTemplateType()
$this->markTestSkipped('The PropertyInfo component before Symfony 7.1 does not support template types.');
}

$normalizer = new class (
classMetadataFactory: new ClassMetadataFactory(new AttributeLoader()),
propertyTypeExtractor: new PropertyInfoExtractor(typeExtractors: [new PhpStanExtractor(), new ReflectionExtractor()])
) extends AbstractObjectNormalizerDummy {
$normalizer = new class(classMetadataFactory: new ClassMetadataFactory(new AttributeLoader()), propertyTypeExtractor: new PropertyInfoExtractor(typeExtractors: [new PhpStanExtractor(), new ReflectionExtractor()])) extends AbstractObjectNormalizerDummy {
protected function isAllowedAttribute($classOrObject, string $attribute, ?string $format = null, array $context = []): bool
{
return true;
Expand Down Expand Up @@ -1587,7 +1600,7 @@ class TruePropertyDummy

class BoolPropertyDummy
{
/** @var null|bool */
/** @var bool|null */
public $foo;
}

Expand Down
Loading