From 30a20d427b9b9713b726f06eed7a2415cfd1ac57 Mon Sep 17 00:00:00 2001 From: User Date: Thu, 27 Mar 2025 03:01:09 +0300 Subject: [PATCH] 20250327#2 --- src/Component/AbstractDataObject.php | 10 +++++----- src/Repository/AbstractRepository.php | 8 ++++---- src/Repository/RepositoryInterface.php | 8 ++++---- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Component/AbstractDataObject.php b/src/Component/AbstractDataObject.php index 6d09d1d..064c0e8 100644 --- a/src/Component/AbstractDataObject.php +++ b/src/Component/AbstractDataObject.php @@ -16,11 +16,11 @@ class AbstractDataObject { * @param object $object * @param array $data * @param bool $update - * @param bool $onlyNotNull + * @param bool $withNull * @return mixed * @throws Exception */ - protected static function fillObject(ReflectionClass $class, object $object, array $data, bool $update = false, bool $onlyNotNull = false) : mixed { + protected static function fillObject(ReflectionClass $class, object $object, array $data, bool $update = false, bool $withNull = true) : mixed { try { $value = []; foreach($class->getProperties() as $property){ @@ -49,11 +49,11 @@ class AbstractDataObject { elseif(isset($value[$property->getName()]) && $value[$property->getName()] != ""){ $object->{$property->getName()} = new ($property->getType()->getName())($value[$property->getName()]); } - elseif(!$onlyNotNull && isset($value[$property->getName()])){ + elseif($withNull && isset($value[$property->getName()])){ $object->{$property->getName()} = new ($property->getType()->getName())($value[$property->getName()]); } // Значения нет и VO может быть без параметров - elseif(!$onlyNotNull && self::isEmptyAvailable($property->getType()->getName())) { + elseif($withNull && self::isEmptyAvailable($property->getType()->getName())) { $object->{$property->getName()} = new ($property->getType()->getName())(); } } @@ -71,7 +71,7 @@ class AbstractDataObject { elseif(isset($value[$property->getName()]) && $value[$property->getName()] != ""){ $object->{$property->getName()} = $value[$property->getName()]; } - elseif(!$onlyNotNull && isset($value[$property->getName()])){ + elseif($withNull && isset($value[$property->getName()])){ $object->{$property->getName()} = $value[$property->getName()]; } } diff --git a/src/Repository/AbstractRepository.php b/src/Repository/AbstractRepository.php index 7626e27..eec880a 100644 --- a/src/Repository/AbstractRepository.php +++ b/src/Repository/AbstractRepository.php @@ -52,10 +52,10 @@ abstract class AbstractRepository extends AbstractDataObject implements Reposito * @inheritDoc * @throws RepositoryException */ - public function createFromData(string $class, array|object $data, bool $onlyNotNull = false) : object { + public function createFromData(string $class, array|object $data, bool $withNull = true) : object { try { if(!isset(self::$classes[$class])) self::$classes[$class] = new ReflectionClass($class); - return self::fillObject(self::$classes[$class], new $class, (is_object($data)) ? get_object_vars($data) : $data, false, $onlyNotNull); + return self::fillObject(self::$classes[$class], new $class, (is_object($data)) ? get_object_vars($data) : $data, false, $withNull); } catch (Exception $exception) { throw new RepositoryException($exception->getMessage()); @@ -67,11 +67,11 @@ abstract class AbstractRepository extends AbstractDataObject implements Reposito * @inheritDoc * @throws RepositoryException */ - public function updateFromData(object $object, array|object $data, bool $onlyNotNull = false) : object { + public function updateFromData(object $object, array|object $data, bool $withNull = true) : object { try { $class = get_class($object); if(!isset(self::$classes[$class])) self::$classes[$class] = new ReflectionClass($class); - return self::fillObject(self::$classes[$class], clone $object, (is_object($data)) ? get_object_vars($data) : $data, true, $onlyNotNull); + return self::fillObject(self::$classes[$class], clone $object, (is_object($data)) ? get_object_vars($data) : $data, true, $withNull); } catch (Exception $exception) { throw new RepositoryException($exception->getMessage()); diff --git a/src/Repository/RepositoryInterface.php b/src/Repository/RepositoryInterface.php index 5125afc..a9b563c 100644 --- a/src/Repository/RepositoryInterface.php +++ b/src/Repository/RepositoryInterface.php @@ -25,19 +25,19 @@ interface RepositoryInterface { /** * @param string $class * @param array|object $data - * @param bool $onlyNotNull + * @param bool $withNull * @return mixed */ - public function createFromData(string $class, array|object $data, bool $onlyNotNull = false) : mixed; + public function createFromData(string $class, array|object $data, bool $withNull = true) : mixed; /** * @param object $object * @param array|object $data - * @param bool $onlyNotNull + * @param bool $withNull * @return mixed */ - public function updateFromData(object $object, array|object $data, bool $onlyNotNull = false) : mixed; + public function updateFromData(object $object, array|object $data, bool $withNull = true) : mixed; /**