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 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; }
/** * @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; }
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))); }
/** * @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->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); }
/** * @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; }
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'); $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->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 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))); }
protected function getDoctrine_Dbal_DefaultConnectionService() { $a = new \Doctrine\Common\EventManager(); $a->addEventSubscriber(new \Doctrine\DBAL\Event\Listeners\MysqlSessionInit('UTF8')); return $this->services['doctrine.dbal.default_connection'] = $this->get('doctrine.dbal.connection_factory')->createConnection(array('dbname' => 'shakingl_scienceapp', 'host' => 'scienceapp.shakinglabs.com', 'port' => '', 'user' => 'shaki_scienceapp', 'password' => 'sciencemola', 'driver' => 'pdo_mysql', 'logging' => false, 'driverOptions' => array()), new \Doctrine\DBAL\Configuration(), $a, array()); }
$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); // timestampable $timestampableListener = new Gedmo\Timestampable\TimestampableListener(); $timestampableListener->setAnnotationReader($cachedAnnotationReader); $evm->addEventSubscriber($timestampableListener); // blameable $blameableListener = new \Gedmo\Blameable\BlameableListener();
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) { return $app['cache']('event_jsonld'); }); $app['event_jsonld_projector'] = $app->share(function ($app) {
/** * @param \Nette\DI\Container * @return \Doctrine\Common\EventManager */ public static function createServiceEventManager(DI\Container $context) { $evm = new \Doctrine\Common\EventManager; foreach (array_keys($context->getServiceNamesByTag('listener')) as $name) { $evm->addEventSubscriber($context->getService($name)); } return $evm; }
$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); //table prefix $prefixListener = new \DoctrineExtension\TablePrefixListener($_DBCONFIG['tablePrefix']); $evm->addEventListener(\Doctrine\ORM\Events::loadClassMetadata, $prefixListener); //page listener for unique slugs $pageListener = new PageEventListener(); $evm->addEventListener(\Doctrine\ORM\Events::preUpdate, $pageListener); $evm->addEventListener(\Doctrine\ORM\Events::onFlush, $pageListener); $evm->addEventListener(\Doctrine\ORM\Events::postPersist, $pageListener); $evm->addEventListener(\Doctrine\ORM\Events::preRemove, $pageListener); $config->setSqlLogger(new \Cx\Lib\DBG\DoctrineSQLLogger());
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; }
/** * 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; }
/** * Init doctrine method * * @return Shopware\Components\Model\ModelManager */ public function initModels() { /** @var $config \Doctrine\ORM\Configuration */ $config = $this->getResource('ModelConfig'); $cacheResource = $this->getResource('Cache'); // Check if native Doctrine ApcCache may be used if ($cacheResource->getBackend() instanceof Zend_Cache_Backend_Apc) { $cache = new Doctrine\Common\Cache\ApcCache(); } else { $cache = new Shopware\Components\Model\Cache($cacheResource); } // register standard doctrine annotations Doctrine\Common\Annotations\AnnotationRegistry::registerFile( 'Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php' ); // register symfony validation annotions Doctrine\Common\Annotations\AnnotationRegistry::registerAutoloadNamespace( 'Symfony\Component\Validator\Constraint' ); // register gedmo annotions Doctrine\Common\Annotations\AnnotationRegistry::registerFile( 'Gedmo/Mapping/Annotation/All.php' ); $cachedAnnotationReader = new Doctrine\Common\Annotations\CachedReader( new Doctrine\Common\Annotations\AnnotationReader, $cache ); $annotationDriver = new Doctrine\ORM\Mapping\Driver\AnnotationDriver( $cachedAnnotationReader, array( $this->Application()->Loader()->isReadable('Gedmo/Tree/Entity/MappedSuperclass'), $this->Application()->AppPath('Models') )); // create a driver chain for metadata reading $driverChain = new Doctrine\ORM\Mapping\Driver\DriverChain(); // register annotation driver for our application $driverChain->addDriver($annotationDriver, 'Gedmo'); $driverChain->addDriver($annotationDriver, 'Shopware\\Models\\'); $driverChain->addDriver($annotationDriver, 'Shopware\\CustomModels\\'); $this->registerResource('ModelAnnotations', $annotationDriver); $config->setMetadataDriverImpl($driverChain); // Create event Manager $eventManager = new \Doctrine\Common\EventManager(); $treeListener = new Gedmo\Tree\TreeListener; $treeListener->setAnnotationReader($cachedAnnotationReader); $eventManager->addEventSubscriber($treeListener); // Create new shopware event subscriber to handle the entity lifecycle events. $liveCycleSubscriber = new \Shopware\Components\Model\EventSubscriber( $this->Application()->Events() ); $eventManager->addEventSubscriber($liveCycleSubscriber); // now create the entity manager and use the connection // settings we defined in our application.ini $conn = \Doctrine\DBAL\DriverManager::getConnection( array('pdo' => $this->Application()->Db()->getConnection()), $config, $eventManager ); $entityManager = Shopware\Components\Model\ModelManager::create($conn, $config, $eventManager); //if (!is_readable(rtrim($config->getProxyDir(), '/') . '/__CG__ShopwareModelsShopShop.php')) { // $metadata = $entityManager->getMetadataFactory()->getAllMetadata(); // $proxyFactory = $entityManager->getProxyFactory(); // $proxyFactory->generateProxyClasses($metadata); //} return $entityManager; }
/** * Returns the doctrine entity manager * @return \Doctrine\ORM\EntityManager */ public function getEntityManager() { if ($this->em) { return $this->em; } global $objCache; $config = new \Doctrine\ORM\Configuration(); $userCacheEngine = $objCache->getUserCacheEngine(); if (!$objCache->getUserCacheActive()) { $userCacheEngine = \Cx\Core_Modules\Cache\Controller\Cache::CACHE_ENGINE_OFF; } $arrayCache = new \Doctrine\Common\Cache\ArrayCache(); switch ($userCacheEngine) { case \Cx\Core_Modules\Cache\Controller\Cache::CACHE_ENGINE_APC: $cache = new \Doctrine\Common\Cache\ApcCache(); $cache->setNamespace($this->db->getName() . '.' . $this->db->getTablePrefix()); break; case \Cx\Core_Modules\Cache\Controller\Cache::CACHE_ENGINE_MEMCACHE: $memcache = $objCache->getMemcache(); if ($memcache instanceof \Memcache) { $cache = new \Doctrine\Common\Cache\MemcacheCache(); $cache->setMemcache($memcache); } elseif ($memcache instanceof \Memcached) { $cache = new \Doctrine\Common\Cache\MemcachedCache(); $cache->setMemcache($memcache); } $cache->setNamespace($this->db->getName() . '.' . $this->db->getTablePrefix()); break; case \Cx\Core_Modules\Cache\Controller\Cache::CACHE_ENGINE_XCACHE: $cache = new \Doctrine\Common\Cache\XcacheCache(); $cache->setNamespace($this->db->getName() . '.' . $this->db->getTablePrefix()); break; case \Cx\Core_Modules\Cache\Controller\Cache::CACHE_ENGINE_FILESYSTEM: $cache = new \Cx\Core_Modules\Cache\Controller\Doctrine\CacheDriver\FileSystemCache(ASCMS_CACHE_PATH); break; default: $cache = $arrayCache; break; } \Env::set('cache', $cache); //$config->setResultCacheImpl($cache); $config->setMetadataCacheImpl($cache); $config->setQueryCacheImpl($cache); $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); //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; }
/** * 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; }
/** * 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()); }
private static function newConnect() { $dir = __DIR__ . '/../../libs/Doctrine/'; $vendorPath = realpath($dir); $ExtensionPath = realpath($dir . '/DoctrineExtensions'); require_once $vendorPath . '/Doctrine/Common/ClassLoader.php'; // autoload all vendors $loader = new Doctrine\Common\ClassLoader('Doctrine\\Common', $vendorPath); $loader->register(); $loader = new Doctrine\Common\ClassLoader('Doctrine\\DBAL', $vendorPath); $loader->register(); $loader = new Doctrine\Common\ClassLoader('Doctrine\\ORM', $vendorPath); $loader->register(); // gedmo extensions $loader = new Doctrine\Common\ClassLoader('Gedmo', $ExtensionPath); $loader->register(); // Pagefanta $classLoader = new Doctrine\Common\ClassLoader("Pagerfanta", $ExtensionPath); $classLoader->register(); //MYSQL Functions $classLoader = new \Doctrine\Common\ClassLoader('DoctrineExtensions', realpath($dir)); $classLoader->register(); // autoloader for Entity namespace $loader = new Doctrine\Common\ClassLoader('Entities', $dir); $loader->register(); // ensure standard doctrine annotations are registered Doctrine\Common\Annotations\AnnotationRegistry::registerFile($vendorPath . '/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php'); // Second configure ORM // globally used cache driver $cache = new Doctrine\Common\Cache\ArrayCache(); $reader = new \Doctrine\Common\Annotations\AnnotationReader(); Doctrine\Common\Annotations\AnnotationRegistry::registerAutoloadNamespace('Gedmo\\Mapping\\Annotation', $ExtensionPath); $driverChain = new \Doctrine\ORM\Mapping\Driver\DriverChain(); $annotationDriver = new Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader, array($dir . 'Entities', $ExtensionPath . '/Gedmo/Tree/Entity')); // drivers $driverChain->addDriver($annotationDriver, 'Gedmo\\Tree\\Entity'); $driverChain->addDriver($annotationDriver, 'Entities'); // general ORM configuration $config = new Doctrine\ORM\Configuration(); //$config->setProxyDir(sys_get_temp_dir()); $config->setProxyDir($dir . '/Proxies'); $config->setProxyNamespace('Proxy'); $config->setAutoGenerateProxyClasses(true); // this can be based on production config. FALSE // 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 // tree $treeListener = new Gedmo\Tree\TreeListener(); $treeListener->setAnnotationReader($reader); $evm->addEventSubscriber($treeListener); // timestampable $timestampableListener = new Gedmo\Timestampable\TimestampableListener(); $timestampableListener->setAnnotationReader($reader); $evm->addEventSubscriber($timestampableListener); // mysql set names UTF-8 if required $evm->addEventSubscriber(new Doctrine\DBAL\Event\Listeners\MysqlSessionInit()); // Finally, create entity manager $connection = array('dbname' => DB_DATABASE, 'user' => DB_USER, 'password' => DB_PASSWORD, 'host' => DB_HOST, 'driver' => 'pdo_mysql'); $config->addCustomDatetimeFunction('YEAR', 'DoctrineExtensions\\Query\\Mysql\\Year'); $config->addCustomDatetimeFunction('MONTH', 'DoctrineExtensions\\Query\\Mysql\\Month'); $config->addCustomDatetimeFunction('DAY', 'DoctrineExtensions\\Query\\Mysql\\Day'); $config->addCustomDatetimeFunction('HOUR', 'DoctrineExtensions\\Query\\Mysql\\Hour'); $config->addCustomDatetimeFunction('DATE', 'DoctrineExtensions\\Query\\Mysql\\Date'); $config->addCustomDatetimeFunction('DATEDIFF', 'DoctrineExtensions\\Query\\MySql\\DateDiff'); try { $em = Doctrine\ORM\EntityManager::create($connection, $config, $evm); } catch (Exception $e) { } self::$EntityManager = $em; }
/** * Add configured event subscribers and listeners to the event manager * * @return \Doctrine\Common\EventManager * @throws \TYPO3\Flow\Persistence\Exception\IllegalObjectTypeException */ protected function buildEventManager() { $eventManager = new \Doctrine\Common\EventManager(); if (isset($this->settings['doctrine']['eventSubscribers']) && is_array($this->settings['doctrine']['eventSubscribers'])) { foreach ($this->settings['doctrine']['eventSubscribers'] as $subscriberClassName) { $subscriber = $this->objectManager->get($subscriberClassName); if (!$subscriber instanceof \Doctrine\Common\EventSubscriber) { throw new IllegalObjectTypeException('Doctrine eventSubscribers must extend class \\Doctrine\\Common\\EventSubscriber, ' . $subscriberClassName . ' fails to do so.', 1366018193); } $eventManager->addEventSubscriber($subscriber); } } if (isset($this->settings['doctrine']['eventListeners']) && is_array($this->settings['doctrine']['eventListeners'])) { foreach ($this->settings['doctrine']['eventListeners'] as $listenerOptions) { $listener = $this->objectManager->get($listenerOptions['listener']); $eventManager->addEventListener($listenerOptions['events'], $listener); } } return $eventManager; }
protected function getModelsService() { $a = new \Doctrine\Common\EventManager(); $a->addEventSubscriber(new \Shopware\Components\Model\EventSubscriber($this->get('events'))); $a->addEventSubscriber(new \Shopware\Models\Order\OrderHistorySubscriber()); $a->addEventSubscriber($this->get('categorysubscriber')); $a->addEventSubscriber(new \Shopware\Models\Media\MediaSubscriber($this)); $a->addEventSubscriber(new \Shopware\Bundle\ESIndexingBundle\Subscriber\ORMBacklogSubscriber($this)); return $this->services['models'] = $this->get('model_factory')->factory($a, $this->get('modelconfig'), $this->get('loader'), $this->get('db_connection'), 'C:\\Users\\jkeull\\Documents\\xampp\\htdocs\\shopware', $this->get('modelannotations')); }
protected function _setupEventManager() { $options = $this->getOptions(); if (!empty($options['events'])) { if (isset($options['events']['eventManager'])) { $eventManager = new $options['events']['eventManager'](); } else { $eventManager = new \Doctrine\Common\EventManager(); } if (!empty($options['events']['subscribers'])) { $subscribers = $options['events']['subscribers']; foreach ($subscribers as $subscriberOptions) { if (is_array($subscriberOptions)) { $subscriberClass = $subscriberOptions['className']; unset($subscriberOptions['className']); // We use Reflection to create a new instance of the Subscriber // and provides according arguments $subscriberReflection = new ReflectionClass($subscriberClass); $subscriber = $subscriberReflection->newInstanceArgs($subscriberOptions); } else { $subscriber = new $subscriberOptions(); } $eventManager->addEventSubscriber($subscriber); } } $this->setEventManager($eventManager); } }
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); $messageTemplate = new Swift_Message(); $messageTemplate->setSubject($parameters['mail.subject']);
/** * 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; }