Allow File::getInstance() with empty data.
This commit is contained in:
@ -5,25 +5,25 @@ abstract class File
|
||||
public $path;
|
||||
public $filename;
|
||||
/**
|
||||
* @param array|string $data
|
||||
* @param array|string|null $data
|
||||
* @return Image
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public static function getInstance($data)
|
||||
public static function getInstance($data = null)
|
||||
{
|
||||
if (is_null($data) || $data == '') {
|
||||
throw new ErrorException('Empty data for File::getInstance().');
|
||||
}
|
||||
if (!is_array($data)) {
|
||||
$instance = new static;
|
||||
if (!(is_null($data) && $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.');
|
||||
if (json_last_error() != JSON_ERROR_NONE) {
|
||||
//TODO: decrease warning level
|
||||
throw new ErrorException('Unable to convert json-string to array. Data ' . print_r($data, true));
|
||||
}
|
||||
}
|
||||
}
|
||||
$instance = new static($data);
|
||||
foreach ($data as $attribute_name => $attribute_value) {
|
||||
if (property_exists($instance, $attribute_name)) {
|
||||
$instance->{$attribute_name} = $attribute_value;
|
||||
foreach ($data as $attribute_name => $attribute_value) {
|
||||
if (property_exists($instance, $attribute_name)) {
|
||||
$instance->{$attribute_name} = $attribute_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $instance;
|
||||
|
Reference in New Issue
Block a user