20250330#6

This commit is contained in:
User
2025-03-30 20:19:12 +03:00
parent e6fd18fa2f
commit 09e8520ded
3 changed files with 13 additions and 6 deletions

View File

@@ -8,7 +8,7 @@ use Attribute;
class ValueObject {
public function __construct(
public bool $autoPropertyName = true,
public bool $autoPropertyName = false,
public ?string $propertyName = null,
) {}

View File

@@ -5,4 +5,4 @@ namespace Rmphp\Storage\Attribute;
use Attribute;
#[Attribute(Attribute::TARGET_CLASS)]
class ValueObjectWithoutAutoPropertyName {}
class ValueObjectAutoPropertyName {}

View File

@@ -10,7 +10,7 @@ use Rmphp\Storage\Attribute\Property;
use Rmphp\Storage\Attribute\PropertyNoReturn;
use Rmphp\Storage\Attribute\PropertyNoReturnIfNull;
use Rmphp\Storage\Attribute\ValueObject;
use Rmphp\Storage\Attribute\ValueObjectWithoutAutoPropertyName;
use Rmphp\Storage\Attribute\ValueObjectAutoPropertyName;
use Rmphp\Storage\Component\AbstractDataObject;
use Rmphp\Storage\Exception\RepositoryException;
@@ -62,19 +62,26 @@ abstract class AbstractRepository extends AbstractDataObject implements Reposito
: new ValueObject();
}
$valueObjectAttributes = self::$attributeObjects[$valueObjectClass];
if(!empty(self::$classes[$valueObjectClass]->getAttributes(ValueObjectWithoutAutoPropertyName::class))) $valueObjectAttributes->autoPropertyName = false;
if(!empty(self::$classes[$valueObjectClass]->getAttributes(ValueObjectAutoPropertyName::class))) $valueObjectAttributes->autoPropertyName = true;
if(!empty($valueObjectAttributes->propertyName) && self::$classes[$valueObjectClass]->hasProperty($valueObjectAttributes->propertyName)){
if(self::$classes[$valueObjectClass]->getProperty($valueObjectAttributes->propertyName)->isInitialized($property->getValue($object))){
$fieldValue[$property->getName()] = self::$classes[$valueObjectClass]->getProperty($valueObjectAttributes->propertyName)->getValue($property->getValue($object));
}
} elseif(!empty($valueObjectAttributes->autoPropertyName) && count(self::$classes[$valueObjectClass]->getProperties()) === 1){
}
elseif(!empty($valueObjectAttributes->autoPropertyName) && count(self::$classes[$valueObjectClass]->getProperties()) === 1){
if(self::$classes[$valueObjectClass]->getProperties()[0]->isInitialized($property->getValue($object))){
$fieldValue[$property->getName()] = self::$classes[$valueObjectClass]->getProperties()[0]->getValue($property->getValue($object));
}
} elseif(self::$classes[$valueObjectClass]->hasMethod('getValue')){
}
elseif(self::$classes[$valueObjectClass]->hasMethod('getValue')){
$fieldValue[$property->getName()] = $property->getValue($object)->getValue();
}
elseif(count(self::$classes[$valueObjectClass]->getProperties()) === 1){
if(self::$classes[$valueObjectClass]->getProperties()[0]->isInitialized($property->getValue($object))){
$fieldValue[$property->getName()] = self::$classes[$valueObjectClass]->getProperties()[0]->getValue($property->getValue($object));
}
}
}
elseif(is_bool($property->getValue($object))){
$fieldValue[$property->getName()] = (int)$property->getValue($object);