diff --git a/File.class.php b/File.class.php index e430728..da9b374 100644 --- a/File.class.php +++ b/File.class.php @@ -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; + } } } }