Creates a new entity manager instance based on the given configuration.

@return \Doctrine\ORM\EntityManagerInterface The entity manager instance
185267
public function factory()
    {

        // load the application and persistence unit configuration
        $application = $this->getApplication();
        $persistenceUnitNode = $this->getPersistenceUnitNode();

        // create a new Doctrine ORM configuration instance
        $configuration = $this->createConfiguration();

        // query whether or not an initialize EM configuration is available
        if ($application->hasAttribute($persistenceUnitNode->getName()) === false) {
            // globally ignore configured annotations to ignore
            foreach ($persistenceUnitNode->getIgnoredAnnotations() as $ignoredAnnotation) {
                AnnotationReader::addGlobalIgnoredName($ignoredAnnotation->getNodeValue()->__toString());
            }

            // load the datasource node
            $datasourceNode = null;
            foreach ($application->getInitialContext()->getSystemConfiguration()->getDatasources() as $datasourceNode) {
                if ($datasourceNode->getName() === $persistenceUnitNode->getDatasource()->getName()) {
                    break;
                }
            }

            // throw a exception if the configured datasource is NOT available
            if ($datasourceNode == null) {
                throw new \Exception(sprintf('Can\'t find a datasource node for persistence unit %s', $persistenceUnitNode->getName()));
            }

            // load the database node
            $databaseNode = $datasourceNode->getDatabase();

            // throw an exception if the configured database is NOT available
            if ($databaseNode == null) {
                throw new \Exception(sprintf('Can\'t find database node for persistence unit %s', $persistenceUnitNode->getName()));
            }

            // load the driver node
            $driverNode = $databaseNode->getDriver();

            // throw an exception if the configured driver is NOT available
            if ($driverNode == null) {
                throw new \Exception(sprintf('Can\'t find driver node for persistence unit %s', $persistenceUnitNode->getName()));
            }

            // load the connection parameters
            $connectionParameters = ConnectionUtil::get($application)->fromDatabaseNode($databaseNode);

            // append the initialized EM configuration to the application
            $application->setAttribute($persistenceUnitNode->getName(), array($connectionParameters, $configuration));
        }

        // load the initialized EM configuration from the application
        list ($connectionParameters, $configuration) = $application->getAttribute($persistenceUnitNode->getName());

        // initialize and return a entity manager decorator instance
        return new DoctrineEntityManagerDecorator(EntityManager::create($connectionParameters, $configuration));
    }
797640
public function writer()
    {
        if (empty($this->entityName)) {
            throw new InvalidConfigurationException('Can only use doctrine for writing if entityName is given.');
        }

        $writer = new DoctrineWriter($this->entityManager, $this->entityName);
        $writer->setTruncate(false);

        return $writer;
    }
43879
public function getEntityManager()
    {
        if (!isset($this->_entityManager)) {
            $this->_entityManager = $this->getServiceLocator()
                    ->get('Doctrine\ORM\EntityManager');
        }
        return $this->_entityManager;
    }
1130039
public function searchManager()
    {
        if ($this->_manager === null) {
            $this->_manager = new Manager(
                $this->_repository(),
                $this->_collectionClass
            );
        }

        return $this->_manager;
    }
856491
protected function extendAuthManager()
    {
        if ($this->app->bound('auth')) {
            $this->app->make('auth')->provider('doctrine', function ($app, $config) {
                $entity = $config['model'];

                $em = $app['registry']->getManagerForClass($entity);

                if (!$em) {
                    throw new InvalidArgumentException("No EntityManager is set-up for {$entity}");
                }

                return new DoctrineUserProvider(
                    $app['hash'],
                    $em,
                    $entity
                );
            });
        }
    }
436895
protected function createConfiguration()
    {

        // load the persistence unit configuration
        $persistenceUnitNode = $this->getPersistenceUnitNode();

        // load the metadata configuration
        $metadataConfiguration = $persistenceUnitNode->getMetadataConfiguration();

        // prepare the setup properties
        $absolutePaths = $metadataConfiguration->getDirectoriesAsArray();
        $proxyDir = $metadataConfiguration->getParam(MetadataConfigurationInterface::PARAM_PROXY_DIR);
        $proxyNamespace = $metadataConfiguration->getParam(MetadataConfigurationInterface::PARAM_PROXY_NAMESPACE);
        $autoGenerateProxyClasses = $metadataConfiguration->getParam(MetadataConfigurationInterface::PARAM_AUTO_GENERATE_PROXY_CLASSES);
        $useSimpleAnnotationReader = $metadataConfiguration->getParam(MetadataConfigurationInterface::PARAM_USE_SIMPLE_ANNOTATION_READER);

        // load the metadata driver factory class name
        $metadataDriverFactory = $metadataConfiguration->getFactory();

        // initialize the params to be passed to the factory
        $metadataDriverParams = array(DriverKeys::USE_SIMPLE_ANNOTATION_READER => $useSimpleAnnotationReader);

        // create the Doctrine ORM configuration
        $configuration = new Configuration();
        $configuration->setMetadataDriverImpl($metadataDriverFactory::get($configuration, $absolutePaths, $metadataDriverParams));

        // initialize the metadata cache configuration
        $metadataCacheConfiguration = $persistenceUnitNode->getMetadataCacheConfiguration();
        $configuration->setMetadataCacheImpl($this->getCacheImpl($metadataCacheConfiguration));

        // initialize the query cache configuration
        $queryCacheConfiguration = $persistenceUnitNode->getQueryCacheConfiguration();
        $configuration->setQueryCacheImpl($this->getCacheImpl($queryCacheConfiguration));

        // initialize the result cache configuration
        $resultCacheConfiguration = $persistenceUnitNode->getResultCacheConfiguration();
        $configuration->setResultCacheImpl($this->getCacheImpl($resultCacheConfiguration));

        // proxy configuration
        $configuration->setProxyDir($proxyDir = $proxyDir ?: sys_get_temp_dir());
        $configuration->setProxyNamespace($proxyNamespace = $proxyNamespace ?: 'Doctrine\Proxy');
        $configuration->setAutoGenerateProxyClasses($autoGenerateProxyClasses = $autoGenerateProxyClasses ?: true);

        // repository configuration
        $configuration->setDefaultRepositoryClassName($persistenceUnitNode->getDefaultRepositoryClassName());
        $configuration->setRepositoryFactory($this->getApplication()->search($persistenceUnitNode->getRepositoryFactory()));

        // return the configuration instance
        return $configuration;
    }
