39 private array $legacyToString = [];
41 public function __construct(
string $file){
42 $stringToLegacyId = json_decode(Filesystem::fileGetContents($file),
true);
43 if(!is_array($stringToLegacyId)){
46 foreach($stringToLegacyId as $stringId => $legacyId){
47 if(!is_string($stringId) || !is_int($legacyId)){
50 $this->legacyToString[$legacyId] = $stringId;
54 public function legacyToString(
int $legacy) : ?
string{
55 return $this->legacyToString[$legacy] ??
null;
63 return $this->legacyToString;
66 public function add(
string $string,
int $legacy) : void{
67 if(isset($this->legacyToString[$legacy])){
68 if($this->legacyToString[$legacy] === $string){
71 throw new \InvalidArgumentException(
"Legacy ID $legacy is already mapped to string " . $this->legacyToString[$legacy]);
73 $this->legacyToString[$legacy] = $string;