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

View File

@ -10,33 +10,27 @@ class Image extends File
public $original_filename;
public $variants = array();
const SIZE_100_80 = '100x80';
const SIZE_200_160 = '200x160';
const SIZE_300_240 = '300x240';
const SIZE_550_440 = '550x440';
const SIZE_SKI = 'x';
const SIZE_INSTRUCTION = 'x';
public static $sizes = array(
self::SIZE_100_80,
self::SIZE_200_160,
self::SIZE_300_240,
self::SIZE_550_440
);
protected $sizes;
/**
* @param $size string
* @return Image
* @param $class string
* @throws ErrorException
*/
public function getVariant($size)
public static function checkSubClass($class)
{
if (!array_key_exists($size, $this->variants)) {
$this->variants[$size] = new ImageVariant;
} else {
if (!is_object($this->variants[$size])) {
$this->variants[$size] = parent::getInstance($this->variants[$size]);
}
if (is_null($class) || $class == '') {
throw new ErrorException('Class not defined.');
}
return $this->variants[$size];
if (!class_exists($class)) {
throw new ErrorException('Class "' . $class . '" not exists.');
}
if (get_parent_class($class) != 'Image') {
throw new ErrorException('Class "' . $class . '" mast be extend of "Image".');
}
}
public function getSizes()
{
return $this->sizes;
}
}