Browse Source
Refactoring with use of separate to sub classes from Image. Add FileHelper to trying toString conversion. Add ImageCollection (not tested work).
master
Refactoring with use of separate to sub classes from Image. Add FileHelper to trying toString conversion. Add ImageCollection (not tested work).
master
Alexander Demidov
12 years ago
5 changed files with 94 additions and 39 deletions
-
29File.class.php
-
13FileHelper.class.php
-
40Image.class.php
-
34ImageCollection.class.php
-
17Upload.class.php
@ -0,0 +1,13 @@ |
|||
<?php |
|||
|
|||
class FileHelper |
|||
{ |
|||
public static function toString($object) |
|||
{ |
|||
$data = array(); |
|||
foreach ($object as $attribute_name => $attribute_value) { |
|||
$data[$attribute_name] = $attribute_value; |
|||
} |
|||
return json_encode($data); |
|||
} |
|||
} |
@ -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)); |
|||
} |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue