entity provider get
This commit is contained in:
@@ -35,6 +35,8 @@ use Espo\Core\Exceptions\NotFound;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\ORM\EntityManager;
|
||||
|
||||
use const E_USER_DEPRECATED;
|
||||
|
||||
/**
|
||||
* Fetches entities.
|
||||
*
|
||||
@@ -64,6 +66,44 @@ class EntityProvider
|
||||
->getRDBRepositoryByClass($className)
|
||||
->getById($id);
|
||||
|
||||
return $this->processGet($entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch an entity by an entity type.
|
||||
*
|
||||
* @return Entity
|
||||
* @throws NotFound
|
||||
* @throws Forbidden
|
||||
* @since 8.5.0
|
||||
*/
|
||||
public function get(string $entityType, string $id): Entity
|
||||
{
|
||||
if (!$this->entityManager->hasRepository($entityType)) {
|
||||
// @todo Remove in v9.0.
|
||||
trigger_error(
|
||||
'EntityProvider::get should receive an entity type, not a class name.',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
/** @phpstan-ignore-next-line */
|
||||
return $this->getByClass($entityType, $id);
|
||||
}
|
||||
|
||||
$entity = $this->entityManager->getEntityById($entityType, $id);
|
||||
|
||||
return $this->processGet($entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @template T of Entity
|
||||
* @param ?T $entity
|
||||
* @return T
|
||||
* @throws Forbidden
|
||||
* @throws NotFound
|
||||
* @noinspection PhpDocSignatureInspection
|
||||
*/
|
||||
private function processGet(?Entity $entity): Entity
|
||||
{
|
||||
if (!$entity) {
|
||||
throw new NotFound();
|
||||
}
|
||||
@@ -74,20 +114,4 @@ class EntityProvider
|
||||
|
||||
return $entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated As of v8.3.
|
||||
* @todo Remove in v8.4. Change $className to $entityType.
|
||||
*
|
||||
* @template T of Entity
|
||||
* @param class-string<T> $className
|
||||
* @return T
|
||||
* @throws NotFound
|
||||
* @throws Forbidden
|
||||
* @noinspection PhpDocSignatureInspection
|
||||
*/
|
||||
public function get(string $className, string $id): Entity
|
||||
{
|
||||
return $this->getByClass($className, $id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user