940148
public function getObjectManager()
    {
        $manager = $this->registry->getManagerForClass($this->class);

        if (!$manager) {
            throw new \RuntimeException(sprintf(
                'Unable to find the mapping information for the class %s.'
                .' Please check the `auto_mapping` option'
                .' (http://symfony.com/doc/current/reference/configuration/doctrine.html#configuration-overview)'
                .' or add the bundle to the `mappings` section in the doctrine configuration.',
                $this->class
            ));
        }

        return $manager;
    }
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);
    }
3322
public static function create($conn, Configuration $config = null, EventManager $eventManager = null)
    {
        if (null === $config) {
            $config = new Configuration();
            $config->setProxyDir(__DIR__ . '/../Proxies');
            $config->setProxyNamespace('Doctrine\Tests\Proxies');
            $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver([], true));
        }
        if (null === $eventManager) {
            $eventManager = new EventManager();
        }

        return new EntityManagerMock($conn, $config, $eventManager);
    }
1012383
protected function createRepository(EntityManagerInterface $entityManager, $entityName)
    {
        $metadata = $entityManager->getClassMetadata($entityName);
        $repository = $metadata->customRepositoryClassName;

        if ($repository === null) {
            $repository = $entityManager->getConfiguration()->getDefaultRepositoryClassName();
        }

        return $this->createResourceRepository(
            $repository,
            $entityManager,
            $metadata,
            $this->resolveResource($metadata->getName())
        );
    }
969268
protected function createEntityManager(ConfigRepository $config)
    {
        if (!isset($config['doctrine'])) {
            throw new Exception('Doctrine configuration not registered.');
        }

        if (!isset($config['database'])) {
            throw new Exception('Database configuration not registered.');
        }

        $doctrineConfig = $config['doctrine'];
        $databaseConfig = $config['database'];

        $connectionConfig = $this->createConnectionConfig($doctrineConfig, $databaseConfig);

        $type              = array_get($doctrineConfig, 'mapping', self::METADATA_ANNOTATIONS);
        $paths             = array_get($doctrineConfig, 'paths', [base_path('app/Entities')]);
        $debug             = $config['app.debug'];
        $proxyDir          = array_get($doctrineConfig, 'proxy.directory');
        $simpleAnnotations = array_get($doctrineConfig, 'simple_annotations', false);

        $metadataConfiguration = $this->createMetadataConfiguration($type, $paths, $debug, $proxyDir, null,
            $simpleAnnotations);

        $this->configureMetadataConfiguration($metadataConfiguration, $doctrineConfig);

        $eventManager = new EventManager;

        $this->configureEventManager($doctrineConfig, $eventManager);

        $entityManager = EntityManager::create($connectionConfig, $metadataConfiguration, $eventManager);

        $this->configureEntityManager($doctrineConfig, $entityManager);

        return $entityManager;
    }
889913
public function create() {
        $data = Values::of(array());

        $payload = $this->version->create(
            'POST',
            $this->uri,
            array(),
            $data
        );

        return new ConfigurationInstance($this->version, $payload);
    }
995910
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        $entityManager = $serviceLocator->get('Doctrine\ORM\EntityManager');

        return new \Reliv\RcmConfig\Model\DoctrineModel($entityManager, null);
    }
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;
    }
500616
public function create(): ConfigurationInterface
    {
        $config = $this->detectConfig();
        $config->set('env', $this->environment);

        return $config;
    }
480463
public static function create()
     {
         $config = parent::create();
         $config->level(FixerInterface::SYMFONY_LEVEL);
         $rules = static::getApplicableRules();

         $config->fixers($rules);

         return $config;
     }
267863
public function setEntityManager(EntityManager $entityManager)
	{
		$this->entityManager = $entityManager;
		$this->connection = $entityManager->getConnection();
		$bar = Debugger::getBar();
		$bar->addPanel($this);

		$config = $this->connection->getConfiguration();
		$logger = $config->getSQLLogger();

		if ($logger instanceof Doctrine\DBAL\Logging\LoggerChain) {
			$logger->addLogger($this);
		} else {
			$config->setSQLLogger($this);
		}
	}