1<?php 2 3 4namespace ComboStrap; 5 6 7class Dictionary 8{ 9 10 /** 11 * @throws ExceptionCompile 12 */ 13 public static function getFrom(string $name): array 14 { 15 $path = DirectoryLayout::getComboDictionaryDirectory()->resolve("$name.json"); 16 if (!FileSystems::exists($path)) { 17 throw new ExceptionCompile("The dictionary file ($path) does not exist"); 18 } 19 $jsonContent = FileSystems::getContent($path); 20 try { 21 $dict = Json::createFromString($jsonContent)->toArray(); 22 } catch (ExceptionCompile $e) { 23 throw new ExceptionCompile("The dictionary ($path) is not a valid json. Error: {$e->getMessage()}"); 24 } 25 if ($dict === null) { 26 throw new ExceptionCompile("The returned dictionary of the file ($path) is empty"); 27 } 28 return $dict; 29 } 30} 31