|null */ private static $valueToEci; /** * @var array|null */ private static $nameToEci; public function __construct(array $values, string ...$otherEncodingNames) { $this->values = $values; $this->otherEncodingNames = $otherEncodingNames; } /** * Returns the primary value. */ public function getValue() : int { return $this->values[0]; } /** * Gets character set ECI by value. * * Returns the representing ECI of a given value, or null if it is legal but unsupported. * * @throws InvalidArgumentException if value is not between 0 and 900 */ public static function getCharacterSetEciByValue(int $value) : ?self { if ($value < 0 || $value >= 900) { throw new InvalidArgumentException('Value must be between 0 and 900'); } $valueToEci = self::valueToEci(); if (! array_key_exists($value, $valueToEci)) { return null; } return $valueToEci[$value]; } /** * Returns character set ECI by name. * * Returns the representing ECI of a given name, or null if it is legal but unsupported */ public static function getCharacterSetEciByName(string $name) : ?self { $nameToEci = self::nameToEci(); $name = strtolower($name); if (! array_key_exists($name, $nameToEci)) { return null; } return $nameToEci[$name]; } private static function valueToEci() : array { if (null !== self::$valueToEci) { return self::$valueToEci; } self::$valueToEci = []; foreach (self::values() as $eci) { foreach ($eci->values as $value) { self::$valueToEci[$value] = $eci; } } return self::$valueToEci; } private static function nameToEci() : array { if (null !== self::$nameToEci) { return self::$nameToEci; } self::$nameToEci = []; foreach (self::values() as $eci) { self::$nameToEci[strtolower($eci->name())] = $eci; foreach ($eci->otherEncodingNames as $name) { self::$nameToEci[strtolower($name)] = $eci; } } return self::$nameToEci; } }