- Fixed a bug caused by the addition of Attributes (on Ignore tags) and ajusted the EntityTrait with it
This commit is contained in:
parent
d4a9fc8463
commit
c9c6a11ebd
|
@ -76,7 +76,7 @@ class EntityResolver {
|
|||
public function fieldList($fieldKey = self::KEY_ENTITY_NAME, bool $skipVirtual = false) : array
|
||||
{
|
||||
$fieldList = [];
|
||||
|
||||
|
||||
foreach($this->properties as $item) {
|
||||
foreach($item['tags'] ?? [] as $tag) {
|
||||
if ( $tag['object'] instanceof Field or $tag['object'] instanceof Attribute\Property\Field ) {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Ulmus;
|
||||
|
||||
use Notes\Attribute\Ignore;
|
||||
use Ulmus\{ Repository, Query, Common\EntityResolver, Common\EntityField };
|
||||
use Ulmus\Annotation\Classes\{ Method, Table, Collation, };
|
||||
use Ulmus\Annotation\Property\{ Field, Filter, FilterJoin, Relation, OrderBy, Where, OrWhere, Join, Virtual, On, WithJoin, };
|
||||
|
@ -11,28 +12,21 @@ use Ulmus\Annotation\Property\Relation\{ Ignore as RelationIgnore };
|
|||
trait EntityTrait {
|
||||
use EventTrait;
|
||||
|
||||
/**
|
||||
* @Ignore
|
||||
*/
|
||||
#[Ignore]
|
||||
protected bool $entityStrictFieldsDeclaration = false;
|
||||
|
||||
/**
|
||||
* @Ignore
|
||||
*/
|
||||
#[Ignore]
|
||||
protected array $entityDatasetUnmatchedFields = [];
|
||||
|
||||
/**
|
||||
* @Ignore
|
||||
*/
|
||||
#[Ignore]
|
||||
public array $entityLoadedDataset = [];
|
||||
|
||||
#[Ignore]
|
||||
public function __construct() {
|
||||
$this->resetVirtualProperties();
|
||||
}
|
||||
|
||||
/**entityLoadedDataset
|
||||
* @Ignore
|
||||
*/
|
||||
#[Ignore]
|
||||
public function entityFillFromDataset(iterable $dataset, bool $overwriteDataset = false) : self
|
||||
{
|
||||
$loaded = $this->isLoaded();
|
||||
|
@ -110,6 +104,7 @@ trait EntityTrait {
|
|||
return $this;
|
||||
}
|
||||
|
||||
#[Ignore]
|
||||
public function resetVirtualProperties() : self
|
||||
{
|
||||
foreach($this->resolveEntity()->properties as $prop => $property) {
|
||||
|
@ -125,6 +120,7 @@ trait EntityTrait {
|
|||
return $this;
|
||||
}
|
||||
|
||||
#[Ignore]
|
||||
public function fromArray(iterable $dataset) : self
|
||||
{
|
||||
return $this->entityFillFromDataset($dataset);
|
||||
|
@ -178,6 +174,7 @@ trait EntityTrait {
|
|||
return $dataset;
|
||||
}
|
||||
|
||||
#[Ignore]
|
||||
public function toArray($includeRelations = false, array $filterFields = null) : array
|
||||
{
|
||||
$dataset = $this->entityGetDataset($includeRelations);
|
||||
|
@ -185,11 +182,13 @@ trait EntityTrait {
|
|||
return $filterFields ? array_intersect_key($dataset, array_flip($filterFields)) : $dataset;
|
||||
}
|
||||
|
||||
#[Ignore]
|
||||
public function toCollection() : EntityCollection
|
||||
{
|
||||
return static::entityCollection([ $this ]);
|
||||
}
|
||||
|
||||
#[Ignore]
|
||||
public function isLoaded() : bool
|
||||
{
|
||||
if (empty($this->entityLoadedDataset)) {
|
||||
|
@ -205,6 +204,7 @@ trait EntityTrait {
|
|||
return isset($this->$key);
|
||||
}
|
||||
|
||||
#[Ignore]
|
||||
public function __get(string $name)
|
||||
{
|
||||
$relation = new Repository\RelationBuilder($this);
|
||||
|
@ -216,6 +216,7 @@ trait EntityTrait {
|
|||
throw new \Exception(sprintf("[%s] - Undefined variable: %s", static::class, $name));
|
||||
}
|
||||
|
||||
#[Ignore]
|
||||
public function __isset(string $name) : bool
|
||||
{
|
||||
#if ( null !== $relation = static::resolveEntity()->searchFieldAnnotation($name, new Relation() ) ) {
|
||||
|
@ -230,16 +231,19 @@ trait EntityTrait {
|
|||
return isset($this->$name);
|
||||
}
|
||||
|
||||
#[Ignore]
|
||||
public function __sleep()
|
||||
{
|
||||
return array_merge(array_keys($this->resolveEntity()->fieldList()), [ 'entityLoadedDataset' ] );
|
||||
}
|
||||
|
||||
#[Ignore]
|
||||
public function __wakeup()
|
||||
{
|
||||
$this->resetVirtualProperties();
|
||||
}
|
||||
|
||||
#[Ignore]
|
||||
public function __clone()
|
||||
{
|
||||
foreach($this as $prop) {
|
||||
|
@ -253,21 +257,25 @@ trait EntityTrait {
|
|||
}
|
||||
}
|
||||
|
||||
#[Ignore]
|
||||
public function jsonSerialize() : mixed
|
||||
{
|
||||
return $this->entityGetDataset();
|
||||
}
|
||||
|
||||
#[Ignore]
|
||||
public static function resolveEntity() : EntityResolver
|
||||
{
|
||||
return Ulmus::resolveEntity(static::class);
|
||||
}
|
||||
|
||||
#[Ignore]
|
||||
public static function repository(string $alias = Repository::DEFAULT_ALIAS, ConnectionAdapter $adapter = null) : Repository
|
||||
{
|
||||
return Ulmus::repository(static::class, $alias, $adapter);
|
||||
}
|
||||
|
||||
#[Ignore]
|
||||
public static function entityCollection(...$arguments) : EntityCollection
|
||||
{
|
||||
$collection = new EntityCollection(...$arguments);
|
||||
|
@ -276,16 +284,19 @@ trait EntityTrait {
|
|||
return $collection;
|
||||
}
|
||||
|
||||
#[Ignore]
|
||||
public static function queryBuilder() : QueryBuilder
|
||||
{
|
||||
return Ulmus::queryBuilder(static::class);
|
||||
}
|
||||
|
||||
#[Ignore]
|
||||
public static function field($name, ? string $alias = Repository::DEFAULT_ALIAS) : EntityField
|
||||
{
|
||||
return new EntityField(static::class, $name, $alias ? Ulmus::repository(static::class)->adapter->adapter()->escapeIdentifier($alias, Adapter\AdapterInterface::IDENTIFIER_FIELD) : Repository::DEFAULT_ALIAS, Ulmus::resolveEntity(static::class));
|
||||
}
|
||||
|
||||
#[Ignore]
|
||||
public static function fields(array $fields, ? string $alias = Repository::DEFAULT_ALIAS) : string
|
||||
{
|
||||
return implode(', ', array_map(function($item) use ($alias){
|
||||
|
|
Loading…
Reference in New Issue