- 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 !
|
||||
if ( $this->isLoaded() ) {
|
||||
|
||||
if ( null !== ( $join= $entityResolver->searchFieldAnnotation($name, new Join() ) ) ) {
|
||||
$vars = [];
|
||||
|
||||
|
@ -60,7 +59,7 @@ trait EntityTrait {
|
|||
}
|
||||
|
||||
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() );
|
||||
$where = $entityResolver->searchFieldAnnotationList($name, new Where() );
|
||||
|
@ -84,6 +83,7 @@ trait EntityTrait {
|
|||
switch( $relationType ) {
|
||||
case 'onetoone':
|
||||
$repository->where( is_object($relation->foreignKey) ? $relation->foreignKey : $baseEntity->field($relation->foreignKey), $this->$field );
|
||||
$repository->limit(1);
|
||||
|
||||
$this->eventExecute(Event\EntityRelationLoadInterface::class, $name, $repository);
|
||||
|
||||
|
@ -164,9 +164,6 @@ trait EntityTrait {
|
|||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
|
||||
throw new \Exception(sprintf("[%s] - Undefined variable: %s", static::class, $name));
|
||||
}
|
||||
|
@ -247,6 +244,21 @@ trait EntityTrait {
|
|||
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
|
||||
*/
|
||||
|
|
|
@ -135,7 +135,7 @@ class Repository
|
|||
$statement = $this->insertSqlQuery($dataset)->runQuery();
|
||||
|
||||
if ( ( 0 !== $statement->lastInsertId ) &&
|
||||
( null !== $primaryKeyDefinition )) {
|
||||
( null !== $primaryKeyDefinition )) {
|
||||
$pkField = key($primaryKeyDefinition);
|
||||
$entity->$pkField = $statement->lastInsertId;
|
||||
}
|
||||
|
@ -393,21 +393,17 @@ class Repository
|
|||
|
||||
public function filterServerRequest(SearchRequest\SearchRequestInterface $searchRequest) : self
|
||||
{
|
||||
$likes = $searchRequest->likes();
|
||||
$wheres = $searchRequest->wheres();
|
||||
$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)
|
||||
$searchRequest->count = $searchRequest->filter( clone $this )
|
||||
->wheres($searchRequest->wheres(), Query\Where::OPERATOR_EQUAL, Query\Where::CONDITION_AND)
|
||||
->likes($searchRequest->likes(), Query\Where::CONDITION_OR)
|
||||
->groups($searchRequest->groups())
|
||||
->count();
|
||||
|
||||
return $searchRequest->filter($this)
|
||||
->wheres($wheres, Query\Where::OPERATOR_EQUAL, Query\Where::CONDITION_AND)
|
||||
->likes($likes, Query\Where::CONDITION_OR)
|
||||
->wheres($searchRequest->wheres(), Query\Where::OPERATOR_EQUAL, Query\Where::CONDITION_AND)
|
||||
->likes($searchRequest->likes(), Query\Where::CONDITION_OR)
|
||||
->orders($searchRequest->orders())
|
||||
->groups($groups)
|
||||
->groups($searchRequest->groups())
|
||||
->offset($searchRequest->offset())
|
||||
->limit($searchRequest->limit());
|
||||
}
|
||||
|
@ -416,17 +412,17 @@ class Repository
|
|||
{
|
||||
$class = $entityClass ?: $this->entityClass;
|
||||
|
||||
$entityCollection = $class::entityCollection();
|
||||
$entityCollection = $this->instanciateEntityCollection();
|
||||
|
||||
$this->selectSqlQuery();
|
||||
|
||||
$this->finalizeQuery();
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -510,6 +506,11 @@ class Repository
|
|||
return $this->entityClass::entityCollection();
|
||||
}
|
||||
|
||||
public function instanciateEntity() : object
|
||||
{
|
||||
return new $this->entityClass();
|
||||
}
|
||||
|
||||
public function escapeTable(string $identifier) : string
|
||||
{
|
||||
return $this->adapter->adapter()->escapeIdentifier($identifier, Adapter\AdapterInterface::IDENTIFIER_TABLE);
|
||||
|
|
Loading…
Reference in New Issue