From 9c1f6be32666e2263b547002a2fac87bdd9a77d3 Mon Sep 17 00:00:00 2001 From: User Date: Sun, 30 Mar 2025 19:16:20 +0300 Subject: [PATCH] 20250330#4 --- src/Attribute/Data.php | 14 +++++++++++++ ...ntityIgnorEmpty.php => DataIgnorEmpty.php} | 2 +- src/Attribute/Entity.php | 2 +- src/Attribute/Property.php | 4 ++-- src/Component/AbstractDataObject.php | 20 +++++++++---------- src/Repository/AbstractRepository.php | 10 ++++------ 6 files changed, 32 insertions(+), 20 deletions(-) create mode 100644 src/Attribute/Data.php rename src/Attribute/{EntityIgnorEmpty.php => DataIgnorEmpty.php} (78%) diff --git a/src/Attribute/Data.php b/src/Attribute/Data.php new file mode 100644 index 0000000..9760fde --- /dev/null +++ b/src/Attribute/Data.php @@ -0,0 +1,14 @@ +getName()][0])){ - self::$attributeObjects[$class->getName()][0] = !empty($class->getAttributes(Entity::class)) - ? $class->getAttributes(Entity::class)[0]->newInstance() - : new Entity(); + self::$attributeObjects[$class->getName()][0] = !empty($class->getAttributes(Data::class)) + ? $class->getAttributes(Data::class)[0]->newInstance() + : new Data(); } - /** @var Entity $entityAttributes */ - $entityAttributes = self::$attributeObjects[$class->getName()][0]; - if(!empty($class->getAttributes(EntityIgnorEmpty::class))) $entityAttributes->ignorEmpty = true; + /** @var Data $dataAttributes */ + $dataAttributes = self::$attributeObjects[$class->getName()][0]; + if(!empty($class->getAttributes(DataIgnorEmpty::class))) $dataAttributes->ignorEmpty = true; $value = []; foreach($class->getProperties() as $property){ @@ -68,12 +68,12 @@ abstract class AbstractDataObject { $object->{$property->getName()} = new ($property->getType()->getName())($value[$property->getName()]); $case[$property->getName()] = 'VO: NewInstance'; } - elseif(($withEmpty && empty($entityAttributes->ignorEmpty)) && array_key_exists($property->getName(), $value)){ + elseif(($withEmpty && empty($dataAttributes->ignorEmpty)) && array_key_exists($property->getName(), $value)){ $object->{$property->getName()} = new ($property->getType()->getName())($value[$property->getName()]); $case[$property->getName()] = 'VO: NewInstance withEmpty'; } // Значения нет и VO может быть без параметров - elseif(($withEmpty && empty($entityAttributes->ignorEmpty)) && self::isEmptyAvailable($property->getType()->getName())) { + elseif(($withEmpty && empty($dataAttributes->ignorEmpty)) && self::isEmptyAvailable($property->getType()->getName())) { $object->{$property->getName()} = new ($property->getType()->getName())(); $case[$property->getName()] = 'VO: Without params'; } diff --git a/src/Repository/AbstractRepository.php b/src/Repository/AbstractRepository.php index 17786f1..af29b7d 100644 --- a/src/Repository/AbstractRepository.php +++ b/src/Repository/AbstractRepository.php @@ -5,7 +5,6 @@ namespace Rmphp\Storage\Repository; use Exception; use ReflectionClass; use Rmphp\Storage\Attribute\Entity; -use Rmphp\Storage\Attribute\EntityIgnorEmpty; use Rmphp\Storage\Attribute\EntityNoReturnIfNull; use Rmphp\Storage\Attribute\Property; use Rmphp\Storage\Attribute\PropertyNoReturn; @@ -30,8 +29,7 @@ abstract class AbstractRepository extends AbstractDataObject implements Reposito } /** @var Entity $entityAttributes */ $entityAttributes = self::$attributeObjects[$class][0]; - if(!empty(self::$classes[$class]->getAttributes(EntityIgnorEmpty::class))) $entityAttributes->ignorEmpty = true; - if(!empty(self::$classes[$class]->getAttributes(EntityNoReturnIfNull::class))) $entityAttributes->ignorEmpty = true; + if(!empty(self::$classes[$class]->getAttributes(EntityNoReturnIfNull::class))) $entityAttributes->noReturnIfNull = true; $fieldValue = []; foreach(self::$classes[$class]->getProperties() as $property){ @@ -43,9 +41,9 @@ abstract class AbstractRepository extends AbstractDataObject implements Reposito } /** @var Property $propertyAttributes */ $propertyAttributes = self::$attributeObjects[$class][$property->getName()]; - if(!empty($property->getAttributes(PropertyNoReturnIfNull::class))) $propertyAttributes->emptyIfNull = true; + if(!empty($property->getAttributes(PropertyNoReturnIfNull::class))) $propertyAttributes->noReturnIfNull = true; - if(!empty($property->getAttributes(PropertyNoReturn::class)) || !empty($propertyAttributes->empty)) continue; + if(!empty($property->getAttributes(PropertyNoReturn::class)) || !empty($propertyAttributes->noReturn)) continue; if($property->isInitialized($object)) { @@ -85,7 +83,7 @@ abstract class AbstractRepository extends AbstractDataObject implements Reposito $fieldValue[$property->getName()] = $property->getValue($object); } - if(!isset($fieldValue[$property->getName()]) && (!empty($propertyAttributes->emptyIfNull) || !empty($entityAttributes->ignorEmpty))) continue; + if(!isset($fieldValue[$property->getName()]) && (!empty($propertyAttributes->noReturnIfNull) || !empty($entityAttributes->noReturnIfNull))) continue; if(array_key_exists($property->getName(), $fieldValue) && false !== $fieldValue[$property->getName()]) { $columnName = !empty($propertyAttributes->keyName) ? $propertyAttributes->keyName : strtolower(preg_replace("'([A-Z])'", "_$1", $property->getName()));