_connFactory = new Doctrine_ConnectionFactory(); } public function setConfiguration(Doctrine_Configuration $config) { $this->_config = $config; } public function setEventManager(Doctrine_EventManager $eventManager) { $this->_eventManager = $eventManager; } public function createEntityManager($connParams, $name = null) { if ( ! $this->_config) { $this->_config = new Doctrine_Configuration(); } if ( ! $this->_eventManager) { $this->_eventManager = new Doctrine_EventManager(); } $conn = $this->_connFactory->createConnection($connParams); $conn->setEventManager($this->_eventManager); $conn->setConfiguration($this->_config); $em = new Doctrine_EntityManager($conn); $em->setEventManager($this->_eventManager); $em->setConfiguration($this->_config); if ($name !== null) { self::$_ems[$name] = $em; } else { self::$_ems[] = $em; } return $em; } /** * Gets the EntityManager that is responsible for the Entity. * Static method, so that ActiveEntities can look up the right EntityManager * without having a reference to the factory at hand. * * @param string $entityName * @return EntityManager * @throws Doctrine_EntityManager_Exception If a suitable manager can not be found. */ public static function getManager($entityName = null) { if ( ! is_null($entityName) && isset(self::$_emBindings[$entityName])) { $emName = self::$_emBindings[$entityName]; if (isset(self::$_ems[$emName])) { return self::$_ems[$emName]; } else { throw Doctrine_EntityManagerFactory_Exception::noManagerWithName($emName); } } else if (self::$_ems) { return current(self::$_ems); } else { throw Doctrine_EntityManagerFactory_Exception::noEntityManagerAvailable(); } } /** * Gets the EntityManager that is responsible for the Entity. * * @param unknown_type $entityName * @return unknown */ public function getEntityManager($entityName = null) { return self::getManager($entityName); } /** * Binds an Entity to a specific EntityManager. * * @param string $entityName * @param string $emName */ public function bindEntityToManager($entityName, $emName) { if (isset(self::$_emBindings[$entityName])) { throw Doctrine_EntityManagerFactory_Exception::entityAlreadyBound($entityName); } self::$_emBindings[$entityName] = $emName; } /** * Clears all bindings between Entities and EntityManagers. */ public function unbindAllManagers() { self::$_emBindings = array(); } /** * Releases all EntityManagers. * */ public function releaseAllManagers() { self::unbindAllManagers(); self::$_ems = array(); } public function releaseAllBindings() { self::$_emBindings = array(); } public function releaseEntityManager($name) { if (isset(self::$_ems[$name])) { unset(self::$_ems[$name]); return true; } return false; } } ?>