20250330#1
This commit is contained in:
@@ -60,7 +60,7 @@ abstract class AbstractMysqlRepository extends AbstractRepository implements Mys
|
|||||||
$in = $this->getProperties($object, function ($value){
|
$in = $this->getProperties($object, function ($value){
|
||||||
return (is_string($value)) ? $this->mysql->escapeStr($value) : $value;
|
return (is_string($value)) ? $this->mysql->escapeStr($value) : $value;
|
||||||
});
|
});
|
||||||
if($this->getDebug()) {$this->debug($object, $in, $table, $this->getRepositoryStack()); exit;}
|
if($this->isDebug()) {$this->debug($object, $in, $table, ...$this->getDebugExtraData()); exit;}
|
||||||
try {
|
try {
|
||||||
if (!empty($object->getId()) && !empty($this->mysql->findById($table, $object->getId()))) {
|
if (!empty($object->getId()) && !empty($this->mysql->findById($table, $object->getId()))) {
|
||||||
$this->mysql->updateById($table, $in, $object->getId());
|
$this->mysql->updateById($table, $in, $object->getId());
|
||||||
@@ -79,7 +79,7 @@ abstract class AbstractMysqlRepository extends AbstractRepository implements Mys
|
|||||||
$in = array_map(function ($value){
|
$in = array_map(function ($value){
|
||||||
return (is_string($value)) ? $this->mysql->escapeStr($value) : $value;
|
return (is_string($value)) ? $this->mysql->escapeStr($value) : $value;
|
||||||
}, $data);
|
}, $data);
|
||||||
if($this->getDebug()) {$this->debug($data, $in, $table, $this->getRepositoryStack()); exit;}
|
if($this->isDebug()) {$this->debug($data, $in, $table, ...$this->getDebugExtraData()); exit;}
|
||||||
try {
|
try {
|
||||||
if (!empty($data[$primaryKey]) && !empty($this->mysql->findById($table, $data[$primaryKey], $primaryKey))) {
|
if (!empty($data[$primaryKey]) && !empty($this->mysql->findById($table, $data[$primaryKey], $primaryKey))) {
|
||||||
$this->mysql->updateById($table, $in, $data[$primaryKey]);
|
$this->mysql->updateById($table, $in, $data[$primaryKey]);
|
||||||
@@ -181,12 +181,19 @@ abstract class AbstractMysqlRepository extends AbstractRepository implements Mys
|
|||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private function getDebug(): bool {
|
private function isDebug(): bool {
|
||||||
if(!empty($this->debug)) return $this->debug;
|
if(!empty($this->debug)) return $this->debug;
|
||||||
if(!empty(static::DEBUG)) return static::DEBUG;
|
if(!empty(static::DEBUG)) return static::DEBUG;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function getDebugExtraData() : array {
|
||||||
|
return [$this->getRepositoryStack(), $this->getClassesCache(), $this->getAttributesObjectsCache()];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ...$arg
|
* @param ...$arg
|
||||||
* @return void
|
* @return void
|
||||||
|
|||||||
14
src/Attribute/Entity.php
Normal file
14
src/Attribute/Entity.php
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Rmphp\Storage\Attribute;
|
||||||
|
|
||||||
|
use Attribute;
|
||||||
|
|
||||||
|
#[Attribute(Attribute::TARGET_CLASS)]
|
||||||
|
class Entity {
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
public bool $withoutEmpty = false,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
}
|
||||||
16
src/Attribute/GetProperty.php
Normal file
16
src/Attribute/GetProperty.php
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Rmphp\Storage\Attribute;
|
||||||
|
|
||||||
|
use Attribute;
|
||||||
|
|
||||||
|
#[Attribute(Attribute::TARGET_PROPERTY)]
|
||||||
|
class GetProperty {
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
public ?string $keyName = null,
|
||||||
|
public bool $empty = false,
|
||||||
|
public bool $emptyIfNull = false,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
}
|
||||||
8
src/Attribute/GetPropertyEmpty.php
Normal file
8
src/Attribute/GetPropertyEmpty.php
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Rmphp\Storage\Attribute;
|
||||||
|
|
||||||
|
use Attribute;
|
||||||
|
|
||||||
|
#[Attribute(Attribute::TARGET_PROPERTY)]
|
||||||
|
class GetPropertyEmpty {}
|
||||||
8
src/Attribute/GetPropertyEmptyIfNull.php
Normal file
8
src/Attribute/GetPropertyEmptyIfNull.php
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Rmphp\Storage\Attribute;
|
||||||
|
|
||||||
|
use Attribute;
|
||||||
|
|
||||||
|
#[Attribute(Attribute::TARGET_PROPERTY)]
|
||||||
|
class GetPropertyEmptyIfNull {}
|
||||||
14
src/Attribute/ValueObject.php
Normal file
14
src/Attribute/ValueObject.php
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Rmphp\Storage\Attribute;
|
||||||
|
|
||||||
|
use Attribute;
|
||||||
|
|
||||||
|
#[Attribute(Attribute::TARGET_CLASS)]
|
||||||
|
class ValueObject {
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
public ?string $propertyName = null,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -5,26 +5,38 @@ namespace Rmphp\Storage\Component;
|
|||||||
use Exception;
|
use Exception;
|
||||||
use ReflectionClass;
|
use ReflectionClass;
|
||||||
use ReflectionException;
|
use ReflectionException;
|
||||||
|
use Rmphp\Storage\Attribute\Entity;
|
||||||
|
|
||||||
class AbstractDataObject {
|
abstract class AbstractDataObject {
|
||||||
|
|
||||||
private static array $constructorEmptyAvailableClasses = [];
|
|
||||||
private static array $stack = [];
|
private static array $stack = [];
|
||||||
|
protected static array $constructorEmptyAvailableClasses = [];
|
||||||
|
protected static array $classes = [];
|
||||||
|
protected static array $attributeObjects = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ReflectionClass $class
|
* @param ReflectionClass $class
|
||||||
* @param object $object
|
* @param object $object
|
||||||
* @param array $data
|
* @param array $data
|
||||||
* @param bool $update
|
* @param bool $update
|
||||||
* @param bool $withNull
|
* @param bool $withEmpty
|
||||||
* @return mixed
|
* @return mixed
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
protected static function fillObject(ReflectionClass $class, object $object, array $data, bool $update = false, bool $withNull = true) : mixed {
|
protected static function fillObject(ReflectionClass $class, object $object, array $data, bool $update = false, bool $withEmpty = true) : mixed {
|
||||||
try {
|
try {
|
||||||
|
if(!isset(self::$attributeObjects[$class->getName()][0])){
|
||||||
|
self::$attributeObjects[$class->getName()][0] = !empty($class->getAttributes(Entity::class))
|
||||||
|
? $class->getAttributes(Entity::class)[0]->newInstance()
|
||||||
|
: new Entity();
|
||||||
|
}
|
||||||
|
/** @var Entity $entityAttributes */
|
||||||
|
$entityAttributes = self::$attributeObjects[$class->getName()][0];
|
||||||
|
|
||||||
$value = [];
|
$value = [];
|
||||||
foreach($class->getProperties() as $property){
|
foreach($class->getProperties() as $property){
|
||||||
$prop[$property->getName()] = ($property->hasType()) ? $property->getType()->getName() : "";
|
$prop[$property->getName()] = ($property->hasType()) ? $property->getType()->getName() : "";
|
||||||
|
|
||||||
// значение в массиве по ключю с именем свойства
|
// значение в массиве по ключю с именем свойства
|
||||||
if(array_key_exists($property->getName(), $data)){
|
if(array_key_exists($property->getName(), $data)){
|
||||||
$value[$property->getName()] = $data[$property->getName()];
|
$value[$property->getName()] = $data[$property->getName()];
|
||||||
@@ -40,44 +52,58 @@ class AbstractDataObject {
|
|||||||
// если есть внутренний метод (приоритетная обработка)
|
// если есть внутренний метод (приоритетная обработка)
|
||||||
if($class->hasMethod('set'.ucfirst($property->getName()))) {
|
if($class->hasMethod('set'.ucfirst($property->getName()))) {
|
||||||
$object->{'set'.ucfirst($property->getName())}($value[$property->getName()] ?? null);
|
$object->{'set'.ucfirst($property->getName())}($value[$property->getName()] ?? null);
|
||||||
|
$case[$property->getName()] = 'Method set'.ucfirst($property->getName());
|
||||||
}
|
}
|
||||||
// Если тип свойства класс (valueObject)
|
// Если тип свойства класс (valueObject)
|
||||||
elseif($property->hasType() && class_exists($property->getType()->getName())) {
|
elseif($property->hasType() && class_exists($property->getType()->getName())) {
|
||||||
|
// значение объект
|
||||||
if(is_object($value[$property->getName()])){
|
if(is_object($value[$property->getName()])){
|
||||||
$object->{$property->getName()} = $value[$property->getName()];
|
$object->{$property->getName()} = $value[$property->getName()];
|
||||||
|
$case[$property->getName()] = 'VO: Object';
|
||||||
}
|
}
|
||||||
|
// значение есть и не пустое
|
||||||
elseif(isset($value[$property->getName()]) && $value[$property->getName()] !== ""){
|
elseif(isset($value[$property->getName()]) && $value[$property->getName()] !== ""){
|
||||||
$object->{$property->getName()} = new ($property->getType()->getName())($value[$property->getName()]);
|
$object->{$property->getName()} = new ($property->getType()->getName())($value[$property->getName()]);
|
||||||
|
$case[$property->getName()] = 'VO: NewInstance';
|
||||||
}
|
}
|
||||||
elseif($withNull && isset($value[$property->getName()])){
|
elseif(($withEmpty && empty($entityAttributes->withoutEmpty)) && array_key_exists($property->getName(), $value)){
|
||||||
$object->{$property->getName()} = new ($property->getType()->getName())($value[$property->getName()]);
|
$object->{$property->getName()} = new ($property->getType()->getName())($value[$property->getName()]);
|
||||||
|
$case[$property->getName()] = 'VO: NewInstance withEmpty';
|
||||||
}
|
}
|
||||||
// Значения нет и VO может быть без параметров
|
// Значения нет и VO может быть без параметров
|
||||||
elseif($withNull && self::isEmptyAvailable($property->getType()->getName())) {
|
elseif(($withEmpty && empty($entityAttributes->withoutEmpty)) && self::isEmptyAvailable($property->getType()->getName())) {
|
||||||
$object->{$property->getName()} = new ($property->getType()->getName())();
|
$object->{$property->getName()} = new ($property->getType()->getName())();
|
||||||
|
$case[$property->getName()] = 'VO: Without params';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
// Базовые типы при наличии значения
|
// Базовые типы при наличии значения
|
||||||
elseif(array_key_exists($property->getName(), $value)){
|
elseif(array_key_exists($property->getName(), $value)){
|
||||||
if(!$property->hasType()){
|
if(!$property->hasType()){
|
||||||
$object->{$property->getName()} = $value[$property->getName()];
|
$object->{$property->getName()} = $value[$property->getName()];
|
||||||
|
$case[$property->getName()] = 'Base: Hasn`t type';
|
||||||
}
|
}
|
||||||
elseif(in_array($property->getType()->getName(), ['float', 'int'])){
|
elseif(in_array($property->getType()->getName(), ['float', 'int'])){
|
||||||
if(is_numeric($value[$property->getName()])) $object->{$property->getName()} = $value[$property->getName()];
|
if(is_numeric($value[$property->getName()])) $object->{$property->getName()} = $value[$property->getName()];
|
||||||
|
$case[$property->getName()] = 'Base: Number';
|
||||||
}
|
}
|
||||||
elseif($property->getType()->getName() == 'bool'){
|
elseif($property->getType()->getName() == 'bool'){
|
||||||
$object->{$property->getName()} = (bool)$value[$property->getName()];
|
$object->{$property->getName()} = (bool)$value[$property->getName()];
|
||||||
|
$case[$property->getName()] = 'Base: Boolean';
|
||||||
}
|
}
|
||||||
elseif(isset($value[$property->getName()]) && $value[$property->getName()] !== ""){
|
elseif(isset($value[$property->getName()])){
|
||||||
$object->{$property->getName()} = $value[$property->getName()];
|
$object->{$property->getName()} = $value[$property->getName()];
|
||||||
|
$case[$property->getName()] = 'Base: NotNull';
|
||||||
}
|
}
|
||||||
elseif($withNull && isset($value[$property->getName()])){
|
elseif($property->getType()->allowsNull()){
|
||||||
$object->{$property->getName()} = $value[$property->getName()];
|
$object->{$property->getName()} = $value[$property->getName()];
|
||||||
|
$case[$property->getName()] = 'Base: Null';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self::$stack[$object::class." #".spl_object_id($object)]['properties'] = $prop ?? [];
|
self::$stack[$object::class." #".spl_object_id($object)]['properties'] = $prop ?? [];
|
||||||
self::$stack[$object::class." #".spl_object_id($object)]['values'] = $value;
|
self::$stack[$object::class." #".spl_object_id($object)]['values'] = $value;
|
||||||
|
self::$stack[$object::class." #".spl_object_id($object)]['matchCase'] = $case ?? [];
|
||||||
self::$stack[$object::class." #".spl_object_id($object)]['object'] = $object;
|
self::$stack[$object::class." #".spl_object_id($object)]['object'] = $object;
|
||||||
return $object;
|
return $object;
|
||||||
}
|
}
|
||||||
@@ -101,7 +127,6 @@ class AbstractDataObject {
|
|||||||
return self::$constructorEmptyAvailableClasses[$class] = true;
|
return self::$constructorEmptyAvailableClasses[$class] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -4,31 +4,71 @@ namespace Rmphp\Storage\Repository;
|
|||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use ReflectionClass;
|
use ReflectionClass;
|
||||||
use ReflectionException;
|
use Rmphp\Storage\Attribute\Entity;
|
||||||
|
use Rmphp\Storage\Attribute\GetProperty;
|
||||||
|
use Rmphp\Storage\Attribute\GetPropertyEmpty;
|
||||||
|
use Rmphp\Storage\Attribute\GetPropertyEmptyIfNull;
|
||||||
|
use Rmphp\Storage\Attribute\ValueObject;
|
||||||
use Rmphp\Storage\Component\AbstractDataObject;
|
use Rmphp\Storage\Component\AbstractDataObject;
|
||||||
use Rmphp\Storage\Entity\ValueObjectInterface;
|
use Rmphp\Storage\Entity\ValueObjectInterface;
|
||||||
use Rmphp\Storage\Exception\RepositoryException;
|
use Rmphp\Storage\Exception\RepositoryException;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
abstract class AbstractRepository extends AbstractDataObject implements RepositoryInterface {
|
abstract class AbstractRepository extends AbstractDataObject implements RepositoryInterface {
|
||||||
|
|
||||||
private static array $classes = [];
|
|
||||||
|
|
||||||
/** @inheritDoc */
|
/** @inheritDoc */
|
||||||
public function getProperties(object $object, callable $method = null) : array {
|
public function getProperties(object $object, callable $method = null) : array {
|
||||||
try{
|
try{
|
||||||
$class = get_class($object);
|
$class = get_class($object);
|
||||||
if(!isset(self::$classes[$class])) self::$classes[$class] = new ReflectionClass($class);
|
if(!isset(self::$classes[$class])) self::$classes[$class] = new ReflectionClass($class);
|
||||||
|
|
||||||
|
if(!isset(self::$attributeObjects[$class][0])){
|
||||||
|
self::$attributeObjects[$class][0] = !empty(self::$classes[$class]->getAttributes(Entity::class))
|
||||||
|
? self::$classes[$class]->getAttributes(Entity::class)[0]->newInstance()
|
||||||
|
: new Entity();
|
||||||
|
}
|
||||||
|
/** @var Entity $entityAttributes */
|
||||||
|
$entityAttributes = self::$attributeObjects[$class][0];
|
||||||
|
|
||||||
$fieldValue = [];
|
$fieldValue = [];
|
||||||
foreach(self::$classes[$class]->getProperties() as $property){
|
foreach(self::$classes[$class]->getProperties() as $property){
|
||||||
if(!$property->isInitialized($object) || is_array($property->getValue($object))) continue;
|
|
||||||
|
if(!isset(self::$attributeObjects[$class][$property->getName()])){
|
||||||
|
self::$attributeObjects[$class][$property->getName()] = !empty($property->getAttributes(GetProperty::class))
|
||||||
|
? $property->getAttributes(GetProperty::class)[0]->newInstance()
|
||||||
|
: new GetProperty();
|
||||||
|
}
|
||||||
|
/** @var GetProperty $getPropertyAttributes */
|
||||||
|
$getPropertyAttributes = self::$attributeObjects[$class][$property->getName()];
|
||||||
|
|
||||||
|
if(!empty($property->getAttributes(GetPropertyEmpty::class)) || !empty($getPropertyAttributes->empty)) continue;
|
||||||
|
|
||||||
|
if($property->isInitialized($object)) {
|
||||||
|
|
||||||
|
if(is_array($property->getValue($object))) continue;
|
||||||
|
|
||||||
if(self::$classes[$class]->hasMethod('get'.ucfirst($property->getName()))){
|
if(self::$classes[$class]->hasMethod('get'.ucfirst($property->getName()))){
|
||||||
$fieldValue[$property->getName()] = $object->{'get'.ucfirst($property->getName())}($property->getValue($object));
|
$fieldValue[$property->getName()] = $object->{'get'.ucfirst($property->getName())}($property->getValue($object));
|
||||||
}
|
}
|
||||||
elseif($property->hasType() && class_exists($property->getType()->getName()) && $property->getValue($object) instanceof ValueObjectInterface){
|
elseif($property->hasType() && class_exists($property->getType()->getName()) && $property->getValue($object) instanceof ValueObjectInterface){
|
||||||
|
|
||||||
|
$valueObjectClass = get_class($property->getValue($object));
|
||||||
|
if(!isset(self::$classes[$valueObjectClass])) self::$classes[$valueObjectClass] = new ReflectionClass($valueObjectClass);
|
||||||
|
|
||||||
|
if(!isset(self::$attributeObjects[$valueObjectClass])){
|
||||||
|
self::$attributeObjects[$valueObjectClass] = !empty(self::$classes[$valueObjectClass]->getAttributes(ValueObject::class))
|
||||||
|
? self::$classes[$valueObjectClass]->getAttributes(ValueObject::class)[0]->newInstance()
|
||||||
|
: new ValueObject();
|
||||||
|
}
|
||||||
|
$valueObjectAttributes = self::$attributeObjects[$valueObjectClass];
|
||||||
|
|
||||||
|
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));
|
||||||
|
} else{
|
||||||
$fieldValue[$property->getName()] = $property->getValue($object)->getValue();
|
$fieldValue[$property->getName()] = $property->getValue($object)->getValue();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
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);
|
||||||
}
|
}
|
||||||
@@ -36,13 +76,21 @@ abstract class AbstractRepository extends AbstractDataObject implements Reposito
|
|||||||
$fieldValue[$property->getName()] = $property->getValue($object);
|
$fieldValue[$property->getName()] = $property->getValue($object);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(
|
||||||
|
!isset($fieldValue[$property->getName()])
|
||||||
|
&& (!empty($property->getAttributes(GetPropertyEmptyIfNull::class)) || !empty($getPropertyAttributes->emptyIfNull) || !empty($entityAttributes->withoutNull))
|
||||||
|
) continue;
|
||||||
|
|
||||||
if(array_key_exists($property->getName(), $fieldValue) && 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()];
|
$columnName = !empty($getPropertyAttributes->keyName) ? $getPropertyAttributes->keyName : strtolower(preg_replace("'([A-Z])'", "_$1", $property->getName()));
|
||||||
|
$out[$columnName] = $fieldValue[$property->getName()];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
//dd($this->getAttributesObjectsCache());
|
||||||
return (isset($method)) ? array_map($method, $out ?? []) : $out ?? [];
|
return (isset($method)) ? array_map($method, $out ?? []) : $out ?? [];
|
||||||
}
|
}
|
||||||
catch (ReflectionException $exception) {
|
catch (\ReflectionException $exception) {
|
||||||
throw new RepositoryException($exception->getMessage());
|
throw new RepositoryException($exception->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -52,10 +100,10 @@ abstract class AbstractRepository extends AbstractDataObject implements Reposito
|
|||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
* @throws RepositoryException
|
* @throws RepositoryException
|
||||||
*/
|
*/
|
||||||
public function createFromData(string $class, array|object $data, bool $withNull = true) : object {
|
public function createFromData(string $class, array|object $data, bool $withEmpty = true) : object {
|
||||||
try {
|
try {
|
||||||
if(!isset(self::$classes[$class])) self::$classes[$class] = new ReflectionClass($class);
|
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, $withNull);
|
return self::fillObject(self::$classes[$class], new $class, (is_object($data)) ? get_object_vars($data) : $data, false, $withEmpty);
|
||||||
}
|
}
|
||||||
catch (Exception $exception) {
|
catch (Exception $exception) {
|
||||||
throw new RepositoryException($exception->getMessage());
|
throw new RepositoryException($exception->getMessage());
|
||||||
@@ -67,11 +115,11 @@ abstract class AbstractRepository extends AbstractDataObject implements Reposito
|
|||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
* @throws RepositoryException
|
* @throws RepositoryException
|
||||||
*/
|
*/
|
||||||
public function updateFromData(object $object, array|object $data, bool $withNull = true) : object {
|
public function updateFromData(object $object, array|object $data, bool $withEmpty = true) : object {
|
||||||
try {
|
try {
|
||||||
$class = get_class($object);
|
$class = get_class($object);
|
||||||
if(!isset(self::$classes[$class])) self::$classes[$class] = new ReflectionClass($class);
|
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, $withNull);
|
return self::fillObject(self::$classes[$class], clone $object, (is_object($data)) ? get_object_vars($data) : $data, true, $withEmpty);
|
||||||
}
|
}
|
||||||
catch (Exception $exception) {
|
catch (Exception $exception) {
|
||||||
throw new RepositoryException($exception->getMessage());
|
throw new RepositoryException($exception->getMessage());
|
||||||
@@ -88,8 +136,22 @@ abstract class AbstractRepository extends AbstractDataObject implements Reposito
|
|||||||
/**
|
/**
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getClassesCash() : array {
|
public function getClassesCache() : array {
|
||||||
return self::$classes;
|
return self::$classes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getAttributesObjectsCache() : array {
|
||||||
|
return self::$attributeObjects;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getConstructorEmptyAvailableClassesCache() : array {
|
||||||
|
return self::$constructorEmptyAvailableClasses;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,19 +25,19 @@ interface RepositoryInterface {
|
|||||||
/**
|
/**
|
||||||
* @param string $class
|
* @param string $class
|
||||||
* @param array|object $data
|
* @param array|object $data
|
||||||
* @param bool $withNull
|
* @param bool $withEmpty
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function createFromData(string $class, array|object $data, bool $withNull = true) : mixed;
|
public function createFromData(string $class, array|object $data, bool $withEmpty = true) : mixed;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param object $object
|
* @param object $object
|
||||||
* @param array|object $data
|
* @param array|object $data
|
||||||
* @param bool $withNull
|
* @param bool $withEmpty
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function updateFromData(object $object, array|object $data, bool $withNull = true) : mixed;
|
public function updateFromData(object $object, array|object $data, bool $withEmpty = true) : mixed;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user