34 lines
		
	
	
		
			827 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
		
		
			
		
	
	
			34 lines
		
	
	
		
			827 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
| 
								 | 
							
								<?php
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								abstract class ImageCollection extends ArrayIterator
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    /**
							 | 
						||
| 
								 | 
							
								     * @var string
							 | 
						||
| 
								 | 
							
								     */
							 | 
						||
| 
								 | 
							
								    protected $class;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    /**
							 | 
						||
| 
								 | 
							
								     * @param array $data
							 | 
						||
| 
								 | 
							
								     * @throws ErrorException
							 | 
						||
| 
								 | 
							
								     */
							 | 
						||
| 
								 | 
							
								    public function __construct($data)
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        /**
							 | 
						||
| 
								 | 
							
								         * @var $class Image
							 | 
						||
| 
								 | 
							
								         */
							 | 
						||
| 
								 | 
							
								        $class = $this->class;
							 | 
						||
| 
								 | 
							
								        Image::checkSubClass($class);
							 | 
						||
| 
								 | 
							
								        if (is_null($data) || $data == '') {
							 | 
						||
| 
								 | 
							
								            throw new ErrorException('Empty data.');
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								        if (!is_array($data)) {
							 | 
						||
| 
								 | 
							
								            $data = json_decode($data, true);
							 | 
						||
| 
								 | 
							
								            if (json_last_error() != JSON_ERROR_NONE) {
							 | 
						||
| 
								 | 
							
								                throw new ErrorException('Unable to convert json-string to array.');
							 | 
						||
| 
								 | 
							
								            }
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								        foreach ($data as $item_data) {
							 | 
						||
| 
								 | 
							
								            $this->append($class::getInstance($item_data));
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								}
							 |