20250224#2
This commit is contained in:
@@ -9,7 +9,6 @@ use ReflectionException;
|
||||
class AbstractDataObject {
|
||||
|
||||
private static array $constructorEmptyAvailableClasses = [];
|
||||
private static array $constructorNullAvailableClasses = [];
|
||||
private static array $stack = [];
|
||||
|
||||
/**
|
||||
@@ -49,10 +48,6 @@ class AbstractDataObject {
|
||||
elseif(isset($value[$property->getName()])){
|
||||
$object->{$property->getName()} = new ($property->getType()->getName())($value[$property->getName()]);
|
||||
}
|
||||
// Значение NULL и VO может принимать null в виде единственного значения
|
||||
elseif(array_key_exists($property->getName(), $value) && self::isNullAvailable($property->getType()->getName())) {
|
||||
$object->{$property->getName()} = new ($property->getType()->getName())(null);
|
||||
}
|
||||
// Значения нет и VO может быть без параметров
|
||||
elseif(self::isEmptyAvailable($property->getType()->getName())) {
|
||||
$object->{$property->getName()} = new ($property->getType()->getName())();
|
||||
@@ -85,18 +80,6 @@ class AbstractDataObject {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
private static function isNullAvailable(string $class) : bool {
|
||||
if(isset(self::$constructorNullAvailableClasses[$class])) return self::$constructorNullAvailableClasses[$class];
|
||||
if(!$constructor = (new \ReflectionClass($class))->getConstructor()) return self::$constructorNullAvailableClasses[$class] = false;
|
||||
$parameters = $constructor->getParameters();
|
||||
if(count($parameters) == 1 && $parameters[0]->allowsNull()) return self::$constructorNullAvailableClasses[$class] = true;
|
||||
return self::$constructorNullAvailableClasses[$class] = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
@@ -111,6 +94,7 @@ class AbstractDataObject {
|
||||
return self::$constructorEmptyAvailableClasses[$class] = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
|
||||
@@ -37,7 +37,7 @@ abstract class AbstractRepository extends AbstractDataObject implements Reposito
|
||||
$fieldValue[$property->getName()] = $property->getValue($object);
|
||||
}
|
||||
|
||||
if(false !== $fieldValue[$property->getName()]) {
|
||||
if(array_key_exists($property->getName(), $fieldValue) && false !== $fieldValue[$property->getName()]) {
|
||||
$out[strtolower(preg_replace("'([A-Z])'", "_$1", $property->getName()))] = $fieldValue[$property->getName()];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user