| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
* This file is part of the Symfony package. |
| 5 |
* |
| 6 |
* (c) Fabien Potencier <[email protected]> |
| 7 |
* |
| 8 |
* For the full copyright and license information, please view the LICENSE |
| 9 |
* file that was distributed with this source code. |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace Symfony\Component\TypeInfo\Type; |
| 13 |
|
| 14 |
use Symfony\Component\TypeInfo\Exception\InvalidArgumentException; |
| 15 |
use Symfony\Component\TypeInfo\TypeIdentifier; |
| 16 |
|
| 17 |
/** |
| 18 |
* @author Mathias Arlaud <[email protected]> |
| 19 |
* @author Baptiste Leduc <[email protected]> |
| 20 |
* |
| 21 |
* @template T of class-string<\BackedEnum> |
| 22 |
* @template U of BuiltinType<TypeIdentifier::INT>|BuiltinType<TypeIdentifier::STRING> |
| 23 |
* |
| 24 |
* @extends EnumType<T> |
| 25 |
*/ |
| 26 |
final class BackedEnumType extends EnumType |
| 27 |
{ |
| 28 |
/** |
| 29 |
* @param T $className |
| 30 |
* @param U $backingType |
| 31 |
*/ |
| 32 |
public function __construct( |
| 33 |
string $className, |
| 34 |
private readonly BuiltinType $backingType, |
| 35 |
) { |
| 36 |
if (TypeIdentifier::INT !== $backingType->getTypeIdentifier() && TypeIdentifier::STRING !== $backingType->getTypeIdentifier()) { |
| 37 |
throw new InvalidArgumentException(\sprintf('Cannot create "%s" with "%s" backing type.', self::class, $backingType)); |
| 38 |
} |
| 39 |
|
| 40 |
parent::__construct($className); |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* @return U |
| 45 |
*/ |
| 46 |
public function getBackingType(): BuiltinType |
| 47 |
{ |
| 48 |
return $this->backingType; |
| 49 |
} |
| 50 |
} |