Example #1
0
 public static function createFromJSON(array $json) : self
 {
     $collection = new self($json['uid'] ?? null);
     if ($json['is_auto_generated'] ?? false) {
         $collection->markAsAutoGenerated();
     }
     foreach ($json['variants'] ?? [] as $id => $definition) {
         $id = (string) $id;
         if (!(strlen($id) >= self::MIN_ID_LENGTH && strlen($id) <= self::MAX_ID_LENGTH)) {
             throw new \InvalidArgumentException(sprintf('Invalid ID `%s`', $id));
         }
         $collection->attachImage($id, new Image($definition['storage_path'], $definition['public_path']));
     }
     return $collection;
 }