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:
@ -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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user