Get entity manager for the connection and apps.

@param string $name
@return EntityManager
176408
public static function entityManager($name = 'default')
    {
        if (isset(self::$entityManagers[$name])) {
            return self::$entityManagers[$name];
        }
        $databaseConnection = self::connection($name)->getDbalConnection();

        if (Configuration::get('app.env') == 'development') {
            $cache = new ArrayCache();
        } else { // @codeCoverageIgnore
            $cache = new FilesystemCache(Configuration::get('app.cache')); // @codeCoverageIgnore
        }

        $config = new \Doctrine\ORM\Configuration();
        $config->setMetadataCacheImpl($cache);
        $driver = $config->newDefaultAnnotationDriver([APPPATH . 'Entity'], false);

        $config->setMetadataDriverImpl($driver);
        $config->setQueryCacheImpl($cache);

        $proxyDir = APPPATH . 'Proxy';
        $proxyNamespace = 'App\Proxy';

        $config->setProxyDir($proxyDir);
        $config->setProxyNamespace($proxyNamespace);
        Autoloader::register($proxyDir, $proxyNamespace);

        $loggerChain = new LoggerChain();
        if (Configuration::get('app.env') == 'development') {
            $config->setAutoGenerateProxyClasses(true);

            $loggerChain->addLogger(new DoctrineLogBridge(\Logger::getInstance()->getMonologInstance()));
            $loggerChain->addLogger(DebugBarHelper::getInstance()->getDebugStack());
        } else { // @codeCoverageIgnore
            $config->setAutoGenerateProxyClasses(false); // @codeCoverageIgnore
        }
        $em = EntityManager::create($databaseConnection, $config);

        $em->getConnection()->getConfiguration()->setSQLLogger($loggerChain);
        $em->getConfiguration()->setSQLLogger($loggerChain);

        self::$entityManagers[$name] = $em;
        return $em;
    }
391145
public function getProvider($name) {
        if (false === $this->exists($name)) {
            throw new UnregisteredDataTablesProviderException($name);
        }
        return $this->getProviders()[$this->index[$name]];
    }
537374
public function setEntityClass($name)
    {
        $class = App::className($name, 'Model/Entity');
        if (!$class) {
            throw new MissingEntityException([$name]);
        }

        $this->_entityClass = $class;

        return $this;
    }
1171255
public function getRepository(EntityManagerInterface $entityManager, $entityName)
    {
        return $this->repositorySubManager->get($this->entityRepositoryMapping->getRepositoryByEntity($entityName));
    }
12704
public function connection($name = null)
    {
        if ( ! isset($this->connections[$name]))
        {
            $this->connections[$name] = $this->createConnection($name);
        }

        return $this->connections[$name];
    }
337838
private function getEntityManager($force = false)
    {
        /** @var EntityManager $em */
        $em = $this->doctrine->getManagerForClass($this->entityClass);
        if ($force) {
            if (!$em->isOpen()) {
                $this->resetEntityManager();
                $em = $this->doctrine->getManagerForClass($this->entityClass);
            } else {
                /**
                 * ensure that the transaction is fully rolled back
                 * in case if a nested transaction is rolled back but the entity manager is not closed
                 * this may happen if the EntityManager::rollback() method is called
                 * without the call of EntityManager::close() method
                 * @link http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/transactions-and-concurrency.html#exception-handling
                 */
                $connection = $em->getConnection();
                if ($connection->getTransactionNestingLevel() > 0 && $connection->isRollbackOnly()) {
                    while ($connection->getTransactionNestingLevel() > 0) {
                        $connection->rollBack();
                    }
                }
            }
        }

        return $em;
    }
205824
public function getCache($name)
    {
        $cache = $this->getConnector($name)->getCacheAdapter();

        if ($this->logger instanceof LoggerInterface) {
            $cache->setLogger($this->logger);
        }

        return $cache;
    }
76496
public function getHandler(string $name): \SessionHandlerInterface
    {
        $name = strtolower($name);
        $this->isValidate($name);
        return App::getBean($this->handlers[$name]);
    }
10704
public function get(string $name): ApiConnector
    {
        return $this->apiFactory->createApiConnector($name, $this->options);
    }
1191214
protected function _getConnection( $name )
	{
		if( !isset( $this->_connections[$name] ) ) {
			return $this->_conn;
		}

		return $this->_connections[$name];
	}
344462
public function getEntityManager()
    {
        if ($this->em === null) {
            $this->setEntityManager($this->container->get('doctrine')->getManager($this->emName));
        }

        return $this->em;
    }
785499
public static function init(EntityManagerInterface $entityManager, $name = '') {
        Debugger::getBar()->addPanel(new static($entityManager->getConnection()->getConfiguration(), $name));
    }
128870
public static function logger($name = 'Webiny')
    {
        try {
            return ServiceManager::getInstance()->getService('Logger.' . $name);
        } catch (ServiceManagerException $e) {
            if ($e->getCode() == ServiceManagerException::SERVICE_DEFINITION_NOT_FOUND) {
                return new Logger($name, new NullDriver());
            }

            throw $e;
        }

    }
776296
public function values($name)
    {
        return $this->map(function (EntityInterface $entity) use ($name) {
            return $entity->getByName($name);
        });
    }
1172604
public function getLazy($entity, $name)
    {
        // Verify if virtual property exists
        if (! in_array($name, $this->getEntityStructure($entity)->relationProperties)) {
            throw new RelationException("Property '".$name."' is not a valid and declared property, or relation property!");
        }

        return RelationManager::with($entity)->fetch($name);
    }
520574
public function getService($name)
    {
        if (!$this->serviceManager) {
            throw new Exception\UndefinedReferenceException('Cannot get service without an service manager instance!');
        }

        return $this->serviceManager->get($name);
    }
404564
public function getConnection($name = null)
    {
        $name = $name ?: $this->getDefaultConnectionName();

        if (!$this->connectionExists($name)) {
            throw new InvalidArgumentException(sprintf('Doctrine Connection named "%s" does not exist.', $name));
        }

        if (isset($this->connectionsMap[$name])) {
            return $this->connectionsMap[$name];
        }

        return $this->connectionsMap[$name] = $this->getService(
            $this->getConnectionBindingName($this->connections[$name])
        );
    }