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:
@ -11,7 +11,6 @@ abstract class File
|
||||
*/
|
||||
public static function getInstance($data)
|
||||
{
|
||||
$instance = new static($data);
|
||||
if (is_null($data) || $data == '') {
|
||||
throw new ErrorException('Empty data for File::getInstance().');
|
||||
}
|
||||
@ -21,6 +20,7 @@ abstract class File
|
||||
throw new ErrorException('Unable to convert json-string to array.');
|
||||
}
|
||||
}
|
||||
$instance = new static($data);
|
||||
foreach ($data as $attribute_name => $attribute_value) {
|
||||
if (property_exists($instance, $attribute_name)) {
|
||||
$instance->{$attribute_name} = $attribute_value;
|
||||
@ -30,6 +30,22 @@ abstract class File
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $size string
|
||||
* @return ImageVariant
|
||||
*/
|
||||
public function getImageVariant($size)
|
||||
{
|
||||
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]);
|
||||
}
|
||||
}
|
||||
return $this->variants[$size];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getWebName()
|
||||
@ -39,15 +55,6 @@ abstract class File
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return self::toString($this);
|
||||
}
|
||||
|
||||
private static function toString($class)
|
||||
{
|
||||
$data = array();
|
||||
foreach ($class as $attribute_name => $attribute_value) {
|
||||
$data[$attribute_name] = $attribute_value;
|
||||
}
|
||||
return json_encode($data);
|
||||
return FileHelper::toString($this);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user