Fix bug with wrong if statement. Add TODO with use log error message.

This commit is contained in:
Alexander Demidov
2013-06-07 13:43:07 +04:00
parent 5011c7114a
commit d4bf288fed

View File

@ -12,17 +12,19 @@ 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 //TODO: подумать над тем, чтобы субмодуль не был связан с классом приложения - вынести отдельно логгер для этого класса
throw new ErrorException('Unable to convert json-string to array. Data ' . print_r($data, true)); ErrorMessage::log('Unable to convert json-string to array. Data ' . print_r($data, true));
} }
} }
foreach ($data as $attribute_name => $attribute_value) { if (is_array($data)) {
if (property_exists($instance, $attribute_name)) { foreach ($data as $attribute_name => $attribute_value) {
$instance->{$attribute_name} = $attribute_value; if (property_exists($instance, $attribute_name)) {
$instance->{$attribute_name} = $attribute_value;
}
} }
} }
} }