You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Deprecated the `Type::getCollectionKeyType()` and `Type::getCollectionValueType()` methods, use `Type::getCollectionKeyTypes()` and `Type::getCollectionValueTypes()` instead.
Copy file name to clipboardExpand all lines: src/Symfony/Component/PropertyInfo/CHANGELOG.md
+6Lines changed: 6 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,12 @@
1
1
CHANGELOG
2
2
=========
3
3
4
+
5.3.0
5
+
-----
6
+
7
+
* Added support for multiple types for collection keys & values
8
+
* Deprecated the `Type::getCollectionKeyType()` and `Type::getCollectionValueType()` methods, use `Type::getCollectionKeyTypes()` and `Type::getCollectionValueTypes()` instead.
Copy file name to clipboardExpand all lines: src/Symfony/Component/PropertyInfo/Tests/TypeTest.php
+56-1Lines changed: 56 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -12,15 +12,24 @@
12
12
namespaceSymfony\Component\PropertyInfo\Tests;
13
13
14
14
usePHPUnit\Framework\TestCase;
15
+
useSymfony\Bridge\PhpUnit\ExpectDeprecationTrait;
15
16
useSymfony\Component\PropertyInfo\Type;
16
17
17
18
/**
18
19
* @author Kévin Dunglas <dunglas@gmail.com>
19
20
*/
20
21
class TypeTest extends TestCase
21
22
{
22
-
publicfunctiontestConstruct()
23
+
use ExpectDeprecationTrait;
24
+
25
+
/**
26
+
* @group legacy
27
+
*/
28
+
publicfunctiontestLegacyConstruct()
23
29
{
30
+
$this->expectDeprecation('Since symfony/property-info 5.3: The "Symfony\Component\PropertyInfo\Type::getCollectionKeyType()" method is deprecated, use "getCollectionKeyTypes()" instead.');
31
+
$this->expectDeprecation('Since symfony/property-info 5.3: The "Symfony\Component\PropertyInfo\Type::getCollectionValueType()" method is deprecated, use "getCollectionValueTypes()" instead.');
if (null !== $collectionArgument && !\is_array($collectionArgument) && !$collectionArgumentinstanceof self) {
86
+
thrownew \TypeError(sprintf('"%s()": Argument #%d (%s) must be of type "array", "%s" or "null", "%s" given.', __METHOD__, $argumentIndex, $argumentName, self::class, get_debug_type($collectionArgument)));
87
+
}
88
+
89
+
if (\is_array($collectionArgument)) {
90
+
foreach ($collectionArgumentas$type) {
91
+
if (!$typeinstanceof self) {
92
+
thrownew \TypeError(sprintf('"%s()": Argument #%d (%s) must be an array with items of type "%s", "%s" given.', __METHOD__, $argumentIndex, $argumentName, self::class, get_debug_type($collectionArgument)));
93
+
}
94
+
}
95
+
96
+
return$collectionArgument;
97
+
}
98
+
99
+
return [$collectionArgument];
74
100
}
75
101
76
102
/**
@@ -107,8 +133,27 @@ public function isCollection(): bool
107
133
* Gets collection key type.
108
134
*
109
135
* Only applicable for a collection type.
136
+
*
137
+
* @deprecated since Symfony 5.3, use "getCollectionKeyTypes()" instead
110
138
*/
111
139
publicfunctiongetCollectionKeyType(): ?self
140
+
{
141
+
trigger_deprecation('symfony/property-info', '5.3', 'The "%s()" method is deprecated, use "getCollectionKeyTypes()" instead.', __METHOD__);
142
+
143
+
$type = $this->getCollectionKeyTypes();
144
+
if (\is_array($type)) {
145
+
[$type] = $type;
146
+
}
147
+
148
+
return$type;
149
+
}
150
+
151
+
/**
152
+
* Gets collection key types.
153
+
*
154
+
* Only applicable for a collection type.
155
+
*/
156
+
publicfunctiongetCollectionKeyTypes(): ?array
112
157
{
113
158
return$this->collectionKeyType;
114
159
}
@@ -117,8 +162,27 @@ public function getCollectionKeyType(): ?self
117
162
* Gets collection value type.
118
163
*
119
164
* Only applicable for a collection type.
165
+
*
166
+
* @deprecated since Symfony 5.3, use "getCollectionValueTypes()" instead
120
167
*/
121
168
publicfunctiongetCollectionValueType(): ?self
169
+
{
170
+
trigger_deprecation('symfony/property-info', '5.3', 'The "%s()" method is deprecated, use "getCollectionValueTypes()" instead.', __METHOD__);
0 commit comments