Fix bug with wrong if statement. Add TODO with use log error message.
This commit is contained in:
@ -12,17 +12,19 @@ abstract class File
|
||||
public static function getInstance($data = null)
|
||||
{
|
||||
$instance = new static;
|
||||
if (!(is_null($data) && $data == '')) {
|
||||
if (!(is_null($data) || $data == '')) {
|
||||
if (!is_array($data)) {
|
||||
$data = json_decode($data, true);
|
||||
$data = json_decode($data, true);
|
||||
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));
|
||||
}
|
||||
}
|
||||
foreach ($data as $attribute_name => $attribute_value) {
|
||||
if (property_exists($instance, $attribute_name)) {
|
||||
$instance->{$attribute_name} = $attribute_value;
|
||||
if (is_array($data)) {
|
||||
foreach ($data as $attribute_name => $attribute_value) {
|
||||
if (property_exists($instance, $attribute_name)) {
|
||||
$instance->{$attribute_name} = $attribute_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user