- Had to fix a changed behaviour from PHP 7.4 and 7.4.x where __isset() and __get is not called on initialized properties anymore.
This commit is contained in:
parent
c8397484e6
commit
114fa5be09
|
@ -40,7 +40,6 @@ trait EntityTrait {
|
||||||
|
|
||||||
# @TODO REFACTOR THIS CODE ASAP !
|
# @TODO REFACTOR THIS CODE ASAP !
|
||||||
if ( $this->isLoaded() ) {
|
if ( $this->isLoaded() ) {
|
||||||
|
|
||||||
if ( null !== ( $join= $entityResolver->searchFieldAnnotation($name, new Join() ) ) ) {
|
if ( null !== ( $join= $entityResolver->searchFieldAnnotation($name, new Join() ) ) ) {
|
||||||
$vars = [];
|
$vars = [];
|
||||||
|
|
||||||
|
@ -60,7 +59,7 @@ trait EntityTrait {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( null !== ( $relation = $entityResolver->searchFieldAnnotation($name, new Relation() ) ) ) {
|
if ( null !== ( $relation = $entityResolver->searchFieldAnnotation($name, new Relation() ) ) ) {
|
||||||
$relationType = strtolower(str_replace(['-', '_'], '', $relation->type));
|
$relationType = strtolower(str_replace(['-', '_', ' '], '', $relation->type));
|
||||||
|
|
||||||
$order = $entityResolver->searchFieldAnnotationList($name, new OrderBy() );
|
$order = $entityResolver->searchFieldAnnotationList($name, new OrderBy() );
|
||||||
$where = $entityResolver->searchFieldAnnotationList($name, new Where() );
|
$where = $entityResolver->searchFieldAnnotationList($name, new Where() );
|
||||||
|
@ -84,6 +83,7 @@ trait EntityTrait {
|
||||||
switch( $relationType ) {
|
switch( $relationType ) {
|
||||||
case 'onetoone':
|
case 'onetoone':
|
||||||
$repository->where( is_object($relation->foreignKey) ? $relation->foreignKey : $baseEntity->field($relation->foreignKey), $this->$field );
|
$repository->where( is_object($relation->foreignKey) ? $relation->foreignKey : $baseEntity->field($relation->foreignKey), $this->$field );
|
||||||
|
$repository->limit(1);
|
||||||
|
|
||||||
$this->eventExecute(Event\EntityRelationLoadInterface::class, $name, $repository);
|
$this->eventExecute(Event\EntityRelationLoadInterface::class, $name, $repository);
|
||||||
|
|
||||||
|
@ -164,9 +164,6 @@ trait EntityTrait {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new \Exception(sprintf("[%s] - Undefined variable: %s", static::class, $name));
|
throw new \Exception(sprintf("[%s] - Undefined variable: %s", static::class, $name));
|
||||||
}
|
}
|
||||||
|
@ -247,6 +244,21 @@ trait EntityTrait {
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function resetVirtualProperties() : self
|
||||||
|
{
|
||||||
|
foreach($this->resolveEntity()->properties as $prop => $property) {
|
||||||
|
if ( ! $property['builtin'] ) {
|
||||||
|
foreach($property['tags'] as $tag) {
|
||||||
|
if ( in_array(strtolower($tag['tag']), [ 'relation', 'join' ] ) ) {
|
||||||
|
unset($this->$prop);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Ignore
|
* @Ignore
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -135,7 +135,7 @@ class Repository
|
||||||
$statement = $this->insertSqlQuery($dataset)->runQuery();
|
$statement = $this->insertSqlQuery($dataset)->runQuery();
|
||||||
|
|
||||||
if ( ( 0 !== $statement->lastInsertId ) &&
|
if ( ( 0 !== $statement->lastInsertId ) &&
|
||||||
( null !== $primaryKeyDefinition )) {
|
( null !== $primaryKeyDefinition )) {
|
||||||
$pkField = key($primaryKeyDefinition);
|
$pkField = key($primaryKeyDefinition);
|
||||||
$entity->$pkField = $statement->lastInsertId;
|
$entity->$pkField = $statement->lastInsertId;
|
||||||
}
|
}
|
||||||
|
@ -393,21 +393,17 @@ class Repository
|
||||||
|
|
||||||
public function filterServerRequest(SearchRequest\SearchRequestInterface $searchRequest) : self
|
public function filterServerRequest(SearchRequest\SearchRequestInterface $searchRequest) : self
|
||||||
{
|
{
|
||||||
$likes = $searchRequest->likes();
|
$searchRequest->count = $searchRequest->filter( clone $this )
|
||||||
$wheres = $searchRequest->wheres();
|
->wheres($searchRequest->wheres(), Query\Where::OPERATOR_EQUAL, Query\Where::CONDITION_AND)
|
||||||
$groups = $searchRequest->groups();
|
->likes($searchRequest->likes(), Query\Where::CONDITION_OR)
|
||||||
|
->groups($searchRequest->groups())
|
||||||
$searchRequest->count = $searchRequest->skipCount ? 0 : $searchRequest->filter( clone $this )
|
|
||||||
->wheres($wheres, Query\Where::OPERATOR_EQUAL, Query\Where::CONDITION_AND)
|
|
||||||
->likes($likes, Query\Where::CONDITION_OR)
|
|
||||||
->groups($groups)
|
|
||||||
->count();
|
->count();
|
||||||
|
|
||||||
return $searchRequest->filter($this)
|
return $searchRequest->filter($this)
|
||||||
->wheres($wheres, Query\Where::OPERATOR_EQUAL, Query\Where::CONDITION_AND)
|
->wheres($searchRequest->wheres(), Query\Where::OPERATOR_EQUAL, Query\Where::CONDITION_AND)
|
||||||
->likes($likes, Query\Where::CONDITION_OR)
|
->likes($searchRequest->likes(), Query\Where::CONDITION_OR)
|
||||||
->orders($searchRequest->orders())
|
->orders($searchRequest->orders())
|
||||||
->groups($groups)
|
->groups($searchRequest->groups())
|
||||||
->offset($searchRequest->offset())
|
->offset($searchRequest->offset())
|
||||||
->limit($searchRequest->limit());
|
->limit($searchRequest->limit());
|
||||||
}
|
}
|
||||||
|
@ -416,17 +412,17 @@ class Repository
|
||||||
{
|
{
|
||||||
$class = $entityClass ?: $this->entityClass;
|
$class = $entityClass ?: $this->entityClass;
|
||||||
|
|
||||||
$entityCollection = $class::entityCollection();
|
$entityCollection = $this->instanciateEntityCollection();
|
||||||
|
|
||||||
$this->selectSqlQuery();
|
$this->selectSqlQuery();
|
||||||
|
|
||||||
$this->finalizeQuery();
|
$this->finalizeQuery();
|
||||||
|
|
||||||
foreach(Ulmus::iterateQueryBuilder($this->queryBuilder, $this->adapter) as $entityData) {
|
foreach(Ulmus::iterateQueryBuilder($this->queryBuilder, $this->adapter) as $entityData) {
|
||||||
$entityCollection->append( ( new $class() )->entityFillFromDataset($entityData) );
|
$entityCollection->append( ( new $class() )->resetVirtualProperties()->entityFillFromDataset($entityData) );
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->eventExecute(Event\Repository\CollectionFromQueryInterface::class, $entityCollection);
|
$this->eventExecute(Event\RepositoryCollectionFromQueryInterface::class, $entityCollection);
|
||||||
|
|
||||||
return $entityCollection;
|
return $entityCollection;
|
||||||
}
|
}
|
||||||
|
@ -510,6 +506,11 @@ class Repository
|
||||||
return $this->entityClass::entityCollection();
|
return $this->entityClass::entityCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function instanciateEntity() : object
|
||||||
|
{
|
||||||
|
return new $this->entityClass();
|
||||||
|
}
|
||||||
|
|
||||||
public function escapeTable(string $identifier) : string
|
public function escapeTable(string $identifier) : string
|
||||||
{
|
{
|
||||||
return $this->adapter->adapter()->escapeIdentifier($identifier, Adapter\AdapterInterface::IDENTIFIER_TABLE);
|
return $this->adapter->adapter()->escapeIdentifier($identifier, Adapter\AdapterInterface::IDENTIFIER_TABLE);
|
||||||
|
|
Loading…
Reference in New Issue