| 1 | <?php |
||
| 8 | use Laminas\Stdlib\AbstractOptions; |
||
| 9 | use function class_exists; |
||
| 10 | use function sprintf; |
||
| 11 | |||
| 12 | class EntityResolver extends AbstractOptions |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * Set the configuration key for the EventManager. Event manager key |
||
| 16 | * is assembled as "doctrine.eventmanager.{key}" and pulled from |
||
| 17 | * service locator. |
||
| 18 | */ |
||
| 19 | protected string $eventManager = 'orm_default'; |
||
|
|
|||
| 20 | |||
| 21 | /** |
||
| 22 | * An array that maps a class name (or interface name) to another class |
||
| 23 | * name |
||
| 24 | * |
||
| 25 | * @var string[] |
||
| 26 | */ |
||
| 27 | protected array $resolvers = []; |
||
| 28 | |||
| 29 | public function setEventManager(string $eventManager) : self |
||
| 30 | { |
||
| 31 | $this->eventManager = $eventManager; |
||
| 32 | |||
| 33 | return $this; |
||
| 34 | } |
||
| 35 | |||
| 36 | public function getEventManager() : string |
||
| 37 | { |
||
| 38 | return 'doctrine.eventmanager.' . $this->eventManager; |
||
| 39 | } |
||
| 40 | |||
| 41 | 72 | /** |
|
| 42 | * @param string[] $resolvers |
||
| 43 | 72 | * |
|
| 44 | * @throws InvalidArgumentException |
||
| 45 | */ |
||
| 46 | public function setResolvers(array $resolvers) : void |
||
| 47 | { |
||
| 48 | foreach ($resolvers as $old => $new) { |
||
| 49 | if (! class_exists($new)) { |
||
| 50 | 72 | throw new InvalidArgumentException( |
|
| 51 | sprintf( |
||
| 52 | 72 | '%s is resolved to the entity %s, which does not exist', |
|
| 53 | 72 | $old, |
|
| 54 | $new |
||
| 55 | ) |
||
| 56 | ); |
||
| 57 | } |
||
| 58 | |||
| 59 | $this->resolvers[$old] = $new; |
||
| 60 | } |
||
| 61 | } |
||
| 62 | |||
| 63 | 72 | /** |
|
| 64 | * @return string[] |
||
| 65 | 72 | */ |
|
| 66 | public function getResolvers() : array |
||
| 67 | { |
||
| 68 | return $this->resolvers; |
||
| 69 | } |
||
| 70 | } |
||
| 71 |