- 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:
1 parent
c8397484e6
commit
114fa5be09
2 files changed
+132
-119
No files matched your search
+23
-11
@@ -35,12 +35,11 @@ trait EntityTrait {
|
||||
public function __get(string $name)
|
||||
{
|
||||
$entityResolver = $this->resolveEntity();
|
||||
|
||||
|
||||
# Resolve relations here if one is called
|
||||
|
||||
|
||||
# @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);
|
||||
|
||||
@@ -113,7 +113,7 @@ trait EntityTrait {
|
||||
if ($relationRelation === null) {
|
||||
throw new \Exception("@Relation annotation not found for field `{$relation->foreignField}` in entity {$relation->bridge}");
|
||||
}
|
||||
|
||||
|
||||
$repository = $relationRelation->entity()->repository();
|
||||
|
||||
$bridgeAlias = uniqid("bridge_");
|
||||
@@ -164,10 +164,7 @@ trait EntityTrait {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
|
||||
|
||||
throw new \Exception(sprintf("[%s] - Undefined variable: %s", static::class, $name));
|
||||
}
|
||||
|
||||
@@ -179,7 +176,7 @@ trait EntityTrait {
|
||||
if ( $this->isLoaded() && static::resolveEntity()->searchFieldAnnotation($name, new Relation() ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return isset($this->$name);
|
||||
}
|
||||
|
||||
@@ -246,6 +243,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
|
||||
@@ -388,7 +400,7 @@ trait EntityTrait {
|
||||
{
|
||||
$collection = new EntityCollection(...$arguments);
|
||||
$collection->entityClass = static::class;
|
||||
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user