- Added support for Ignore attribute in dataset export of EntityTrait
- Work done on JSONification of entity
This commit is contained in:
1 parent
7f8780d328
commit
3a80fee9c3
5 files changed
+60
-22
No files matched your search
+32
-18
@@ -168,24 +168,41 @@ trait EntityTrait {
|
||||
}
|
||||
}
|
||||
|
||||
# @TODO Must fix recursive bug !
|
||||
if ($includeRelations) {
|
||||
foreach($entityResolver->properties as $name => $field){
|
||||
$relation = $entityResolver->searchFieldAnnotation($name, [ Attribute\Property\Relation::class, Relation::class ] );
|
||||
$relation = $entityResolver->searchFieldAnnotation($name, [ Attribute\Property\Relation::class ] );
|
||||
|
||||
if ( $relation && isset($this->$name) && ($relation->entity ?? $relation->bridge) !== static::class ) {
|
||||
if ( null !== $value = $this->$name ?? null ) {
|
||||
if ( is_iterable($value) ) {
|
||||
$list = [];
|
||||
if ($relation) {
|
||||
$ignore = $entityResolver->searchFieldAnnotation($name, [ Attribute\Property\Relation\Ignore::class ] );
|
||||
|
||||
foreach($value as $entity) {
|
||||
$list[] = $entity->entityGetDataset(false);
|
||||
}
|
||||
|
||||
$dataset[$name] = $list;
|
||||
if ($ignore && $ignore->ignoreExport) {
|
||||
if ( $relation->isOneToOne() ) {
|
||||
# empty object
|
||||
$dataset[$name] = ( new \ReflectionClass($field['type']) )->newInstanceWithoutConstructor();
|
||||
}
|
||||
elseif ( is_object($value) ) {
|
||||
$dataset[$name] = $value->entityGetDataset(false);
|
||||
else {
|
||||
# empty collection
|
||||
$dataset[$name] = [];
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
# @TODO Must fix recursive bug.. this last check is way too basic to work
|
||||
if ( isset($this->$name) && ($relation->entity ?? $relation->bridge) !== static::class ) {
|
||||
if ( null !== $value = $this->$name ?? null ) {
|
||||
if ( is_iterable($value) ) {
|
||||
$list = [];
|
||||
|
||||
foreach($value as $entity) {
|
||||
$list[] = $entity->entityGetDataset(false);
|
||||
}
|
||||
|
||||
$dataset[$name] = $list;
|
||||
}
|
||||
elseif ( is_object($value) ) {
|
||||
$dataset[$name] = $value->entityGetDataset(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -240,10 +257,7 @@ trait EntityTrait {
|
||||
#[Ignore]
|
||||
public function __isset(string $name) : bool
|
||||
{
|
||||
#if ( null !== $relation = static::resolveEntity()->searchFieldAnnotation($name, new Relation() ) ) {
|
||||
# return isset($this->{$relation->key});
|
||||
#}
|
||||
$rel = static::resolveEntity()->searchFieldAnnotation($name, [ Attribute\Property\Relation::class, Relation::class ]);
|
||||
$rel = static::resolveEntity()->searchFieldAnnotation($name, [ Attribute\Property\Relation::class ]);
|
||||
|
||||
if ( $this->isLoaded() && $rel ) {
|
||||
return true;
|
||||
@@ -327,7 +341,7 @@ trait EntityTrait {
|
||||
#[Ignore]
|
||||
public static function searchRequest(...$arguments) : SearchRequestInterface
|
||||
{
|
||||
return new class() implements SearchRequestInterface
|
||||
return new class() implements SearchRequestInterface, \JsonSerializable
|
||||
{
|
||||
use SearchRequestPaginationTrait;
|
||||
|
||||
|
||||
Reference in new issue
Block a user