*/ private array $legacyToString = []; public function __construct(string $file){ $stringToLegacyId = json_decode(Filesystem::fileGetContents($file), true); if(!is_array($stringToLegacyId)){ throw new AssumptionFailedError("Invalid format of ID map"); } foreach(Utils::promoteKeys($stringToLegacyId) as $stringId => $legacyId){ if(!is_string($stringId) || !is_int($legacyId)){ throw new AssumptionFailedError("ID map should have string keys and int values"); } $this->legacyToString[$legacyId] = $stringId; } } public function legacyToString(int $legacy) : ?string{ return $this->legacyToString[$legacy] ?? null; } /** * @return string[] * @phpstan-return array */ public function getLegacyToStringMap() : array{ return $this->legacyToString; } public function add(string $string, int $legacy) : void{ if(isset($this->legacyToString[$legacy])){ if($this->legacyToString[$legacy] === $string){ return; } throw new \InvalidArgumentException("Legacy ID $legacy is already mapped to string " . $this->legacyToString[$legacy]); } $this->legacyToString[$legacy] = $string; } }