Skip to content

Commit 90b5a66

Browse files
committed
minor #30965 Prepare for the new serialization mechanism (fancyweb)
This PR was merged into the 4.3-dev branch. Discussion ---------- Prepare for the new serialization mechanism | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - #eufossa Should I maybe split this component by component ? https://wiki.php.net/rfc/custom_object_serialization has been accepted. Best viewed in "split" mode. This work is kind of required for symfony/symfony#30304 so we don't trigger 30 deprecations from our own code base. Commits ------- d412e77a9c Prepare for the new serialization mechanism
2 parents 74cd8e7 + e8e1f33 commit 90b5a66

File tree

2 files changed

+33
-16
lines changed

2 files changed

+33
-16
lines changed

CompiledRoute.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,9 @@ public function __construct(string $staticPrefix, string $regex, array $tokens,
4949
$this->variables = $variables;
5050
}
5151

52-
/**
53-
* @internal since Symfony 4.3, will be removed in Symfony 5 as the class won't implement Serializable anymore
54-
*/
55-
public function serialize()
52+
public function __serialize(): array
5653
{
57-
return serialize([
54+
return [
5855
'vars' => $this->variables,
5956
'path_prefix' => $this->staticPrefix,
6057
'path_regex' => $this->regex,
@@ -63,16 +60,19 @@ public function serialize()
6360
'host_regex' => $this->hostRegex,
6461
'host_tokens' => $this->hostTokens,
6562
'host_vars' => $this->hostVariables,
66-
]);
63+
];
6764
}
6865

6966
/**
7067
* @internal since Symfony 4.3, will be removed in Symfony 5 as the class won't implement Serializable anymore
7168
*/
72-
public function unserialize($serialized)
69+
public function serialize()
7370
{
74-
$data = unserialize($serialized, ['allowed_classes' => false]);
71+
return serialize($this->__serialize());
72+
}
7573

74+
public function __unserialize(array $data): void
75+
{
7676
$this->variables = $data['vars'];
7777
$this->staticPrefix = $data['path_prefix'];
7878
$this->regex = $data['path_regex'];
@@ -83,6 +83,14 @@ public function unserialize($serialized)
8383
$this->hostVariables = $data['host_vars'];
8484
}
8585

86+
/**
87+
* @internal since Symfony 4.3, will be removed in Symfony 5 as the class won't implement Serializable anymore
88+
*/
89+
public function unserialize($serialized)
90+
{
91+
$this->__unserialize(unserialize($serialized, ['allowed_classes' => false]));
92+
}
93+
8694
/**
8795
* Returns the static prefix.
8896
*

Route.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,9 @@ public function __construct(string $path, array $defaults = [], array $requireme
6262
$this->setCondition($condition);
6363
}
6464

65-
/**
66-
* @internal since Symfony 4.3, will be removed in Symfony 5 as the class won't implement Serializable anymore
67-
*/
68-
public function serialize()
65+
public function __serialize(): array
6966
{
70-
return serialize([
67+
return [
7168
'path' => $this->path,
7269
'host' => $this->host,
7370
'defaults' => $this->defaults,
@@ -77,15 +74,19 @@ public function serialize()
7774
'methods' => $this->methods,
7875
'condition' => $this->condition,
7976
'compiled' => $this->compiled,
80-
]);
77+
];
8178
}
8279

8380
/**
8481
* @internal since Symfony 4.3, will be removed in Symfony 5 as the class won't implement Serializable anymore
8582
*/
86-
public function unserialize($serialized)
83+
public function serialize()
84+
{
85+
return serialize($this->__serialize());
86+
}
87+
88+
public function __unserialize(array $data): void
8789
{
88-
$data = unserialize($serialized);
8990
$this->path = $data['path'];
9091
$this->host = $data['host'];
9192
$this->defaults = $data['defaults'];
@@ -102,6 +103,14 @@ public function unserialize($serialized)
102103
}
103104
}
104105

106+
/**
107+
* @internal since Symfony 4.3, will be removed in Symfony 5 as the class won't implement Serializable anymore
108+
*/
109+
public function unserialize($serialized)
110+
{
111+
$this->__unserialize(unserialize($serialized));
112+
}
113+
105114
/**
106115
* Returns the pattern for the path.
107116
*

0 commit comments

Comments
 (0)