Deprecated: Constant E_STRICT is deprecated in /home/pastorz/old-espace-client/vendor/symfony/error-handler/ErrorHandler.php on line 58

Deprecated: Constant E_STRICT is deprecated in /home/pastorz/old-espace-client/vendor/symfony/error-handler/ErrorHandler.php on line 76
Symfony Profiler

vendor/symfony/property-info/Type.php line 79

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\PropertyInfo;
  11. /**
  12.  * Type value object (immutable).
  13.  *
  14.  * @author Kévin Dunglas <dunglas@gmail.com>
  15.  *
  16.  * @final
  17.  */
  18. class Type
  19. {
  20.     public const BUILTIN_TYPE_INT 'int';
  21.     public const BUILTIN_TYPE_FLOAT 'float';
  22.     public const BUILTIN_TYPE_STRING 'string';
  23.     public const BUILTIN_TYPE_BOOL 'bool';
  24.     public const BUILTIN_TYPE_RESOURCE 'resource';
  25.     public const BUILTIN_TYPE_OBJECT 'object';
  26.     public const BUILTIN_TYPE_ARRAY 'array';
  27.     public const BUILTIN_TYPE_NULL 'null';
  28.     public const BUILTIN_TYPE_FALSE 'false';
  29.     public const BUILTIN_TYPE_TRUE 'true';
  30.     public const BUILTIN_TYPE_CALLABLE 'callable';
  31.     public const BUILTIN_TYPE_ITERABLE 'iterable';
  32.     /**
  33.      * List of PHP builtin types.
  34.      *
  35.      * @var string[]
  36.      */
  37.     public static $builtinTypes = [
  38.         self::BUILTIN_TYPE_INT,
  39.         self::BUILTIN_TYPE_FLOAT,
  40.         self::BUILTIN_TYPE_STRING,
  41.         self::BUILTIN_TYPE_BOOL,
  42.         self::BUILTIN_TYPE_RESOURCE,
  43.         self::BUILTIN_TYPE_OBJECT,
  44.         self::BUILTIN_TYPE_ARRAY,
  45.         self::BUILTIN_TYPE_CALLABLE,
  46.         self::BUILTIN_TYPE_FALSE,
  47.         self::BUILTIN_TYPE_TRUE,
  48.         self::BUILTIN_TYPE_NULL,
  49.         self::BUILTIN_TYPE_ITERABLE,
  50.     ];
  51.     /**
  52.      * List of PHP builtin collection types.
  53.      *
  54.      * @var string[]
  55.      */
  56.     public static $builtinCollectionTypes = [
  57.         self::BUILTIN_TYPE_ARRAY,
  58.         self::BUILTIN_TYPE_ITERABLE,
  59.     ];
  60.     private $builtinType;
  61.     private $nullable;
  62.     private $class;
  63.     private $collection;
  64.     private $collectionKeyType;
  65.     private $collectionValueType;
  66.     /**
  67.      * @param Type[]|Type|null $collectionKeyType
  68.      * @param Type[]|Type|null $collectionValueType
  69.      *
  70.      * @throws \InvalidArgumentException
  71.      */
  72.     public function __construct(string $builtinTypebool $nullable falsestring $class nullbool $collection false$collectionKeyType null$collectionValueType null)
  73.     {
  74.         if (!\in_array($builtinTypeself::$builtinTypes)) {
  75.             throw new \InvalidArgumentException(sprintf('"%s" is not a valid PHP type.'$builtinType));
  76.         }
  77.         $this->builtinType $builtinType;
  78.         $this->nullable $nullable;
  79.         $this->class $class;
  80.         $this->collection $collection;
  81.         $this->collectionKeyType $this->validateCollectionArgument($collectionKeyType5'$collectionKeyType') ?? [];
  82.         $this->collectionValueType $this->validateCollectionArgument($collectionValueType6'$collectionValueType') ?? [];
  83.     }
  84.     private function validateCollectionArgument($collectionArgumentint $argumentIndexstring $argumentName): ?array
  85.     {
  86.         if (null === $collectionArgument) {
  87.             return null;
  88.         }
  89.         if (!\is_array($collectionArgument) && !$collectionArgument instanceof self) {
  90.             throw new \TypeError(sprintf('"%s()": Argument #%d (%s) must be of type "%s[]", "%s" or "null", "%s" given.'__METHOD__$argumentIndex$argumentNameself::class, self::class, get_debug_type($collectionArgument)));
  91.         }
  92.         if (\is_array($collectionArgument)) {
  93.             foreach ($collectionArgument as $type) {
  94.                 if (!$type instanceof self) {
  95.                     throw new \TypeError(sprintf('"%s()": Argument #%d (%s) must be of type "%s[]", "%s" or "null", array value "%s" given.'__METHOD__$argumentIndex$argumentNameself::class, self::class, get_debug_type($collectionArgument)));
  96.                 }
  97.             }
  98.             return $collectionArgument;
  99.         }
  100.         return [$collectionArgument];
  101.     }
  102.     /**
  103.      * Gets built-in type.
  104.      *
  105.      * Can be bool, int, float, string, array, object, resource, null, callback or iterable.
  106.      */
  107.     public function getBuiltinType(): string
  108.     {
  109.         return $this->builtinType;
  110.     }
  111.     public function isNullable(): bool
  112.     {
  113.         return $this->nullable;
  114.     }
  115.     /**
  116.      * Gets the class name.
  117.      *
  118.      * Only applicable if the built-in type is object.
  119.      */
  120.     public function getClassName(): ?string
  121.     {
  122.         return $this->class;
  123.     }
  124.     public function isCollection(): bool
  125.     {
  126.         return $this->collection;
  127.     }
  128.     /**
  129.      * Gets collection key type.
  130.      *
  131.      * Only applicable for a collection type.
  132.      *
  133.      * @deprecated since Symfony 5.3, use "getCollectionKeyTypes()" instead
  134.      */
  135.     public function getCollectionKeyType(): ?self
  136.     {
  137.         trigger_deprecation('symfony/property-info''5.3''The "%s()" method is deprecated, use "getCollectionKeyTypes()" instead.'__METHOD__);
  138.         $type $this->getCollectionKeyTypes();
  139.         if (=== \count($type)) {
  140.             return null;
  141.         }
  142.         if (\is_array($type)) {
  143.             [$type] = $type;
  144.         }
  145.         return $type;
  146.     }
  147.     /**
  148.      * Gets collection key types.
  149.      *
  150.      * Only applicable for a collection type.
  151.      *
  152.      * @return Type[]
  153.      */
  154.     public function getCollectionKeyTypes(): array
  155.     {
  156.         return $this->collectionKeyType;
  157.     }
  158.     /**
  159.      * Gets collection value type.
  160.      *
  161.      * Only applicable for a collection type.
  162.      *
  163.      * @deprecated since Symfony 5.3, use "getCollectionValueTypes()" instead
  164.      */
  165.     public function getCollectionValueType(): ?self
  166.     {
  167.         trigger_deprecation('symfony/property-info''5.3''The "%s()" method is deprecated, use "getCollectionValueTypes()" instead.'__METHOD__);
  168.         return $this->getCollectionValueTypes()[0] ?? null;
  169.     }
  170.     /**
  171.      * Gets collection value types.
  172.      *
  173.      * Only applicable for a collection type.
  174.      *
  175.      * @return Type[]
  176.      */
  177.     public function getCollectionValueTypes(): array
  178.     {
  179.         return $this->collectionValueType;
  180.     }
  181. }