@throws \ReflectionException

@return EntityManager
436163
protected function getEntityManager()
    {
        if (null === $this->entityManager) {
            $reflectionProperty = new \ReflectionProperty(SQLFilter::class, 'em');
            $reflectionProperty->setAccessible(true);
            $this->entityManager = $reflectionProperty->getValue($this);
        }

        return $this->entityManager;
    }
164659
public function createService(ServiceLocatorInterface $serviceManager)
    {
        /** @var \Doctrine\ORM\EntityManager $objectManager */
        $objectManager = $serviceManager->get('Doctrine\ORM\EntityManager');

        /** @var \Eye4web\Zf2Board\Options\ModuleOptionsInterface $options */
        $options = $serviceManager->get('Eye4web\Zf2Board\Options\ModuleOptions');

        $mapper = new PostMapper($objectManager, $options);

        return $mapper;
    }
218395
protected function wrapCommand($entityManagerName)
    {
        if (! $this->isVersionCompatible()) {
            throw new RuntimeException(sprintf('"%s" requires doctrine-orm "%s" or newer', $this->getName(), $this->getMinimalVersion()));
        }

        DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $entityManagerName);
        $this->command->setApplication($this->getApplication());

        return $this->command;
    }
158801
public function from($entityMapperTypeOrFactory)
    {
        if (is_callable($entityMapperTypeOrFactory)) {
            call_user_func($this->callback, $entityMapperTypeOrFactory);
        } elseif (is_a($entityMapperTypeOrFactory, IEntityMapper::class, true)) {
            call_user_func($this->callback, function (IOrm $orm) use ($entityMapperTypeOrFactory) {
                if ($this->iocContainer) {
                    return $this->iocContainer->bindForCallback(IOrm::class, $orm, function () use ($entityMapperTypeOrFactory) {
                        return  $this->iocContainer->get($entityMapperTypeOrFactory);
                    });
                }
                
                return new $entityMapperTypeOrFactory($orm);
            });
        } else {
            throw InvalidArgumentException::format(
                    'Invalid entity object factory: expecting callable or type of %s, %s given',
                    IEntityMapper::class, $entityMapperTypeOrFactory
            );
        }
    }
1211392
public function getEntityManager()
    {
        if (isset($this->entityManager) && is_object($this->entityManager)) {
            // 5.8 ->
            return $this->entityManager;
        }
        $pkgID = $this->c->getPackageID();
        if ($pkgID > 0) {
            return Package::getByID($pkgID)->getEntityManager();
        } else {
            return ORM::entityManager('app');
        }
    }
1289916
public function getSchemaManager()
    {
        if ($this->_schemaManager === null) {
            $this->_schemaManager = $this->_driver->getSchemaManager($this);
        }

        return $this->_schemaManager;
    }
812710
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        /** @var DoctrineObjectManagerInterface $doctrineObjectManager */
        $doctrineObjectManager = $serviceLocator->get(DoctrineObjectManagerInterface::class);

        /** @var ModuleOptionsPluginManagerInterface $moduleOptionsPluginManager */
        $moduleOptionsPluginManager = $serviceLocator->get(ModuleOptionsPluginManagerInterface::class);

        /** @var EntityManagerInterface $entityManager */
        $entityManager = $serviceLocator->get(EntityManagerInterface::class);

        return new EntityMapBuilder($doctrineObjectManager, $moduleOptionsPluginManager, $entityManager);
    }
560459
public function getRepository(EntityManagerInterface $entityManager, $className) {
		if(!isset($this->repositories[$className])) {
			$this->repositories[$className] = $this->generateRepository($entityManager, $className);
		}
		return $this->repositories[$className];
	}
1017287
private function setEntityManager()
    {
        try {
            if ($this->_instance_options['em'] instanceof EntityManager) {
                $this->_em = $this->_instance_options['em'];
            } else {
                $this->_em = EntityManagerCreator::create($this->_instance_options['dbal'], $this->getLogger());
            }
        } catch (InvalidArgumentException $e) {
            throw new CacheException('DAO cache: enable to create a database conneciton', CacheException::INVALID_DB_CONNECTION, $e);
        }

        return $this;
    }
399799
public function getDescriptor()
    {
        if (null == $this->descriptor) {
            $this->setDescriptor(
                EntityDescriptorRegistry::getInstance()
                    ->getDescriptorFor($this->getEntityClassName())
            );
        }
        return $this->descriptor;
    }
749880
private function entityFactory()
    {
        // this is a little tortuous but some constructor flows require the EntityManager
        // as this point in the refactor I'm unwilling to modify the constructor of the Entity
        // TODO. Fix this. Constructor injection
        $entity = $this->reflEntityClass->newInstanceWithoutConstructor();
        // add the entityManager
        if( $this->reflEntityManagerPropertyOfEntity ) {
            $this->reflEntityManagerPropertyOfEntity->setValue($entity, $this->entityManager);
        }
        // call the original constructor
        call_user_func_array( [$entity, '__construct'], func_get_args() );
        return $entity;
    }
1335911
protected function getCollectionManager()
    {
        return $this->getPrototype(
            $this->collectionManagerClass,
            ['umi\orm\collection\ICollectionManager']
        )
            ->createSingleInstance(
                [
                    $this->getObjectCollectionFactory(),
                    $this->collections
                ]
            );
    }
