|
@ -12,20 +12,22 @@ abstract class File |
|
|
public static function getInstance($data = null) |
|
|
public static function getInstance($data = null) |
|
|
{ |
|
|
{ |
|
|
$instance = new static; |
|
|
$instance = new static; |
|
|
if (!(is_null($data) && $data == '')) { |
|
|
|
|
|
|
|
|
if (!(is_null($data) || $data == '')) { |
|
|
if (!is_array($data)) { |
|
|
if (!is_array($data)) { |
|
|
$data = json_decode($data, true); |
|
|
$data = json_decode($data, true); |
|
|
if (json_last_error() != JSON_ERROR_NONE) { |
|
|
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)); |
|
|
|
|
|
|
|
|
//TODO: подумать над тем, чтобы субмодуль не был связан с классом приложения - вынести отдельно логгер для этого класса
|
|
|
|
|
|
ErrorMessage::log('Unable to convert json-string to array. Data ' . print_r($data, true)); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
if (is_array($data)) { |
|
|
foreach ($data as $attribute_name => $attribute_value) { |
|
|
foreach ($data as $attribute_name => $attribute_value) { |
|
|
if (property_exists($instance, $attribute_name)) { |
|
|
if (property_exists($instance, $attribute_name)) { |
|
|
$instance->{$attribute_name} = $attribute_value; |
|
|
$instance->{$attribute_name} = $attribute_value; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
return $instance; |
|
|
return $instance; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|