42    public static function loadSchemas(
string $path, 
int $maxSchemaId) : array{
 
   43        $iterator = new \RegexIterator(
 
   44            new \FilesystemIterator(
 
   46                \FilesystemIterator::KEY_AS_FILENAME | \FilesystemIterator::SKIP_DOTS
 
   48            '/^(\d{4}).*\.json$/',
 
   49            \RegexIterator::GET_MATCH,
 
   50            \RegexIterator::USE_KEY
 
   56        foreach($iterator as $matches){
 
   57            $filename = $matches[0];
 
   58            $schemaId = (int) $matches[1];
 
   59            if($schemaId > $maxSchemaId){
 
   63            $fullPath = Path::join($path, $filename);
 
   65            $raw = Filesystem::fileGetContents($fullPath);
 
   68                $schema = self::loadSchemaFromString($raw, $schemaId);
 
   69            }
catch(\RuntimeException $e){
 
   70                throw new \RuntimeException(
"Loading schema file $fullPath: " . $e->getMessage(), 0, $e);
 
   73            $result[$schemaId] = $schema;
 
   76        ksort($result, SORT_NUMERIC);
 
 
   80    public static function loadSchemaFromString(
string $raw, 
int $schemaId) : ItemIdMetaUpgradeSchema{
 
   82            $json = json_decode($raw, false, flags: JSON_THROW_ON_ERROR);
 
   83        }
catch(\JsonException $e){
 
   84            throw new \RuntimeException($e->getMessage(), 0, $e);
 
   86        if(!is_object($json)){
 
   87            throw new \RuntimeException(
"Unexpected root type of schema file " . gettype($json) . 
", expected object");
 
   90        $jsonMapper = new \JsonMapper();
 
   91        $jsonMapper->bExceptionOnMissingData = 
true;
 
   92        $jsonMapper->bExceptionOnUndefinedProperty = 
true;
 
   93        $jsonMapper->bStrictObjectTypeChecking = 
true;
 
   95            $model = $jsonMapper->map($json, 
new ItemIdMetaUpgradeSchemaModel());
 
   96        }
catch(\JsonMapper_Exception $e){
 
   97            throw new \RuntimeException($e->getMessage(), 0, $e);
 
  100        return new ItemIdMetaUpgradeSchema($model->renamedIds, $model->remappedMetas, $schemaId);