init
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\MultiLocaleTranslation\Model;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
class EntityPool
|
||||
{
|
||||
public function __construct(private readonly array $entities = [])
|
||||
{
|
||||
}
|
||||
|
||||
public function get(string $entityType): TranslatableEntityInterface
|
||||
{
|
||||
if (!isset($this->entities[$entityType])) {
|
||||
throw new InvalidArgumentException(sprintf('Unsupported entity type "%s".', $entityType));
|
||||
}
|
||||
|
||||
$entity = $this->entities[$entityType];
|
||||
|
||||
if (!$entity instanceof TranslatableEntityInterface) {
|
||||
throw new InvalidArgumentException(sprintf('Entity "%s" is misconfigured.', $entityType));
|
||||
}
|
||||
|
||||
return $entity;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user