- 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
					
				@ -2,6 +2,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace Ulmus;
 | 
					namespace Ulmus;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use Notes\Attribute\Ignore;
 | 
				
			||||||
use Ulmus\{ Repository, Query, Common\EntityResolver, Common\EntityField };
 | 
					use Ulmus\{ Repository, Query, Common\EntityResolver, Common\EntityField };
 | 
				
			||||||
use Ulmus\Annotation\Classes\{ Method, Table, Collation, };
 | 
					use Ulmus\Annotation\Classes\{ Method, Table, Collation, };
 | 
				
			||||||
use Ulmus\Annotation\Property\{ Field, Filter, FilterJoin, Relation, OrderBy, Where, OrWhere, Join, Virtual, On, WithJoin, };
 | 
					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 {
 | 
					trait EntityTrait {
 | 
				
			||||||
    use EventTrait;
 | 
					    use EventTrait;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    #[Ignore]
 | 
				
			||||||
     * @Ignore
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    protected bool $entityStrictFieldsDeclaration = false;
 | 
					    protected bool $entityStrictFieldsDeclaration = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    #[Ignore]
 | 
				
			||||||
     * @Ignore
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    protected array $entityDatasetUnmatchedFields = [];
 | 
					    protected array $entityDatasetUnmatchedFields = [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    #[Ignore]
 | 
				
			||||||
     * @Ignore
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    public array $entityLoadedDataset = [];
 | 
					    public array $entityLoadedDataset = [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #[Ignore]
 | 
				
			||||||
    public function __construct() {
 | 
					    public function __construct() {
 | 
				
			||||||
        $this->resetVirtualProperties();
 | 
					        $this->resetVirtualProperties();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**entityLoadedDataset
 | 
					    #[Ignore]
 | 
				
			||||||
     * @Ignore
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    public function entityFillFromDataset(iterable $dataset, bool $overwriteDataset = false) : self
 | 
					    public function entityFillFromDataset(iterable $dataset, bool $overwriteDataset = false) : self
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $loaded = $this->isLoaded();
 | 
					        $loaded = $this->isLoaded();
 | 
				
			||||||
@ -110,6 +104,7 @@ trait EntityTrait {
 | 
				
			|||||||
        return $this;
 | 
					        return $this;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #[Ignore]
 | 
				
			||||||
    public function resetVirtualProperties() : self
 | 
					    public function resetVirtualProperties() : self
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        foreach($this->resolveEntity()->properties as $prop => $property) {
 | 
					        foreach($this->resolveEntity()->properties as $prop => $property) {
 | 
				
			||||||
@ -125,6 +120,7 @@ trait EntityTrait {
 | 
				
			|||||||
        return $this;
 | 
					        return $this;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #[Ignore]
 | 
				
			||||||
    public function fromArray(iterable $dataset) : self
 | 
					    public function fromArray(iterable $dataset) : self
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return $this->entityFillFromDataset($dataset);
 | 
					        return $this->entityFillFromDataset($dataset);
 | 
				
			||||||
@ -178,6 +174,7 @@ trait EntityTrait {
 | 
				
			|||||||
        return $dataset;
 | 
					        return $dataset;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #[Ignore]
 | 
				
			||||||
    public function toArray($includeRelations = false, array $filterFields = null) : array
 | 
					    public function toArray($includeRelations = false, array $filterFields = null) : array
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $dataset = $this->entityGetDataset($includeRelations);
 | 
					        $dataset = $this->entityGetDataset($includeRelations);
 | 
				
			||||||
@ -185,11 +182,13 @@ trait EntityTrait {
 | 
				
			|||||||
        return $filterFields ? array_intersect_key($dataset, array_flip($filterFields)) : $dataset;
 | 
					        return $filterFields ? array_intersect_key($dataset, array_flip($filterFields)) : $dataset;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #[Ignore]
 | 
				
			||||||
    public function toCollection() : EntityCollection
 | 
					    public function toCollection() : EntityCollection
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return static::entityCollection([ $this ]);
 | 
					        return static::entityCollection([ $this ]);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #[Ignore]
 | 
				
			||||||
    public function isLoaded() : bool
 | 
					    public function isLoaded() : bool
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if (empty($this->entityLoadedDataset)) {
 | 
					        if (empty($this->entityLoadedDataset)) {
 | 
				
			||||||
@ -205,6 +204,7 @@ trait EntityTrait {
 | 
				
			|||||||
        return isset($this->$key);
 | 
					        return isset($this->$key);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #[Ignore]
 | 
				
			||||||
    public function __get(string $name)
 | 
					    public function __get(string $name)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $relation = new Repository\RelationBuilder($this);
 | 
					        $relation = new Repository\RelationBuilder($this);
 | 
				
			||||||
@ -216,6 +216,7 @@ trait EntityTrait {
 | 
				
			|||||||
        throw new \Exception(sprintf("[%s] - Undefined variable: %s", static::class, $name));
 | 
					        throw new \Exception(sprintf("[%s] - Undefined variable: %s", static::class, $name));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #[Ignore]
 | 
				
			||||||
    public function __isset(string $name) : bool
 | 
					    public function __isset(string $name) : bool
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        #if ( null !== $relation = static::resolveEntity()->searchFieldAnnotation($name, new Relation() ) ) {
 | 
					        #if ( null !== $relation = static::resolveEntity()->searchFieldAnnotation($name, new Relation() ) ) {
 | 
				
			||||||
@ -230,16 +231,19 @@ trait EntityTrait {
 | 
				
			|||||||
        return isset($this->$name);
 | 
					        return isset($this->$name);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #[Ignore]
 | 
				
			||||||
    public function __sleep()
 | 
					    public function __sleep()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return array_merge(array_keys($this->resolveEntity()->fieldList()), [ 'entityLoadedDataset' ] );
 | 
					        return array_merge(array_keys($this->resolveEntity()->fieldList()), [ 'entityLoadedDataset' ] );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #[Ignore]
 | 
				
			||||||
    public function __wakeup()
 | 
					    public function __wakeup()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $this->resetVirtualProperties();
 | 
					        $this->resetVirtualProperties();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #[Ignore]
 | 
				
			||||||
    public function __clone()
 | 
					    public function __clone()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        foreach($this as $prop) {
 | 
					        foreach($this as $prop) {
 | 
				
			||||||
@ -253,21 +257,25 @@ trait EntityTrait {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #[Ignore]
 | 
				
			||||||
    public function jsonSerialize() : mixed
 | 
					    public function jsonSerialize() : mixed
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return $this->entityGetDataset();
 | 
					        return $this->entityGetDataset();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #[Ignore]
 | 
				
			||||||
    public static function resolveEntity() : EntityResolver
 | 
					    public static function resolveEntity() : EntityResolver
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return Ulmus::resolveEntity(static::class);
 | 
					        return Ulmus::resolveEntity(static::class);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #[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);
 | 
					        return Ulmus::repository(static::class, $alias, $adapter);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #[Ignore]
 | 
				
			||||||
    public static function entityCollection(...$arguments) : EntityCollection
 | 
					    public static function entityCollection(...$arguments) : EntityCollection
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $collection = new EntityCollection(...$arguments);
 | 
					        $collection = new EntityCollection(...$arguments);
 | 
				
			||||||
@ -276,16 +284,19 @@ trait EntityTrait {
 | 
				
			|||||||
        return $collection;
 | 
					        return $collection;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #[Ignore]
 | 
				
			||||||
    public static function queryBuilder() : QueryBuilder
 | 
					    public static function queryBuilder() : QueryBuilder
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return Ulmus::queryBuilder(static::class);
 | 
					        return Ulmus::queryBuilder(static::class);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #[Ignore]
 | 
				
			||||||
    public static function field($name, ? string $alias = Repository::DEFAULT_ALIAS) : EntityField
 | 
					    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));
 | 
					        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
 | 
					    public static function fields(array $fields, ? string $alias = Repository::DEFAULT_ALIAS) : string
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return implode(', ', array_map(function($item) use ($alias){
 | 
					        return implode(', ', array_map(function($item) use ($alias){
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user