40 private array $legacyToString = [];
42 public function __construct(
string $file){
43 $stringToLegacyId = json_decode(Filesystem::fileGetContents($file),
true);
44 if(!is_array($stringToLegacyId)){
47 foreach(Utils::promoteKeys($stringToLegacyId) as $stringId => $legacyId){
48 if(!is_string($stringId) || !is_int($legacyId)){
51 $this->legacyToString[$legacyId] = $stringId;
55 public function legacyToString(
int $legacy) : ?
string{
56 return $this->legacyToString[$legacy] ??
null;
64 return $this->legacyToString;
67 public function add(
string $string,
int $legacy) : void{
68 if(isset($this->legacyToString[$legacy])){
69 if($this->legacyToString[$legacy] === $string){
72 throw new \InvalidArgumentException(
"Legacy ID $legacy is already mapped to string " . $this->legacyToString[$legacy]);
74 $this->legacyToString[$legacy] = $string;