You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
827 B

  1. <?php
  2. abstract class ImageCollection extends ArrayIterator
  3. {
  4. /**
  5. * @var string
  6. */
  7. protected $class;
  8. /**
  9. * @param array $data
  10. * @throws ErrorException
  11. */
  12. public function __construct($data)
  13. {
  14. /**
  15. * @var $class Image
  16. */
  17. $class = $this->class;
  18. Image::checkSubClass($class);
  19. if (is_null($data) || $data == '') {
  20. throw new ErrorException('Empty data.');
  21. }
  22. if (!is_array($data)) {
  23. $data = json_decode($data, true);
  24. if (json_last_error() != JSON_ERROR_NONE) {
  25. throw new ErrorException('Unable to convert json-string to array.');
  26. }
  27. }
  28. foreach ($data as $item_data) {
  29. $this->append($class::getInstance($item_data));
  30. }
  31. }
  32. }