Added the possibility to add event subscribers directly when creating em in factory
This commit is contained in:
@@ -18,7 +18,7 @@ use RuntimeException;
|
||||
*/
|
||||
class EntityManagerFactory
|
||||
{
|
||||
public static function create(array $params, bool $dev_mode = false, array $middlewares = [], array $filters = []) : EntityManager
|
||||
public static function create(array $params, bool $dev_mode = false, array $middlewares = [], array $filters = [], array $event_subscribers = []) : EntityManager
|
||||
{
|
||||
self::checkRequiredParams($params, ['paths', 'database', 'proxy_dir']);
|
||||
|
||||
@@ -45,6 +45,14 @@ class EntityManagerFactory
|
||||
|
||||
$connection = DriverManager::getConnection($params['database'], $config);
|
||||
$em = new EntityManager($connection, $config);
|
||||
|
||||
if ($event_subscribers) {
|
||||
$evm = $em->getEventManager();
|
||||
foreach ($event_subscribers as $subscriber) {
|
||||
$evm->addEventSubscriber($subscriber);
|
||||
}
|
||||
}
|
||||
|
||||
return $em;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user