8000 [PropertyInfo] Support multiple builtinType (union types) by Korbeil · Pull Request #38987 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[PropertyInfo] Support multiple builtinType (union types) #38987

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
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
Add UnionType value object
  • Loading branch information
Korbeil committed Nov 5, 2020
commit bb4ccaa50cf2668932b281054abe4d24afe3a9f0
5 changes: 5 additions & 0 deletions src/Symfony/Component/PropertyInfo/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

5.3.0
-----

* Added ability to have union types in `Type` class.

5.2.0
-----

Expand Down
44 changes: 44 additions & 0 deletions src/Symfony/Component/PropertyInfo/UnionType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\PropertyInfo;

/**
* Union type value object (immutable).
*
* @author Baptiste Leduc <baptiste.leduc@gmail.com>
*/
final class UnionType
{
private $types;

/**
* @param Type[] $types
*/
public function __construct(array $types)
{
foreach ($types as $type) {
if (!$type instanceof Type) {
throw new \TypeError(sprintf('"%s()": Argument #1 ($types) must be an array with items of type "%s", "%s" given.', __METHOD__, Type::class, get_debug_type($type)));
}
}

$this->types = $types;
}

/**
* @return Type[]
*/
public function getTypes(): array
{
return $this->types;
}
}
0