Refactoring with use of separate to sub classes from Image. Add FileHelper to trying toString conversion. Add ImageCollection (not tested work).

This commit is contained in:
Alexander Demidov
2013-05-29 15:01:54 +04:00
parent 47e20b1ef8
commit 5a73c9773d
5 changed files with 94 additions and 39 deletions

34
ImageCollection.class.php Normal file
View File

@ -0,0 +1,34 @@
<?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));
}
}
}