1374897
public function getObjectManager(): ObjectManagerInterface
    {
        if (!isset($this->earlyInstances[ObjectManagerInterface::class])) {
            debug_print_backtrace();
            throw new FlowException('The Object Manager is not available at this stage of the bootstrap run.', 1301120788);
        }
        return $this->earlyInstances[ObjectManagerInterface::class];
    }
548838
protected function setUpEntityManagers()
    {
        $managers    = [];
        $connections = [];

        foreach ($this->config['managers'] as $manager => $settings) {
            $managerName    = IlluminateRegistry::getManagerNamePrefix() . $manager;
            $connectionName = IlluminateRegistry::getConnectionNamePrefix() . $manager;

            // Bind manager
            $this->app->singleton($managerName, function () use ($settings) {

                $manager = EntityManager::create(
                    ConnectionManager::resolve(array_get($settings, 'connection')),
                    MetaDataManager::resolve(array_get($settings, 'meta'))
                );

                $configuration = $manager->getConfiguration();

                // Listeners
                if (isset($settings['events']['listeners'])) {
                    foreach ($settings['events']['listeners'] as $event => $listener) {
                        $manager->getEventManager()->addEventListener($event, $listener);
                    }
                }

                // Subscribers
                if (isset($settings['events']['subscribers'])) {
                    foreach ($settings['events']['subscribers'] as $subscriber) {
                        $manager->getEventManager()->addEventSubscriber($subscriber);
                    }
                }

                // Filters
                if (isset($settings['filters'])) {
                    foreach ($settings['filters'] as $name => $filter) {
                        $configuration->getMetadataDriverImpl()->addFilter($name, $filter);
                        $manager->getFilters()->enable($name);
                    }
                }

                // Paths
                $configuration->getMetadataDriverImpl()->addPaths(
                    array_get($settings, 'paths', [])
                );

                // Repository
                $configuration->setDefaultRepositoryClassName(
                    array_get($settings, 'repository', \Doctrine\ORM\EntityRepository::class)
                );

                $configuration->setAutoGenerateProxyClasses(
                    array_get($settings, 'proxies.auto_generate', false)
                );

                if ($namespace = array_get($settings, 'proxies.namespace', false)) {
                    $configuration->setProxyNamespace($namespace);
                }

                return $manager;
            });

            // Bind connection
            $this->app->singleton($connectionName, function ($app) use ($manager) {
                $app->make(IlluminateRegistry::getManagerNamePrefix() . $manager)->getConnection();
            });

            $managers[$manager]    = $manager;
            $connections[$manager] = $manager;
        }

        return [$managers, $connections];
    }
1112753
private function processEntityManager()
	{
		$builder = $this->getContainerBuilder();

		$configuration = $builder->addDefinition($this->prefix('configuration'))
			->setClass(Configuration::class)
			->addSetup('$service->setMetadataDriverImpl($this->getService(?))', [$this->prefix('metadata.driver')])
			->addSetup('$service->setMetadataCacheImpl(?)', ['@' . $this->prefix('cache.metadata')])
			->addSetup('$service->setQueryCacheImpl(?)', ['@' . $this->prefix('cache.query')])
			->addSetup('$service->setResultCacheImpl(?)', ['@' . $this->prefix('cache.result')])
			->addSetup('$service->setHydrationCacheImpl(?)', ['@' . $this->prefix('cache.hydration')])
			->addSetup('$service->setProxyDir(?)', [$this->config['proxyDir']])
			->addSetup('$service->setProxyNamespace(?)', [$this->config['proxyNamespace']])
			->addSetup('$service->setNamingStrategy(?)', [new \Nette\DI\Statement('Doctrine\ORM\Mapping\UnderscoreNamingStrategy')])
			->addSetup('$service->setQuoteStrategy(?)', [new \Nette\DI\Statement('Doctrine\ORM\Mapping\DefaultQuoteStrategy')])
			->addSetup('$service->setAutoGenerateProxyClasses(?)', [1])
			->addSetup('$service->setEntityListenerResolver(?)', ['@' . $this->prefix('entityListenerResolver')]);

		$entityManager = $builder->addDefinition($this->prefix('entityManager'))
			->setClass(EntityManager::class)
			->setFactory(EntityManager::class . '::create', [
				'@' . $this->prefix('connection'),
				'@' . $this->prefix('configuration'),
				'@' . $this->prefix('eventManager')
			]);
	}
769879
public static function getEntityManager() {
		if (self::$_entityManager == null) {
			self::$_entityManager = self::_getInstance ();
		}
		return self::$_entityManager;
	}
743165
public function getRegistry(string $registryName, $entityClass = null, EntityManager $entityManager = null)
    {
        if (!array_key_exists($registryName, self::$registries)) {
            throw new InvalidRegistryName($registryName);
        }

        $reflectionClass = new \ReflectionClass(self::$registries[$registryName]);

        /** @var RegistryInterface $instance */
        $instance = $reflectionClass->newInstance();

        $this->injectDependencies($instance, $entityClass, $entityManager);

        return $instance;
    }