20250327#2
This commit is contained in:
@@ -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()];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user