20250330#6
This commit is contained in:
@@ -8,7 +8,7 @@ use Attribute;
|
|||||||
class ValueObject {
|
class ValueObject {
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public bool $autoPropertyName = true,
|
public bool $autoPropertyName = false,
|
||||||
public ?string $propertyName = null,
|
public ?string $propertyName = null,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
|||||||
@@ -5,4 +5,4 @@ namespace Rmphp\Storage\Attribute;
|
|||||||
use Attribute;
|
use Attribute;
|
||||||
|
|
||||||
#[Attribute(Attribute::TARGET_CLASS)]
|
#[Attribute(Attribute::TARGET_CLASS)]
|
||||||
class ValueObjectWithoutAutoPropertyName {}
|
class ValueObjectAutoPropertyName {}
|
||||||
@@ -10,7 +10,7 @@ use Rmphp\Storage\Attribute\Property;
|
|||||||
use Rmphp\Storage\Attribute\PropertyNoReturn;
|
use Rmphp\Storage\Attribute\PropertyNoReturn;
|
||||||
use Rmphp\Storage\Attribute\PropertyNoReturnIfNull;
|
use Rmphp\Storage\Attribute\PropertyNoReturnIfNull;
|
||||||
use Rmphp\Storage\Attribute\ValueObject;
|
use Rmphp\Storage\Attribute\ValueObject;
|
||||||
use Rmphp\Storage\Attribute\ValueObjectWithoutAutoPropertyName;
|
use Rmphp\Storage\Attribute\ValueObjectAutoPropertyName;
|
||||||
use Rmphp\Storage\Component\AbstractDataObject;
|
use Rmphp\Storage\Component\AbstractDataObject;
|
||||||
use Rmphp\Storage\Exception\RepositoryException;
|
use Rmphp\Storage\Exception\RepositoryException;
|
||||||
|
|
||||||
@@ -62,19 +62,26 @@ abstract class AbstractRepository extends AbstractDataObject implements Reposito
|
|||||||
: new ValueObject();
|
: new ValueObject();
|
||||||
}
|
}
|
||||||
$valueObjectAttributes = self::$attributeObjects[$valueObjectClass];
|
$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(!empty($valueObjectAttributes->propertyName) && self::$classes[$valueObjectClass]->hasProperty($valueObjectAttributes->propertyName)){
|
||||||
if(self::$classes[$valueObjectClass]->getProperty($valueObjectAttributes->propertyName)->isInitialized($property->getValue($object))){
|
if(self::$classes[$valueObjectClass]->getProperty($valueObjectAttributes->propertyName)->isInitialized($property->getValue($object))){
|
||||||
$fieldValue[$property->getName()] = self::$classes[$valueObjectClass]->getProperty($valueObjectAttributes->propertyName)->getValue($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))){
|
if(self::$classes[$valueObjectClass]->getProperties()[0]->isInitialized($property->getValue($object))){
|
||||||
$fieldValue[$property->getName()] = self::$classes[$valueObjectClass]->getProperties()[0]->getValue($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();
|
$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))){
|
elseif(is_bool($property->getValue($object))){
|
||||||
$fieldValue[$property->getName()] = (int)$property->getValue($object);
|
$fieldValue[$property->getName()] = (int)$property->getValue($object);
|
||||||
|
|||||||
Reference in New Issue
Block a user