protected function getDoctrine_Dbal_DefaultConnectionService() { $a = new \Doctrine\Common\EventManager(); $a->addEventSubscriber(new \Doctrine\DBAL\Event\Listeners\MysqlSessionInit('UTF8')); $a->addEventSubscriber(new \FOS\UserBundle\Entity\UserListener($this)); return $this->services['doctrine.dbal.default_connection'] = $this->get('doctrine.dbal.connection_factory')->createConnection(array('dbname' => 'S3', 'host' => 'localhost', 'port' => '', 'user' => 'root', 'password' => 'root', 'driver' => 'pdo_mysql', 'logging' => false, 'driverOptions' => array()), new \Doctrine\DBAL\Configuration(), $a, array()); }
/** * @brief Get default connection parameters for a given DBMS. * @param string $type DBMS type * @param array $additionalConnectionParams Additional connection parameters * @return \OC\DB\Connection */ public function getConnection($type, $additionalConnectionParams) { $normalizedType = $this->normalizeType($type); $eventManager = new \Doctrine\Common\EventManager(); switch ($normalizedType) { case 'mysql': // Send "SET NAMES utf8". Only required on PHP 5.3 below 5.3.6. // See http://stackoverflow.com/questions/4361459/php-pdo-charset-set-names#4361485 $eventManager->addEventSubscriber(new \Doctrine\DBAL\Event\Listeners\MysqlSessionInit()); break; case 'oci': $eventManager->addEventSubscriber(new \Doctrine\DBAL\Event\Listeners\OracleSessionInit()); break; case 'sqlite3': $eventManager->addEventSubscriber(new SQLiteSessionInit()); break; } $connection = \Doctrine\DBAL\DriverManager::getConnection(array_merge($this->getDefaultConnectionParams($type), $additionalConnectionParams), new \Doctrine\DBAL\Configuration(), $eventManager); switch ($normalizedType) { case 'sqlite3': // Sqlite doesn't handle query caching and schema changes // TODO: find a better way to handle this /** @var $connection \OC\DB\Connection */ $connection->disableQueryStatementCaching(); break; } return $connection; }
public function setUp() { if (version_compare(\Doctrine\Common\Version::VERSION, '2.1.0RC4-DEV', '>=')) { $this->markTestSkipped('Doctrine common is 2.1.0RC4-DEV version, skipping.'); } else { if (version_compare(\Doctrine\Common\Version::VERSION, '2.1.0-BETA3-DEV', '>=')) { $reader = new AnnotationReader(); $reader->setDefaultAnnotationNamespace('Doctrine\\ORM\\Mapping\\'); $reader->setIgnoreNotImportedAnnotations(true); $reader->setAnnotationNamespaceAlias('Gedmo\\Mapping\\Annotation\\', 'gedmo'); $reader->setEnableParsePhpImports(false); $reader->setAutoloadAnnotations(true); $reader = new CachedReader(new \Doctrine\Common\Annotations\IndexedReader($reader), new ArrayCache()); } else { $reader = new AnnotationReader(); $reader->setAutoloadAnnotations(true); $reader->setAnnotationNamespaceAlias('Gedmo\\Mapping\\Annotation\\', 'gedmo'); $reader->setDefaultAnnotationNamespace('Doctrine\\ORM\\Mapping\\'); } } $config = new \Doctrine\ORM\Configuration(); $config->setProxyDir(TESTS_TEMP_DIR); $config->setProxyNamespace('Gedmo\\Mapping\\Proxy'); $config->setMetadataDriverImpl(new AnnotationDriver($reader)); $conn = array('driver' => 'pdo_sqlite', 'memory' => true); //$config->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger()); $evm = new \Doctrine\Common\EventManager(); $this->timestampable = new \Gedmo\Timestampable\TimestampableListener(); $evm->addEventSubscriber($this->timestampable); $this->em = \Doctrine\ORM\EntityManager::create($conn, $config, $evm); $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->em); $schemaTool->dropSchema(array()); $schemaTool->createSchema(array($this->em->getClassMetadata(self::ARTICLE))); }
/** * Gets a <b>real</b> database connection using the following parameters * of the $GLOBALS array: * * 'db_type' : The name of the Doctrine DBAL database driver to use. * 'db_username' : The username to use for connecting. * 'db_password' : The password to use for connecting. * 'db_host' : The hostname of the database to connect to. * 'db_name' : The name of the database to connect to. * 'db_port' : The port of the database to connect to. * * Usually these variables of the $GLOBALS array are filled by PHPUnit based * on an XML configuration file. If no such parameters exist, an SQLite * in-memory database is used. * * IMPORTANT: * 1) Each invocation of this method returns a NEW database connection. * 2) The database is dropped and recreated to ensure it's clean. * * @return Doctrine\DBAL\Connection The database connection instance. */ public static function getConnection() { if (isset($GLOBALS['db_type'], $GLOBALS['db_username'], $GLOBALS['db_password'], $GLOBALS['db_host'], $GLOBALS['db_name'], $GLOBALS['db_port']) && isset($GLOBALS['tmpdb_type'], $GLOBALS['tmpdb_username'], $GLOBALS['tmpdb_password'], $GLOBALS['tmpdb_host'], $GLOBALS['tmpdb_name'], $GLOBALS['tmpdb_port'])) { $realDbParams = array('driver' => $GLOBALS['db_type'], 'user' => $GLOBALS['db_username'], 'password' => $GLOBALS['db_password'], 'host' => $GLOBALS['db_host'], 'dbname' => $GLOBALS['db_name'], 'port' => $GLOBALS['db_port']); $tmpDbParams = array('driver' => $GLOBALS['tmpdb_type'], 'user' => $GLOBALS['tmpdb_username'], 'password' => $GLOBALS['tmpdb_password'], 'host' => $GLOBALS['tmpdb_host'], 'dbname' => $GLOBALS['tmpdb_name'], 'port' => $GLOBALS['tmpdb_port']); // Connect to tmpdb in order to drop and create the real test db. $tmpConn = \Doctrine\DBAL\DriverManager::getConnection($tmpDbParams); $realConn = \Doctrine\DBAL\DriverManager::getConnection($realDbParams); $dbname = $realConn->getDatabase(); $realConn->close(); $tmpConn->getSchemaManager()->dropDatabase($dbname); $tmpConn->getSchemaManager()->createDatabase($dbname); $tmpConn->close(); $eventManager = null; if (isset($GLOBALS['db_event_subscribers'])) { $eventManager = new \Doctrine\Common\EventManager(); foreach (explode(",", $GLOBALS['db_event_subscribers']) as $subscriberClass) { $subscriberInstance = new $subscriberClass(); $eventManager->addEventSubscriber($subscriberInstance); } } $conn = \Doctrine\DBAL\DriverManager::getConnection($realDbParams, null, $eventManager); } else { $params = array('driver' => 'pdo_sqlite', 'memory' => true); $conn = \Doctrine\DBAL\DriverManager::getConnection($params); } return $conn; }
/** * @brief Get default connection parameters for a given DBMS. * @param string $type DBMS type * @param array $additionalConnectionParams Additional connection parameters * @return \OC\DB\Connection */ public function getConnection($type, $additionalConnectionParams) { $normalizedType = $this->normalizeType($type); $eventManager = new \Doctrine\Common\EventManager(); switch ($normalizedType) { case 'mysql': // Send "SET NAMES utf8". Only required on PHP 5.3 below 5.3.6. // See http://stackoverflow.com/questions/4361459/php-pdo-charset-set-names#4361485 $eventManager->addEventSubscriber(new MysqlSessionInit()); $eventManager->addEventSubscriber(new SQLSessionInit("SET SESSION AUTOCOMMIT=1")); break; case 'oci': $eventManager->addEventSubscriber(new OracleSessionInit()); // the driverOptions are unused in dbal and need to be mapped to the parameters if (isset($additionalConnectionParams['driverOptions'])) { $additionalConnectionParams = array_merge($additionalConnectionParams, $additionalConnectionParams['driverOptions']); } break; case 'sqlite3': $journalMode = $additionalConnectionParams['sqlite.journal_mode']; $additionalConnectionParams['platform'] = new OCSqlitePlatform(); $eventManager->addEventSubscriber(new SQLiteSessionInit(true, $journalMode)); break; } $connection = \Doctrine\DBAL\DriverManager::getConnection(array_merge($this->getDefaultConnectionParams($type), $additionalConnectionParams), new \Doctrine\DBAL\Configuration(), $eventManager); return $connection; }
public function get($connection, $prefix = 'cms') { $paths = array(realpath(__DIR__ . '/../Entity')); $isDevMode = false; $config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode, null, null, false); $eventManager = new \Doctrine\Common\EventManager(); $tablePrefix = new Prefix($prefix); $eventManager->addEventListener(Events::loadClassMetadata, $tablePrefix); return EntityManager::create($connection, $config, $eventManager); }
public function setUp() { $config = new \Doctrine\ORM\Configuration(); $config->setProxyDir(TESTS_TEMP_DIR); $config->setProxyNamespace('Gedmo\\Mapping\\Proxy'); $config->setMetadataDriverImpl(new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($_ENV['annotation_reader'])); $conn = array('driver' => 'pdo_sqlite', 'memory' => true); $evm = new \Doctrine\Common\EventManager(); $this->timestampable = new \Gedmo\Timestampable\TimestampableListener(); $this->timestampable->setAnnotationReader($_ENV['annotation_reader']); $evm->addEventSubscriber($this->timestampable); $this->em = \Doctrine\ORM\EntityManager::create($conn, $config, $evm); }
protected function createEntityManager() { $config = new \Doctrine\ORM\Configuration(); $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver()); $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache()); $config->setQueryCacheImpl(new \Doctrine\Common\Cache\ArrayCache()); $config->setProxyDir(__DIR__ . '/Proxies'); $config->setProxyNamespace('DoctrineExtensions\\PHPUnit\\Proxies'); $eventManager = new \Doctrine\Common\EventManager(); $eventManager->addEventListener(array("preTestSetUp", "postTestSetUp"), $this); $conn = array('driver' => 'pdo_sqlite', 'memory' => true); return \Doctrine\ORM\EntityManager::create($conn, $config, $eventManager); }
/** * @param Configuration $ormConfiguration * @param Config $dbConfig * @return EntityManager */ public static function configure($dbConfig, Configuration $ormConfiguration) { Type::overrideType("datetime", 'Doctrine\\DBAL\\Types\\VarDateTimeType'); //новый биллинг семь знаков после секунды $ormConfiguration->setProxyDir(__DIR__ . '/Proxy'); $ormConfiguration->setProxyNamespace('Billing\\Proxy'); //$config->setSQLLogger(new Core\HtmlSqlLogger()); $eventManager = new \Doctrine\Common\EventManager(); $eventManager->addEventSubscriber(new \Doctrine\DBAL\Event\Listeners\SQLSessionInit('use billing35;')); //?$eventManager->addEventSubscriber($loggableListener); //dblib:host=217.114.191.214;dbname=planneddebtorsrollcall;','obzvon','qwerty123! $dbConfig = array("driver" => "pdo_sqlsrv", "user" => $dbConfig->user, "password" => $dbConfig->password, "host" => strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' ? "217.114.191.214" : "ipsoft", "dbname" => $dbConfig->database, "driverOptions" => array("CharacterSet" => "UTF-8")); self::$_em = EntityManager::create($dbConfig, $ormConfiguration, $eventManager); return self::$_em; }
/** @override */ public function findOne(array $query = array(), array $fields = array()) { if ($this->class->hasDiscriminator() && !isset($query[$this->class->discriminatorField['name']])) { $discriminatorValues = $this->getClassDiscriminatorValues($this->class); $query[$this->class->discriminatorField['name']] = array('$in' => $discriminatorValues); } $query = $this->prepareQuery($query); if ($this->eventManager->hasListeners(CollectionEvents::preFindOne)) { $this->eventManager->dispatchEvent(CollectionEvents::preFindOne, new CollectionEventArgs($this, $query)); } if ($this->loggerCallable) { $this->log(array('findOne' => true, 'query' => $query, 'fields' => $fields)); } if ($this->mongoCollection instanceof \MongoGridFS) { $file = $this->mongoCollection->findOne($query); $data = $file->file; $data[$this->class->file] = $file; return $data; } $result = $this->mongoCollection->findOne($query, $fields); if ($this->eventManager->hasListeners(CollectionEvents::postFindOne)) { $this->eventManager->dispatchEvent(CollectionEvents::postFindOne, new CollectionEventArgs($this, $result)); } return $result; }
public function setUp() { $config = new \Doctrine\ORM\Configuration(); $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache()); $config->setQueryCacheImpl(new \Doctrine\Common\Cache\ArrayCache()); $config->setProxyDir(TESTS_TEMP_DIR); $config->setProxyNamespace('Gedmo\\Mapping\\Proxy'); $chainDriverImpl = new DriverChain(); $chainDriverImpl->addDriver(new YamlDriver(array(__DIR__ . '/Driver/Yaml')), 'Mapping\\Fixture\\Yaml'); $config->setMetadataDriverImpl($chainDriverImpl); $conn = array('driver' => 'pdo_sqlite', 'memory' => true); //$config->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger()); $evm = new \Doctrine\Common\EventManager(); $evm->addEventSubscriber(new TimestampableListener()); $this->em = \Doctrine\ORM\EntityManager::create($conn, $config, $evm); }
public function setUp() { $config = new \Doctrine\ORM\Configuration(); $config->setProxyDir(TESTS_TEMP_DIR); $config->setProxyNamespace('Gedmo\\Mapping\\Proxy'); $config->setMetadataDriverImpl(new CustomDriver()); $conn = array('driver' => 'pdo_sqlite', 'memory' => true); $evm = new \Doctrine\Common\EventManager(); $this->timestampable = new \Gedmo\Timestampable\TimestampableListener(); $this->timestampable->setAnnotationReader($_ENV['annotation_reader']); $evm->addEventSubscriber($this->timestampable); $this->em = \Doctrine\ORM\EntityManager::create($conn, $config, $evm); $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->em); $schemaTool->dropSchema(array()); $schemaTool->createSchema(array($this->em->getClassMetadata('Mapping\\Fixture\\Unmapped\\Timestampable'))); }
public function setUp() { $config = new \Doctrine\ORM\Configuration(); $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache()); $config->setQueryCacheImpl(new \Doctrine\Common\Cache\ArrayCache()); $config->setProxyDir(TESTS_TEMP_DIR); $config->setProxyNamespace('Gedmo\\Mapping\\Proxy'); $chainDriverImpl = new DriverChain(); $chainDriverImpl->addDriver(new YamlDriver(array(__DIR__ . '/Driver/Yaml')), 'Mapping\\Fixture\\Yaml'); $reader = new \Doctrine\Common\Annotations\AnnotationReader(); \Doctrine\Common\Annotations\AnnotationRegistry::registerAutoloadNamespace('Gedmo\\Mapping\\Annotation', VENDOR_PATH . '/../lib'); $chainDriverImpl->addDriver(new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader), 'Mapping\\Fixture'); $config->setMetadataDriverImpl($chainDriverImpl); $conn = array('driver' => 'pdo_sqlite', 'memory' => true); $evm = new \Doctrine\Common\EventManager(); $evm->addEventSubscriber(new SluggableListener()); $this->em = \Doctrine\ORM\EntityManager::create($conn, $config, $evm); }
public static function create(DI\Container $container) { $config = new \Doctrine\ORM\Configuration(); $cache = new \Doctrine\Common\Cache\ArrayCache(); $config->setMetadataCacheImpl($cache); $driverImpl = $config->newDefaultAnnotationDriver($container->params['appDir'] . '/models/Entities'); $config->setMetadataDriverImpl($driverImpl); $config->setQueryCacheImpl($cache); $config->setProxyDir($container->params['tempDir'] . '/Proxies'); $config->setProxyNamespace('Tatami\\Proxies'); $config->setAutoGenerateProxyClasses(true); /* if ($container->params['productionMode'] == true) { $config->setAutoGenerateProxyClasses(true); } else { $config->setAutoGenerateProxyClasses(false); } var_dump() * */ try { $dbConfig = $container->params['database']; if ($dbConfig['prefix'] != '') { $evm = new \Doctrine\Common\EventManager(); // Table Prefix $tablePrefix = new \DoctrineExtensions\TablePrefix($dbConfig['prefix']); $evm->addEventListener(\Doctrine\ORM\Events::loadClassMetadata, $tablePrefix); $em = EntityManager::create($dbConfig, $config, $evm); } else { $em = EntityManager::create($dbConfig, $config); } $validator = $container->getService('validator'); $em->setValidator($validator); return $em; } catch (PDOException $e) { echo $e->getMessage(); } catch (\Doctrine\DBAL\DBALException $e) { echo $e->getMessage(); } }
/** * @brief Get default connection parameters for a given DBMS. * @param string $type DBMS type * @param array $additionalConnectionParams Additional connection parameters * @return \OC\DB\Connection */ public function getConnection($type, $additionalConnectionParams) { $normalizedType = $this->normalizeType($type); $eventManager = new \Doctrine\Common\EventManager(); switch ($normalizedType) { case 'mysql': // Send "SET NAMES utf8". Only required on PHP 5.3 below 5.3.6. // See http://stackoverflow.com/questions/4361459/php-pdo-charset-set-names#4361485 $eventManager->addEventSubscriber(new \Doctrine\DBAL\Event\Listeners\MysqlSessionInit()); break; case 'oci': $eventManager->addEventSubscriber(new \Doctrine\DBAL\Event\Listeners\OracleSessionInit()); break; case 'sqlite3': $eventManager->addEventSubscriber(new SQLiteSessionInit()); break; } $connection = \Doctrine\DBAL\DriverManager::getConnection(array_merge($this->getDefaultConnectionParams($type), $additionalConnectionParams), new \Doctrine\DBAL\Configuration(), $eventManager); return $connection; }
public function setUp() { $config = new \Doctrine\ORM\Configuration(); $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache()); $config->setQueryCacheImpl(new \Doctrine\Common\Cache\ArrayCache()); $config->setProxyDir(TESTS_TEMP_DIR); $config->setProxyNamespace('Gedmo\\Mapping\\Proxy'); $chainDriverImpl = new DriverChain(); $chainDriverImpl->addDriver(new YamlDriver(array(__DIR__ . '/Driver/Yaml')), 'Mapping\\Fixture\\Yaml'); $config->setMetadataDriverImpl($chainDriverImpl); $conn = array('driver' => 'pdo_sqlite', 'memory' => true); //$config->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger()); $evm = new \Doctrine\Common\EventManager(); $this->translatableListener = new TranslationListener(); $this->translatableListener->setTranslatableLocale('en_us'); $evm->addEventSubscriber($this->translatableListener); $this->em = \Doctrine\ORM\EntityManager::create($conn, $config, $evm); $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->em); $schemaTool->dropSchema(array()); $schemaTool->createSchema(array($this->em->getClassMetadata(self::TEST_YAML_ENTITY_CLASS))); }
public static function init() { $instance = self::getInstance(); $conf = self::conf(); require_once $conf->root_dir . '/system/lib/Doctrine/Common/ClassLoader.php'; // Set up class loading $classLoader = new \Doctrine\Common\ClassLoader('Doctrine', $conf->root_dir . '/system/lib'); $classLoader->register(); $classLoader = new \Doctrine\Common\ClassLoader('Doctrine\\ORM', realpath(__DIR__ . '/../../lib')); $classLoader->register(); $classLoader = new \Doctrine\Common\ClassLoader('Doctrine\\DBAL', realpath(__DIR__ . '/../../lib/vendor/doctrine-dbal/lib')); $classLoader->register(); $classLoader = new \Doctrine\Common\ClassLoader('Doctrine\\Common', realpath(__DIR__ . '/../../lib/vendor/doctrine-common/lib')); $classLoader->register(); // Set up caches $config = new \Doctrine\ORM\Configuration(); $cache = new \Doctrine\Common\Cache\ArrayCache(); $config->setMetadataCacheImpl($cache); $driverImpl = $config->newDefaultAnnotationDriver(array($conf->root_dir . '/system/Entities')); $config->setMetadataDriverImpl($driverImpl); $config->setQueryCacheImpl($cache); // Proxy configuration $config->setProxyDir($conf->root_dir . '/system/models'); $config->setProxyNamespace('Proxies'); // Set up logger // $logger = new EchoSQLLogger; // $config->setSQLLogger($logger); $config->setAutoGenerateProxyClasses(true); // Database connection information $connectionParams = array('dbname' => $conf->db_name, 'user' => $conf->db_username, 'password' => $conf->db_password, 'host' => $conf->db_hostname, 'driver' => 'pdo_' . $conf->db_driver, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'); // Create EntityManager $instance->db = \Doctrine\ORM\EntityManager::create($connectionParams, $config); // Table Prefix $evm = new \Doctrine\Common\EventManager(); $tablePrefix = new \Doctrine\Extensions\TablePrefix($conf->db_prefix); $evm->addEventListener(\Doctrine\ORM\Events::loadClassMetadata, $tablePrefix); // Create EntityManager $instance->em = \Doctrine\ORM\EntityManager::create($connectionParams, $config, $evm); }
/** @override */ public function findOne(array $query = array(), array $fields = array()) { if ($this->_eventManager->hasListeners(CollectionEvents::preFindOne)) { $this->_eventManager->dispatchEvent(CollectionEvents::preFindOne, new CollectionEventArgs($this, $query)); } if ($this->_loggerCallable) { $this->log(array('findOne' => true, 'query' => $query, 'fields' => $fields)); } if ($this->_mongoCollection instanceof \MongoGridFS) { $file = $this->_mongoCollection->findOne($query); $data = $file->file; $data[$this->_class->file] = $file; return $data; } $result = $this->_mongoCollection->findOne($query, $fields); if ($this->_eventManager->hasListeners(CollectionEvents::postFindOne)) { $this->_eventManager->dispatchEvent(CollectionEvents::postFindOne, new CollectionEventArgs($this, $result)); } return $result; }
public function setUp() { $config = new \Doctrine\ORM\Configuration(); $config->setProxyDir(TESTS_TEMP_DIR); $config->setProxyNamespace('Gedmo\\Mapping\\Proxy'); //$this->markTestSkipped('Skipping according to a bug in annotation reader creation.'); $config->setMetadataDriverImpl(new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($_ENV['annotation_reader'])); $conn = array('driver' => 'pdo_sqlite', 'memory' => true); $evm = new \Doctrine\Common\EventManager(); $evm->addEventSubscriber(new \Gedmo\Translatable\TranslatableListener()); $this->timestampable = new \Gedmo\Timestampable\TimestampableListener(); $evm->addEventSubscriber($this->timestampable); $evm->addEventSubscriber(new \Gedmo\Sluggable\SluggableListener()); $evm->addEventSubscriber(new \Gedmo\Tree\TreeListener()); $this->em = \Doctrine\ORM\EntityManager::create($conn, $config, $evm); $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->em); $schemaTool->dropSchema(array()); $schemaTool->createSchema(array($this->em->getClassMetadata(self::TEST_ENTITY_CATEGORY), $this->em->getClassMetadata(self::TEST_ENTITY_TRANSLATION))); }
// NOTE: driver for application Entity can be different, Yaml, Xml or whatever // register annotation driver for our application Entity fully qualified namespace $driverChain->addDriver($annotationDriver, 'Entity'); // general ORM configuration $config = new Doctrine\ORM\Configuration(); $config->setProxyDir(sys_get_temp_dir()); $config->setProxyNamespace('Proxy'); $config->setAutoGenerateProxyClasses(false); // this can be based on production config. // register metadata driver $config->setMetadataDriverImpl($driverChain); // use our allready initialized cache driver $config->setMetadataCacheImpl($cache); $config->setQueryCacheImpl($cache); // Third, create event manager and hook prefered extension listeners $evm = new Doctrine\Common\EventManager(); // gedmo extension listeners // sluggable $sluggableListener = new Gedmo\Sluggable\SluggableListener(); // you should set the used annotation reader to listener, to avoid creating new one for mapping drivers $sluggableListener->setAnnotationReader($cachedAnnotationReader); $evm->addEventSubscriber($sluggableListener); // tree $treeListener = new Gedmo\Tree\TreeListener(); $treeListener->setAnnotationReader($cachedAnnotationReader); $evm->addEventSubscriber($treeListener); // loggable, not used in example //$loggableListener = new Gedmo\Loggable\LoggableListener; //$loggableListener->setAnnotationReader($cachedAnnotationReader); //$loggableListener->setUsername('admin'); //$evm->addEventSubscriber($loggableListener);
/** * Gets the 'doctrine.dbal.default_connection.event_manager' service. * * This service is shared. * This method always returns the same instance of the service. * * @return Doctrine\Common\EventManager A Doctrine\Common\EventManager instance. */ protected function getDoctrine_Dbal_DefaultConnection_EventManagerService() { $this->services['doctrine.dbal.default_connection.event_manager'] = $instance = new \Doctrine\Common\EventManager(); $instance->addEventSubscriber(new \Doctrine\DBAL\Event\Listeners\MysqlSessionInit('UTF8')); return $instance; }
/** * Setup Doctrine ORM */ protected function setupDoctrine() { //setup doctrine $doctrineConfig = new \Doctrine\ORM\Configuration(); //We use different caching and proxy settings in Development status if ($this->_config->getStatus() == 'DEVELOPMENT') { $doctrineConfig->setAutoGenerateProxyClasses(true); $doctrineConfig->setProxyDir($this->_config->getVarPath() . '/tmp'); } else { $doctrineConfig->setAutoGenerateProxyClasses(false); $doctrineConfig->setProxyDir(__DIR__ . '/Entity/Proxy'); if (!extension_loaded('apc')) { throw new Exception('APC cache is required, but was not available.'); } } $driver = $doctrineConfig->newDefaultAnnotationDriver(array(__DIR__ . "/Entity")); $doctrineConfig->setMetadataDriverImpl($driver); $doctrineConfig->setProxyNamespace('Jazzee\\Entity\\Proxy'); $doctrineConfig->setMetadataCacheImpl(self::getCache()); $doctrineConfig->setQueryCacheImpl(self::getCache()); $doctrineConfig->setResultCacheImpl(self::getCache()); $connectionParams = array('dbname' => $this->_config->getDbName(), 'user' => $this->_config->getDbUser(), 'password' => $this->_config->getDbPassword(), 'host' => $this->_config->getDbHost(), 'port' => $this->_config->getDbPort(), 'driver' => $this->_config->getDbDriver()); $previewStore = $this->_session->getStore('preview', 3600); if ($previewStore->check('previewdbpath')) { $this->_previewMode = true; $connectionParams['driver'] = 'pdo_sqlite'; $connectionParams['path'] = $previewStore->get('previewdbpath'); $exitLink = $this->path('preview/end'); $this->addMessage('info', "You are in preview mode, the changes you make will not be saved. You can exit preview mode by visiting <a href='{$exitLink}'>{$exitLink}</a>"); } $eventManager = new \Doctrine\Common\EventManager(); $eventManager->addEventListener(array(\Doctrine\ORM\Events::onFlush), new \Jazzee\Entity\ApplicantEventListener()); $eventManager->addEventListener(array(\Doctrine\ORM\Events::onFlush, \Doctrine\ORM\Events::preRemove), new \Jazzee\Entity\AnswerEventListener()); $eventManager->addEventListener(array(\Doctrine\ORM\Events::onFlush), new \Jazzee\Entity\ApplicationEventListener()); $this->_em = \Doctrine\ORM\EntityManager::create($connectionParams, $doctrineConfig, $eventManager); $this->_em->getConfiguration()->addCustomHydrationMode('ApplicantArrayHydrator', 'Jazzee\\Entity\\ApplicantArrayHydrator'); $this->_em->getConfiguration()->addCustomHydrationMode('ApplicantDisplayHydrator', 'Jazzee\\Entity\\ApplicantDisplayHydrator'); $this->_em->getConfiguration()->addCustomHydrationMode('ApplicantPDFTemplateHydrator', 'Jazzee\\Entity\\ApplicantPDFTemplateHydrator'); \Jazzee\Globals::setEntityManager($this->_em); }
/** * Gets the 'doctrine.dbal.default_connection' service. * * This service is shared. * This method always returns the same instance of the service. * * @return stdClass A stdClass instance. */ protected function getDoctrine_Dbal_DefaultConnectionService() { $a = new \Doctrine\DBAL\Configuration(); $a->setSQLLogger(new \Symfony\Bridge\Doctrine\Logger\DbalLogger($this->get('monolog.logger.doctrine'))); $b = new \Doctrine\Common\EventManager(); $b->addEventSubscriber(new \Doctrine\DBAL\Event\Listeners\MysqlSessionInit('UTF8')); return $this->services['doctrine.dbal.default_connection'] = $this->get('doctrine.dbal.connection_factory')->createConnection(array('dbname' => 'requirement', 'host' => 'localhost', 'port' => '', 'user' => 'root', 'password' => 'root', 'driver' => 'pdo_mysql', 'driverOptions' => array()), $a, $b, array()); }
}); $app['cache-filesystem'] = $app->share(function ($app) { $baseCacheDirectory = __DIR__ . '/cache'; return function ($cacheType) use($baseCacheDirectory) { $cacheDirectory = $baseCacheDirectory . '/' . $cacheType; $cache = new \Doctrine\Common\Cache\FilesystemCache($cacheDirectory); return $cache; }; }); $app['cache'] = $app->share(function (Application $app) { $activeCacheType = $app['config']['cache']['active'] ?: 'filesystem'; $cacheServiceName = 'cache-' . $activeCacheType; return $app[$cacheServiceName]; }); $app['dbal_connection'] = $app->share(function ($app) { $eventManager = new \Doctrine\Common\EventManager(); $sqlMode = 'NO_ENGINE_SUBSTITUTION,STRICT_ALL_TABLES'; $query = "SET SESSION sql_mode = '{$sqlMode}'"; $eventManager->addEventSubscriber(new \Doctrine\DBAL\Event\Listeners\SQLSessionInit($query)); $connection = \Doctrine\DBAL\DriverManager::getConnection($app['config']['database'], null, $eventManager); return $connection; }); $app['event_store'] = $app->share(function ($app) { return new \Broadway\EventStore\DBALEventStore($app['dbal_connection'], $app['eventstore_payload_serializer'], new \Broadway\Serializer\SimpleInterfaceSerializer(), 'events'); }); $app['event_jsonld_repository'] = $app->share(function ($app) { $cachedRepository = new \CultuurNet\UDB3\Doctrine\Event\ReadModel\CacheDocumentRepository($app['event_jsonld_cache']); $broadcastingRepository = new \CultuurNet\UDB3\Event\ReadModel\BroadcastingDocumentRepositoryDecorator($cachedRepository, $app['event_bus'], new \CultuurNet\UDB3\Event\ReadModel\JSONLD\EventFactory()); return $broadcastingRepository; }); $app['event_jsonld_cache'] = $app->share(function (Application $app) {
protected function createEventManager() { $metadataService = new Tx_Doctrine2_Mapping_TYPO3MetadataService(); $metadataService->injectReflectionService($this->reflectionService); $this->dataMapFactory->injectReflectionService($this->reflectionService); $metadataService->injectDataMapFactory($this->dataMapFactory); $metadataListener = new Tx_Doctrine2_Mapping_TYPO3TCAMetadataListener(); $metadataListener->injectMetadataService($metadataService); $evm = new \Doctrine\Common\EventManager(); $evm->addEventSubscriber($metadataListener); if ($this->objectManager) { $storagePidListener = $this->objectManager->get('Tx_Doctrine2_Persistence_StoragePidListener'); $evm->addEventSubscriber($storagePidListener); } $this->configureEventManager($evm); return $evm; }
use Cx\Update\UpdatePageEventListener as PageEventListener; require_once UPDATE_PATH . '/core/UpdatePageEventListener.class.php'; $_DBCONFIG = \Env::get('dbconfig'); $doctrineDir = ASCMS_LIBRARY_PATH . '/doctrine/'; require_once UPDATE_PATH . '/lib/FRAMEWORK/DBG/DoctrineSQLLogger.class.php'; $config = new \Doctrine\ORM\Configuration(); $cache = new \Doctrine\Common\Cache\ArrayCache(); $config->setMetadataCacheImpl($cache); $config->setQueryCacheImpl($cache); $config->setProxyDir(ASCMS_MODEL_PROXIES_PATH); $config->setProxyNamespace('Cx\\Model\\Proxies'); $config->setAutoGenerateProxyClasses(false); $connection = new \PDO('mysql:dbname=' . $_DBCONFIG['database'] . ';' . (!empty($_DBCONFIG['charset']) ? 'charset=' . $_DBCONFIG['charset'] . ';' : '') . 'host=' . $_DBCONFIG['host'], $_DBCONFIG['user'], $_DBCONFIG['password'], array(\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES ' . $_DBCONFIG['charset'])); $connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT); $connectionOptions = array('pdo' => $connection); $evm = new \Doctrine\Common\EventManager(); $chainDriverImpl = new \Doctrine\ORM\Mapping\Driver\DriverChain(); $driverImpl = new \Doctrine\ORM\Mapping\Driver\YamlDriver(ASCMS_MODEL_PATH . '/yml'); $chainDriverImpl->addDriver($driverImpl, 'Cx\\Model'); $driverImpl = new \Doctrine\ORM\Mapping\Driver\YamlDriver(ASCMS_CORE_PATH . '/ContentManager/Model/Yaml'); $chainDriverImpl->addDriver($driverImpl, 'Cx\\Core\\ContentManager'); //loggable stuff $loggableDriverImpl = $config->newDefaultAnnotationDriver(array(UPDATE_CORE, $doctrineDir . 'Gedmo/Loggable/Entity')); $chainDriverImpl->addDriver($loggableDriverImpl, 'Gedmo\\Loggable'); $loggableListener = new \Cx\Update\core\LoggableListener(); $evm->addEventSubscriber($loggableListener); \Env::set('loggableListener', $loggableListener); //tree stuff $treeListener = new \Gedmo\Tree\TreeListener(); $evm->addEventSubscriber($treeListener); $config->setMetadataDriverImpl($chainDriverImpl);
/** * Gets the 'doctrine.odm.mongodb.event_manager' service. * * This service is shared. * This method always returns the same instance of the service. * * @return Doctrine\Common\EventManager A Doctrine\Common\EventManager instance. */ protected function getDoctrine_Odm_Mongodb_EventManagerService() { $this->services['doctrine.odm.mongodb.event_manager'] = $instance = new \Doctrine\Common\EventManager(); $instance->addEventSubscriber(new \FOS\UserBundle\Document\UserListener($this)); return $instance; }
/** * Initialize auto loader of Doctrine. * * @return \Doctrine\ORM\EntityManager */ public static function init($config) { self::optionsContainDSN($config); $vendor = VENDOR_PATH . '/doctrine/common/lib/'; // ensure doctrine2 exists in the libraries folder if (is_file($vendor . 'Doctrine/Common/ClassLoader.php') === false) { throw new \Koch\Exception\Exception('Doctrine2 not found. Check Libraries Folder.', 100); } // get isolated loader require $vendor . 'Doctrine/Common/ClassLoader.php'; // setup autoloaders with namespace and path to search in $classLoader = new \Doctrine\Common\ClassLoader('Doctrine', VENDOR_PATH); $classLoader->register(); $classLoader = new \Doctrine\Common\ClassLoader('Symfony', VENDOR_PATH . 'Doctrine/Symfony'); $classLoader->register(); $classLoader = new \Doctrine\Common\ClassLoader('Entity', APPLICATION_PATH . 'Doctrine'); $classLoader->register(); $classLoader = new \Doctrine\Common\ClassLoader('Repository', APPLICATION_PATH . 'Doctrine'); $classLoader->register(); $classLoader = new \Doctrine\Common\ClassLoader('Proxy', APPLICATION_PATH . 'Doctrine'); $classLoader->register(); // include Doctrine Extensions $classLoader = new \Doctrine\Common\ClassLoader('doctrine-extensions', VENDOR_PATH . 'gedmo/doctrine-extensions/lib/Gedmo'); $classLoader->register(); $classLoader = new \Doctrine\Common\ClassLoader('DoctrineExtensions', VENDOR_PATH . 'beberlei/DoctrineExtensions/lib'); $classLoader->register(); // fetch doctrine config handler for configuring $D2Config = new \Doctrine\ORM\Configuration(); // fetch cache driver - APC in production and Array in development mode if (extension_loaded('apc') and DEBUG === false) { $cache = new \Doctrine\Common\Cache\ApcCache(); } else { $cache = new \Doctrine\Common\Cache\ArrayCache(); } // set cache driver $D2Config->setMetadataCacheImpl($cache); $D2Config->setQueryCacheImpl($cache); // set annotation driver for entities $D2Config->setMetadataDriverImpl($D2Config->newDefaultAnnotationDriver(self::getModelPathsForAllModules())); /* * This is slow like hell, because getAllClassNames traverses all * dirs and files and includes them. Its a workaround, till i find * a better way to acquire all the models. * @todo optimize this for performance reasons */ $D2Config->getMetadataDriverImpl()->getAllClassNames(); #\Koch\Debug\Debug::firebug($config->getMetadataDriverImpl()->getAllClassNames()); // set proxy dirs $D2Config->setProxyDir(APPLICATION_PATH . 'Doctrine'); $D2Config->setProxyNamespace('Proxy'); // regenerate proxies only in debug and not in production mode if (DEBUG === true) { $D2Config->setAutoGenerateProxyClasses(true); } else { $D2Config->setAutoGenerateProxyClasses(false); } // use main configuration values for setting up the connection $connectionOptions = ['driver' => $config['database']['driver'], 'user' => $config['database']['user'], 'password' => $config['database']['password'], 'dbname' => $config['database']['dbname'], 'host' => $config['database']['host'], 'charset' => $config['database']['charset'], 'driverOptions' => ['charset' => $config['database']['charset']]]; // set up Logger #$config->setSqlLogger(new \Doctrine\DBAL\Logging\EchoSqlLogger); /* * Events */ $event = new \Doctrine\Common\EventManager(); /* * Database Prefix * * The constant definition is for building (raw) sql queries manually. * The database prefixing is registered via an event. */ define('DB_PREFIX', $config['database']['prefix']); $tablePrefix = new TablePrefix(DB_PREFIX); $event->addEventListener(\Doctrine\ORM\Events::loadClassMetadata, $tablePrefix); /* * Custom Functions * * We need some more functions for MySQL, like RAND for random values. */ $D2Config->addCustomNumericFunction('RAND', 'Koch\\Doctrine\\Extensions\\Query\\Mysql\\Rand'); // Entity manager $em = \Doctrine\ORM\EntityManager::create($connectionOptions, $D2Config, $event); // set DBAL DebugStack Logger (also needed for counting queries) if (defined('DEBUG') and DEBUG === 1) { self::$sqlLoggerStack = new \Doctrine\DBAL\Logging\DebugStack(); $em->getConfiguration()->setSQLLogger(self::$sqlLoggerStack); // Echo SQL Queries directly on the page. $em->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger()); } self::$em = $em; // the D2 initalization is done, remove vars to safe memory unset($config, $em, $event, $cache, $classLoader, $D2Config); return self::$em; }
use Monolog\Processor\PsrLogMessageProcessor; use Symfony\Component\Console\ConsoleEvents; use Symfony\Component\Console\Event\ConsoleCommandEvent; use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\Validator\Validation; use Symfony\Component\Validator\Validator; use Symfony\Component\Validator\Validator\ValidatorInterface; $paths = array(join(DIRECTORY_SEPARATOR, array(__DIR__, "..", "src", "Entity"))); const DEFAULT_LOG_PATH = "/var/log/hipay.log"; //Get the parameters $parameters = new Accessor(__DIR__ . "/../config/parameters.yml"); $debug = $parameters['debug']; $dbConfiguration = new DbConfiguration($parameters); // the connection configuration $dbParams = array('driver' => $dbConfiguration->getDriver(), 'user' => $dbConfiguration->getUsername(), 'password' => $dbConfiguration->getPassword(), 'dbname' => $dbConfiguration->getDatabaseName(), 'host' => $dbConfiguration->getHost(), 'port' => $dbConfiguration->getPort()); $eventManager = new Doctrine\Common\EventManager(); $timestampableListener = new Gedmo\Timestampable\TimestampableListener(); $eventManager->addEventSubscriber($timestampableListener); AnnotationRegistry::registerLoader(array($loader, 'loadClass')); $annotationMetadataConfiguration = Setup::createAnnotationMetadataConfiguration($paths, $debug, null, new ArrayCache(), false); $entityManager = EntityManager::create($dbParams, $annotationMetadataConfiguration, $eventManager); $helperSet = ConsoleRunner::createHelperSet($entityManager); $logger = new Logger("hipay"); $logFilePath = $parameters['log.file.path'] ?: DEFAULT_LOG_PATH; $logger->pushHandler(new StreamHandler($logFilePath)); $swiftTransport = new Swift_SmtpTransport($parameters['mail.host'], $parameters['mail.port'], $parameters['mail.security']); if (isset($parameters['mail.username']) && isset($parameters['mail.password'])) { $swiftTransport->setUsername($parameters['mail.username']); $swiftTransport->setPassword($parameters['mail.password']); } $mailer = new Swift_Mailer($swiftTransport);
/** * Returns the doctrine entity manager * @return \Doctrine\ORM\EntityManager */ public function getEntityManager() { if ($this->em) { return $this->em; } $config = new \Doctrine\ORM\Configuration(); //$config->setResultCacheImpl($this->cacheDriver); $config->setMetadataCacheImpl($this->cacheDriver); $config->setQueryCacheImpl($this->cacheDriver); $config->setProxyDir(ASCMS_MODEL_PROXIES_PATH); $config->setProxyNamespace('Cx\\Model\\Proxies'); /** * This should be set to true if workbench is present and active. * Just checking for workbench.config is not really a good solution. * Since ConfigurationFactory used by EM caches auto generation * config value, there's no possibility to set this later. */ $config->setAutoGenerateProxyClasses(file_exists(ASCMS_DOCUMENT_ROOT . '/workbench.config')); $connectionOptions = array('pdo' => $this->getPdoConnection(), 'dbname' => $this->db->getName()); $evm = new \Doctrine\Common\EventManager(); $chainDriverImpl = new \Doctrine\ORM\Mapping\Driver\DriverChain(); $driverImpl = new \Cx\Core\Model\Controller\YamlDriver(array(ASCMS_CORE_PATH . '/Core' . '/Model/Yaml')); $chainDriverImpl->addDriver($driverImpl, 'Cx'); //loggable stuff $loggableDriverImpl = $config->newDefaultAnnotationDriver(ASCMS_LIBRARY_PATH . '/doctrine/Gedmo/Loggable/Entity'); $chainDriverImpl->addDriver($loggableDriverImpl, 'Gedmo\\Loggable'); $this->loggableListener = new \Cx\Core\Model\Model\Event\LoggableListener(); $this->loggableListener->setUsername('currently_loggedin_user'); // in real world app the username should be loaded from session, example: // Session::getInstance()->read('user')->getUsername(); $evm->addEventSubscriber($this->loggableListener); $cx = \Cx\Core\Core\Controller\Cx::instanciate(); $sluggableDriverImpl = $config->newDefaultAnnotationDriver($cx->getCodeBaseLibraryPath() . '/doctrine/Gedmo/Sluggable'); $chainDriverImpl->addDriver($sluggableDriverImpl, 'Gedmo\\Sluggable'); $sluggableListener = new \Gedmo\Sluggable\SluggableListener(); // you should set the used annotation reader to listener, // to avoid creating new one for mapping drivers //$sluggableListener->setAnnotationReader($cachedAnnotationReader); $evm->addEventSubscriber($sluggableListener); $timestampableDriverImpl = $config->newDefaultAnnotationDriver($cx->getCodeBaseLibraryPath() . '/doctrine/Gedmo/Timestampable'); $chainDriverImpl->addDriver($timestampableDriverImpl, 'Gedmo\\Timestampable'); $timestampableListener = new \Gedmo\Timestampable\TimestampableListener(); //$timestampableListener->setAnnotationReader($cachedAnnotationReader); $evm->addEventSubscriber($timestampableListener); // Note that LANG_ID and other language constants/variables // have not been set yet! // $langCode = \FWLanguage::getLanguageCodeById(LANG_ID); // \DBG::log("LANG_ID ".LANG_ID.", language code: $langCode"); // -> LOG: LANG_ID LANG_ID, language code: $translatableDriverImpl = $config->newDefaultAnnotationDriver($cx->getCodeBaseLibraryPath() . '/doctrine/Gedmo/Translatable/Entity'); $chainDriverImpl->addDriver($translatableDriverImpl, 'Gedmo\\Translatable'); // RK: Note: // This might have been renamed in newer versions: //$translationListener = new \Gedmo\Translatable\TranslatableListener(); // In this Doctrine version, it is present as: $this->translationListener = new \Gedmo\Translatable\TranslationListener(); // current translation locale should be set from session // or hook later into the listener, // but *before the entity manager is flushed* // TODO: Set default locale from the default language? //$this->translationListener->setDefaultLocale('de_ch'); // Set the current locale (e.g. from the active language) // wherever that's required. //$translationListener->setTranslatableLocale('de_ch'); //$translationListener->setAnnotationReader($cachedAnnotationReader); $evm->addEventSubscriber($this->translationListener); // RK: Note: // This is apparently not yet present in this Doctrine version: //$sortableListener = new \Gedmo\Sortable\SortableListener(); //$sortableListener->setAnnotationReader($cachedAnnotationReader); //$evm->addEventSubscriber($sortableListener); //tree stuff $treeListener = new \Gedmo\Tree\TreeListener(); $evm->addEventSubscriber($treeListener); $config->setMetadataDriverImpl($chainDriverImpl); //table prefix $prefixListener = new \DoctrineExtension\TablePrefixListener($this->db->getTablePrefix()); $evm->addEventListener(\Doctrine\ORM\Events::loadClassMetadata, $prefixListener); $config->setSqlLogger(new \Cx\Lib\DBG\DoctrineSQLLogger()); $em = \Cx\Core\Model\Controller\EntityManager::create($connectionOptions, $config, $evm); //resolve enum, set errors $conn = $em->getConnection(); $conn->setCharset($this->db->getCharset()); $conn->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string'); $conn->getDatabasePlatform()->registerDoctrineTypeMapping('set', 'string'); $this->em = $em; return $this->em; }