entity interface more methods

This commit is contained in:
Yuri Kuznetsov
2021-04-29 12:08:11 +03:00
parent fb94597409
commit bf320261f9
2 changed files with 62 additions and 4 deletions
+5 -4
View File
@@ -645,17 +645,17 @@ class BaseEntity implements Entity
/**
* Whether an entity type has an attribute defined.
*/
public function hasAttribute(string $name): bool
public function hasAttribute(string $attibute): bool
{
return isset($this->attributes[$name]);
return isset($this->attributes[$attibute]);
}
/**
* Whether an entity type has a relation defined.
*/
public function hasRelation(string $name): bool
public function hasRelation(string $relation): bool
{
return isset($this->relations[$name]);
return isset($this->relations[$relation]);
}
/**
@@ -848,6 +848,7 @@ class BaseEntity implements Entity
if (!self::areValuesEqual(self::JSON_OBJECT, $v1[$i], $v2[$i])) {
return false;
}
continue;
}
+57
View File
@@ -99,4 +99,61 @@ interface Entity
* Get an entity type.
*/
public function getEntityType(): string;
/**
* Get attribute list defined for an entity type.
*/
public function getAttributeList(): array;
/**
* Get relation list defined for an entity type.
*/
public function getRelationList(): array;
/**
* Whether an entity type has an attribute defined.
*/
public function hasAttribute(string $attribute): bool;
/**
* Whether an entity type has a relation defined.
*/
public function hasRelation(string $relation): bool;
/**
* Get an attribute type.
*/
public function getAttributeType(string $attribute): ?string;
/**
* Get a relation type.
*/
public function getRelationType(string $relation): ?string;
/**
* Whether an entity is new.
*/
public function isNew(): bool;
/**
* Whether is fetched from DB.
*/
public function isFetched(): bool;
/**
* Whether an attribute was changed (since syncing with DB).
*/
public function isAttributeChanged(string $name): bool;
/**
* Get a fetched value of a specific attribute.
*
* @return mixed
*/
public function getFetched(string $attribute);
/**
* Whether a fetched value is set for a specific attribute.
*/
public function hasFetched(string $attribute): bool;
}