Creates a new EntityManager that operates on the given database connection
and uses the given Configuration and EventManager implementations.
protected __construct ( Doctrine\DBAL\Connection $conn, Doctrine\ORM\Configuration $config, Doctrine\Common\EventManager $eventManager ) | ||
$conn | Doctrine\DBAL\Connection | |
$config | Doctrine\ORM\Configuration | |
$eventManager | Doctrine\Common\EventManager |
protected function __construct(Doctrine\DBAL\Connection $conn, Doctrine\ORM\Configuration $config, Doctrine\Common\EventManager $eventManager) { parent::__construct($conn, $config, $eventManager); if ($conn instanceof Kdyby\Doctrine\Connection) { $conn->bindEntityManager($this); } }
public function __construct(EntityManagerProvider $provider) { $this->provider = $provider; $connection = $provider->getDriver()->connection(); $eventManager = $connection->getEventManager(); $config = $provider->getConfiguration()->config(); parent::__construct($connection, $config, $eventManager); }
/** * Do not use this constructor, use the factory method instead * @final * @param array $database_params in order to construct an EntityManager */ protected final function __construct(array $database_params) { $connection = DriverManager::getConnection($database_params); // constructing an EntityManager parent::__construct($connection, Setup::createAnnotationMetadataConfiguration(array(COGS), Config::get('development', false)), $connection->getEventManager()); if (isset($database_params['logging']) && $database_params['logging']) { $logger = new \Doctrine\DBAL\Logging\EchoSQLLogger(); $this->getConnection()->getConfiguration()->setSQLLogger($logger); } }
public function __construct(Connection $conn = NULL, Configuration $config = NULL, EventManager $eventManager = NULL) { $this->persisted = new ArrayCollection(); $this->removed = new ArrayCollection(); $this->merged = new ArrayCollection(); $this->detached = new ArrayCollection(); if (isset($conn)) { parent::__construct($conn, $config, $eventManager); } }
/** * Creates instance of EntityManager */ public function __construct() { $db = __DIR__ . '/Storage.db'; if (self::$useCopy) { $tempDir = sys_get_temp_dir(); $tempDb = $tempDir . '/erpk-common-6c814ae7-ceb3-4aeb-88f4-a42d8f05dcb6'; copy($db, $tempDb); $db = $tempDb; } $cache = new ArrayCache(); $config = new ORM\Configuration(); $config->setMetadataCacheImpl($cache); $driverImpl = $config->newDefaultAnnotationDriver(__DIR__ . '/Entity'); $config->setMetadataDriverImpl($driverImpl); $config->setQueryCacheImpl($cache); $config->setProxyDir(__DIR__ . '/Proxy'); $config->setProxyNamespace('Erpk\\Common\\Proxy'); $config->setAutoGenerateProxyClasses(AbstractProxyFactory::AUTOGENERATE_NEVER); $conn = DriverManager::getConnection(['driver' => 'pdo_sqlite', 'path' => $db], $config, new EventManager()); parent::__construct($conn, $config, $conn->getEventManager()); }
/** * @param string|mixed|\ $dsn * @param array $options * * @return AdapterInterface * * @link http://docs.doctrine-project.org/en/2.0.x/reference/configuration.html * @link http://docs.doctrine-project.org/en/latest/reference/tools.html * @link https://github.com/itmcd/StormIgniter/blob/master/app/libraries/DoctrineDb.php * @link http://framework.zend.com/manual/2.2/en/user-guide/database-and-models.html * @link http://piotrdeszynski.com/zend-framework-2-and-doctrine-2-integration.html * @link http://www.jasongrimes.org/2012/01/using-doctrine-2-in-zend-framework-2/#toc-update-the-album-controller-to-use-doctrine-instead-of-zend_db * @link http://framework.zend.com/manual/2.2/en/user-guide/database-and-models.html */ public function __construct($conn, $options = array()) { $isDev = Environment::isDev(); // @see Doctrine\ORM\EntityManager#create() $config = ArrayUtils::arrayMergeRecursiveRight($options, array('cache' => $isDev ? new Cache\ArrayCache() : new Cache\ApcCache(), 'queryCache' => $isDev ? new Cache\ArrayCache() : new Cache\ApcCache(), 'modelsProxiesPath' => getcwd() . '/cache/ModelProxies')); // create Configuration object if (is_array($options)) { $config = $this->renderConfig($options); if (!$config->getMetadataDriverImpl()) { throw ORMException::missingMappingDriverImpl(); } } // test EventManager object $eventManager = empty($options['eventManager']) ? new EventManager() : $options['eventManager']; switch (true) { case $conn instanceof \PDO: $conn = array('driver' => 'pdo_' . $conn->getAttribute(\PDO::ATTR_DRIVER_NAME), 'pdo' => $conn); $conn = \Doctrine\DBAL\DriverManager::getConnection($conn, $config, $eventManager); break; case is_string($conn): if (($pos = strpos($conn, ':')) !== false) { $driver = substr($conn, 0, $pos); // @TODO: must implement like this, but for now throws an error about not knowing the database // if ($driver !== 'oci8') { // $conn = array( // 'driver' => 'pdo_' . $driver, // 'pdo' => new \PDO($conn), // ); // } else { // $conn = $this->mapDsnToDoctrine($conn); // } // ^ by dragosc@itmcd.ro / temporary replacement untill we discover why \PDO doesn't work $dsn = new Dsn($conn); $conn = $this->mapDsnToDoctrine($dsn->parse()); if ($driver !== 'oci8') { $conn['driver'] = 'pdo_' . $conn['driver']; } // ^ END } $conn = \Doctrine\DBAL\DriverManager::getConnection($conn, $config, $eventManager); break; case is_array($conn): $conn = \Doctrine\DBAL\DriverManager::getConnection($conn, $config, $eventManager); break; case $conn instanceof Connection: if ($eventManager !== null && $conn->getEventManager() !== null) { throw ORMException::mismatchedEventManager(); } break; default: throw new AthemException\InvalidArgument("Invalid argument: " . json_encode($conn)); } // parent constructor // @see Doctrine\ORM\EntityManager#__construct() parent::__construct($conn, $config, $conn->getEventManager()); }
/** * Constructor * * @param App $app * @param Connection $conn * @param Configuration $config * @param EventManager $eventManager */ public function __construct(App $app, Connection $conn, Configuration $config, EventManager $eventManager) { parent::__construct($conn, $config, $eventManager); $this->app = $app; }
/** * @param Connection $conn * @param Configuration $config * @param EventManager $eventManager */ protected function __construct(Connection $conn, Configuration $config, EventManager $eventManager) { parent::__construct($conn, $config, $eventManager); $this->setParentPrivatePropertyValue('proxyFactory', new ProxyFactory($this, $config->getProxyDir(), $config->getProxyNamespace(), $config->getAutoGenerateProxyClasses())); $this->setParentPrivatePropertyValue('unitOfWork', new UnitOfWork($this)); }