- ArrayOf errors now catched in EntityTrait (event soon to be attached to it)
- Fixed some non-nullable defaulted to null vars in functions - Added a new diff method for entities which skips nullable values if they are not defined.
This commit is contained in:
1 parent
709ed63323
commit
13b7cf06f1
9 files changed
+52
-26
No files matched your search
+31
-10
@@ -4,20 +4,15 @@ namespace Ulmus;
|
||||
|
||||
use Notes\Attribute\Ignore;
|
||||
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
|
||||
use Ulmus\{Attribute\Obj\JsonSerialize,
|
||||
Attribute\Property\Join,
|
||||
Attribute\Property\Relation,
|
||||
Attribute\Property\ResettablePropertyInterface,
|
||||
Attribute\Property\Virtual,
|
||||
Common\EntityResolver,
|
||||
Common\EntityField,
|
||||
Entity\DatasetHandler,
|
||||
Entity\EntityInterface,
|
||||
QueryBuilder\QueryBuilderInterface};
|
||||
|
||||
use Ulmus\{Attribute\RegisterEntityEventInterface, Entity\EntityValueModifier, SearchRequest, Event};
|
||||
use Ulmus\{Attribute\RegisterEntityEventInterface, Entity\EntityValueModifier, };
|
||||
|
||||
#[JsonSerialize(includeRelations: true)]
|
||||
trait EntityTrait {
|
||||
@@ -33,7 +28,7 @@ trait EntityTrait {
|
||||
protected array $entityDatasetUnmatchedFields = [];
|
||||
|
||||
#[Ignore]
|
||||
protected DatasetHandler $datasetHandler;
|
||||
public DatasetHandler $datasetHandler;
|
||||
|
||||
#[Ignore]
|
||||
public string $loadedFromAdapter;
|
||||
@@ -82,7 +77,16 @@ trait EntityTrait {
|
||||
foreach($generator as $field => $value) {
|
||||
foreach($properties[$field]->attributes as $tag) {
|
||||
if ( $tag->object instanceof EntityValueModifier ) {
|
||||
$value = $tag->object->push($value, $properties[$field]);
|
||||
try {
|
||||
$value = $tag->object->push($value, $properties[$field]);
|
||||
}
|
||||
catch(\Throwable $ex) {
|
||||
throw new \LogicException(
|
||||
message: sprintf("An error occured trying to push an EntityValueModifier results : %s", $ex->getMessage()),
|
||||
code: $ex->getCode(),
|
||||
previous: $ex,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,6 +132,18 @@ trait EntityTrait {
|
||||
}
|
||||
}
|
||||
|
||||
#[Ignore]
|
||||
public function entityGetDiffDataset() : array
|
||||
{
|
||||
$return = [];
|
||||
|
||||
foreach($this->datasetHandler->pull($this, false) as $field => $value) {
|
||||
$return[$field] = static::repository()->adapter->adapter()->writableValue($value);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
#[Ignore]
|
||||
public function resetVirtualProperties() : self
|
||||
{
|
||||
@@ -217,7 +233,12 @@ trait EntityTrait {
|
||||
return true;
|
||||
}
|
||||
|
||||
return isset($this->$name);
|
||||
if (isset($this->$name)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
# Handling undefined 'nullable'
|
||||
return new \ReflectionProperty($this, $name)->isInitialized($this);
|
||||
}
|
||||
|
||||
#[Ignore]
|
||||
@@ -289,7 +310,7 @@ trait EntityTrait {
|
||||
}
|
||||
|
||||
#[Ignore]
|
||||
public static function repository(string $alias = Repository::DEFAULT_ALIAS, ConnectionAdapter $adapter = null) : Repository
|
||||
public static function repository(string $alias = Repository::DEFAULT_ALIAS, ?ConnectionAdapter $adapter = null) : Repository
|
||||
{
|
||||
return Ulmus::repository(static::class, $alias, $adapter);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user