![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/laminas/laminas-code/src/Generator/EnumGenerator/Cases/ |
<?php namespace Laminas\Code\Generator\EnumGenerator\Cases; use InvalidArgumentException; use function in_array; use function sprintf; /** * @internal * * @psalm-immutable */ final class BackedCases { /** * @param 'int'|'string' $type * @param list<non-empty-string> $cases */ private function __construct(public readonly string $type, public readonly array $cases) { } /** * @param array<non-empty-string, int>|array<non-empty-string, string> $backedCases * @param 'int'|'string' $type */ public static function fromCasesWithType(array $backedCases, string $type): self { if (! ($type === 'int' || $type === 'string')) { throw new InvalidArgumentException(sprintf( '"%s" is not a valid type for Enums, only "int" and "string" types are allowed.', $type )); } $cases = []; foreach ($backedCases as $case => $value) { if ($type === 'string') { $value = sprintf("'%s'", $value); } $cases[] = $case . ' = ' . $value; } return new self($type, $cases); } }