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));
    }
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));
    }
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 ) ) ; }
Creates a new entity manager instance based on the given configuration.

@return \Doctrine\ORM\EntityManagerInterface The entity manager instance
Creates a new entity manager instance based on the given configuration .