8000 Support multiple builtinType (union types) · symfony/symfony@bf96c1a · GitHub
[go: up one dir, main page]

Skip to content

Commit bf96c1a

Browse files
committed
Support multiple builtinType (union types)
1 parent 57e39b4 commit bf96c1a

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/Symfony/Component/PropertyInfo/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
5.3.0
5+
-----
6+
7+
* Added ability to have union types in `Type` class.
8+
49
5.2.0
510
-----
611

src/Symfony/Component/PropertyInfo/Type.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,16 @@ class Type
5959
/**
6060
* @throws \InvalidArgumentException
6161
*/
62-
public function __construct(string $builtinType, bool $nullable = false, string $class = null, bool $collection = false, self $collectionKeyType = null, self $collectionValueType = null)
62+
public function __construct(/* string|array */ $builtinType, bool $nullable = false, string $class = null, bool $collection = false, self $collectionKeyType = null, self $collectionValueType = null)
6363
{
64-
if (!\in_array($builtinType, self::$builtinTypes)) {
65-
throw new \InvalidArgumentException(sprintf('"%s" is not a valid PHP type.', $builtinType));
64+
if (!\is_string($builtinType) && !\is_array($builtinType)) {
65+
throw new \TypeError('"$builtinType" should be a string or an array.');
66+
}
67+
68+
foreach ((array) $builtinType as $type) {
69+
if (!\in_array($type, self::$builtinTypes)) {
70+
throw new \InvalidArgumentException(sprintf('"%s" is not a valid PHP type.', $type));
71+
}
6672
}
6773

6874
$this->builtinType = $builtinType;
@@ -77,8 +83,10 @@ public function __construct(string $builtinType, bool $nullable = false, string
7783
* Gets built-in type.
7884
*
7985
* Can be bool, int, float, string, array, object, resource, null, callback or iterable.
86+
*
87+
* @return string|array
8088
*/
81-
public function getBuiltinType(): string
89+
public function getBuiltinType()
8290
{
8391
return $this->builtinType;
8492
}

0 commit comments

Comments
 (0)
0