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
1 change: 1 addition & 0 deletions UPGRADE-7.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Translation
Validator
---------

* Deprecate implementing `__sleep/wakeup()` on `GenericMetadata` implementations; use `__(un)serialize()` instead
* Deprecate passing a list of choices to the first argument of the `Choice` constraint. Use the `choices` option instead
* Deprecate `getRequiredOptions()` and `getDefaultOption()` methods of the `All`, `AtLeastOneOf`, `CardScheme`, `Collection`,
`CssColor`, `Expression`, `Regex`, `Sequentially`, `Type`, and `When` constraints
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,7 @@ public function __unserialize(array $data): void
}

/**
* @internal since Symfony 7.4, will be removed in 8.0
*
* @final since Symfony 7.4, will be removed in 8.0
* @deprecated since Symfony 7.4, will be replaced by `__serialize()` in 8.0
*/
public function __sleep(): array
{
Expand All @@ -148,9 +146,7 @@ public function __sleep(): array
}

/**
* @internal since Symfony 7.4, will be removed in 8.0
*
* @final since Symfony 7.4, will be removed in 8.0
* @deprecated since Symfony 7.4, will be replaced by `__unserialize()` in 8.0
*/
public function __wakeup(): void
{
Expand Down
8 changes: 2 additions & 6 deletions src/Symfony/Component/HttpKernel/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -846,9 +846,7 @@ public function __unserialize(array $data): void
}

/**
* @internal since Symfony 7.4, will be removed in 8.0
*
* @final since Symfony 7.4, will be removed in 8.0
* @deprecated since Symfony 7.4, will be replaced by `__serialize()` in 8.0
*/
public function __sleep(): array
{
Expand All @@ -858,9 +856,7 @@ public function __sleep(): array
}

/**
* @internal since Symfony 7.4, will be removed in 8.0
*
* @final since Symfony 7.4, will be removed in 8.0
* @deprecated since Symfony 7.4, will be replaced by `__unserialize()` in 8.0
*/
public function __wakeup(): void
{
Expand Down
4 changes: 1 addition & 3 deletions src/Symfony/Component/String/AbstractString.php
Original file line number Diff line number Diff line change
Expand Up @@ -729,9 +729,7 @@ public function __serialize(): array
}

/**
* @internal since Symfony 7.4, will be removed in 8.0
*
* @final since Symfony 7.4, will be removed in 8.0
* @deprecated since Symfony 7.4, will be replaced by `__unserialize()` in 8.0
*/
public function __sleep(): array
{
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/String/LazyString.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ public function __serialize(): array
}

/**
* @internal since Symfony 7.4, will be removed in 8.0
*
* @final since Symfony 7.4, will be removed in 8.0
* @deprecated since Symfony 7.4, will be replaced by `__serialize()` in 8.0
*/
public function __sleep(): array
{
trigger_deprecation('symfony/string', '7.4', 'Calling "%s::__sleep()" is deprecated, use "__serialize()" instead.', get_debug_type($this));

$this->__toString();

return ['value'];
Expand Down
4 changes: 1 addition & 3 deletions src/Symfony/Component/String/UnicodeString.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,7 @@ public function __unserialize(array $data): void
}

/**
* @internal since Symfony 7.4, will be removed in 8.0
*
* @final since Symfony 7.4, will be removed in 8.0
* @deprecated since Symfony 7.4, will be replaced by `__unserialize()` in 8.0
*/
public function __wakeup(): void
{
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/Validator/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CHANGELOG
7.4
---

* Deprecate implementing `__sleep/wakeup()` on `GenericMetadata` implementations; use `__(un)serialize()` instead
* Deprecate passing a list of choices to the first argument of the `Choice` constraint. Use the `choices` option instead
* Add the `min` and `max` parameter to the `Length` constraint violation
* Deprecate `getRequiredOptions()` and `getDefaultOption()` methods of the `All`, `AtLeastOneOf`, `CardScheme`, `Collection`,
Expand Down
51 changes: 45 additions & 6 deletions src/Symfony/Component/Validator/Mapping/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,53 @@ public function __construct(string $class)
}
}

public function __sleep(): array
public function __serialize(): array
{
$parentProperties = parent::__sleep();
if (self::class === (new \ReflectionMethod($this, '__sleep'))->class) {
return [
'constraints' => $this->constraints,
'constraintsByGroup' => $this->constraintsByGroup,
'traversalStrategy' => $this->traversalStrategy,
'autoMappingStrategy' => $this->autoMappingStrategy,
'getters' => $this->getters,
'groupSequence' => $this->groupSequence,
'groupSequenceProvider' => $this->groupSequenceProvider,
'groupProvider' => $this->groupProvider,
'members' => $this->members,
'name' => $this->name,
'properties' => $this->properties,
'defaultGroup' => $this->defaultGroup,
];
}

trigger_deprecation('symfony/validator', '7.4', 'Implementing "%s::__sleep()" is deprecated, use "__serialize()" instead.', get_debug_type($this));

$data = [];
foreach ($this->__sleep() as $key) {
try {
if (($r = new \ReflectionProperty($this, $key))->isInitialized($this)) {
$data[$key] = $r->getValue($this);
}
} catch (\ReflectionException) {
$data[$key] = $this->$key;
}
}

// Don't store the cascading strategy. Classes never cascade.
unset($parentProperties[array_search('cascadingStrategy', $parentProperties)]);
return $data;
}

/**
* @deprecated since Symfony 7.4, will be removed in 8.0
*/
public function __sleep(): array
{
trigger_deprecation('symfony/validator', '7.4', 'Calling "%s::__sleep()" is deprecated, use "__serialize()" instead.', get_debug_type($this));

return array_merge($parentProperties, [
return [
'constraints',
'constraintsByGroup',
'traversalStrategy',
'autoMappingStrategy',
'getters',
'groupSequence',
'groupSequenceProvider',
Expand All @@ -135,7 +174,7 @@ public function __sleep(): array
'name',
'properties',
'defaultGroup',
]);
];
}

public function getClassName(): string
Expand Down
34 changes: 31 additions & 3 deletions src/Symfony/Component/Validator/Mapping/GenericMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,41 @@ class GenericMetadata implements MetadataInterface
*/
public int $autoMappingStrategy = AutoMappingStrategy::NONE;

public function __serialize(): array
{
if (self::class === (new \ReflectionMethod($this, '__sleep'))->class) {
return [
'constraints' => $this->constraints,
'constraintsByGroup' => $this->constraintsByGroup,
'cascadingStrategy' => $this->cascadingStrategy,
'traversalStrategy' => $this->traversalStrategy,
'autoMappingStrategy' => $this->autoMappingStrategy,
];
}

trigger_deprecation('symfony/validator', '7.4', 'Implementing "%s::__sleep()" is deprecated, use "__serialize()" instead.', get_debug_type($this));

$data = [];
foreach ($this->__sleep() as $key) {
try {
if (($r = new \ReflectionProperty($this, $key))->isInitialized($this)) {
$data[$key] = $r->getValue($this);
}
} catch (\ReflectionException) {
$data[$key] = $this->$key;
}
}

return $data;
}

/**
* Returns the names of the properties that should be serialized.
*
* @return string[]
* @deprecated since Symfony 7.4, will be replaced by `__serialize()` in 8.0
*/
public function __sleep(): array
{
trigger_deprecation('symfony/validator', '7.4', 'Calling "%s::__sleep()" is deprecated, use "__serialize()" instead.', get_debug_type($this));

return [
'constraints',
'constraintsByGroup',
Expand Down
45 changes: 43 additions & 2 deletions src/Symfony/Component/Validator/Mapping/MemberMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,54 @@ public function addConstraint(Constraint $constraint): static
return $this;
}

public function __serialize(): array
{
if (self::class === (new \ReflectionMethod($this, '__sleep'))->class) {
return [
'constraints' => $this->constraints,
'constraintsByGroup' => $this->constraintsByGroup,
'cascadingStrategy' => $this->cascadingStrategy,
'traversalStrategy' => $this->traversalStrategy,
'autoMappingStrategy' => $this->autoMappingStrategy,
'class' => $this->class,
'name' => $this->name,
'property' => $this->property,
];
}

trigger_deprecation('symfony/validator', '7.4', 'Implementing "%s::__sleep()" is deprecated, use "__serialize()" instead.', get_debug_type($this));

$data = [];
foreach ($this->__sleep() as $key) {
try {
if (($r = new \ReflectionProperty($this, $key))->isInitialized($this)) {
$data[$key] = $r->getValue($this);
}
} catch (\ReflectionException) {
$data[$key] = $this->$key;
}
}

return $data;
}

/**
* @deprecated since Symfony 7.4, will be replaced by `__serialize()` in 8.0
*/
public function __sleep(): array
{
return array_merge(parent::__sleep(), [
trigger_deprecation('symfony/validator', '7.4', 'Calling "%s::__sleep()" is deprecated, use "__serialize()" instead.', get_debug_type($this));

return [
'constraints',
'constraintsByGroup',
'cascadingStrategy',
'traversalStrategy',
'autoMappingStrategy',
'class',
'name',
'property',
]);
];
}

/**
Expand Down
Loading