This method will dispatch preSelectDatabase and postSelectDatabase
events.
public selectDatabase ( string $name ) : Doctrine\MongoDB\Database | ||
$name | string | |
return | Doctrine\MongoDB\Database |
/** * @return Doctrine\MongoDB\Connection */ public function getDatabase() { if (isset($this->database)) { return $this->database; } $this->database = $this->connection->selectDatabase($this->migrationsDatabaseName); return $this->database; }
protected function setUp() { if (!class_exists('Doctrine\\MongoDB\\Connection')) { $this->markTestSkipped('Doctrine2 MongoDB is required for this test'); } $this->connection = new Connection(); $this->con = $this->connection->selectDatabase(static::$database); }
/** * Constructor * * @param \Doctrine\MongoDb\Connection $connection * @param string $database * @param PermissionGrantingStrategyInterface $permissionGrantingStrategy * @param array $options * @param AclCacheInterface $aclCache */ public function __construct(Connection $connection, $database, PermissionGrantingStrategyInterface $permissionGrantingStrategy, array $options, AclCacheInterface $aclCache = null) { $this->aclCache = $aclCache; $this->connection = $connection->selectDatabase($database); $this->loadedAces = array(); $this->loadedAcls = array(); $this->options = $options; $this->permissionGrantingStrategy = $permissionGrantingStrategy; }
public function setUp() { $yaml = new Parser(); $this->parametersFromYmlFile = $yaml->parse(file_get_contents(__DIR__ . '/parameters.yml'))['parameters']; $config = new Configuration(); $conn = new Connection($this->parametersFromYmlFile['mongodb_server'], [], $config); $this->db = $conn->selectDatabase($this->parametersFromYmlFile['mongodb_db']); $this->wipeDatabase(); }
/** * Returns the MongoDB instance for a class. * * @param string $className The class name. * @return Doctrine\MongoDB\Database */ public function getDocumentDatabase($className) { $metadata = $this->metadataFactory->getMetadataFor($className); $db = $metadata->getDatabase(); $db = $db ? $db : $this->config->getDefaultDB(); $db = $db ? $db : 'doctrine'; $db = sprintf('%s%s', $this->config->getEnvironmentPrefix(), $db); $database = $this->connection->selectDatabase($db); return $database; }
/** * Returns the MongoDB instance for a class. * * @param string $className The class name. * @return \Doctrine\MongoDB\Database */ public function getDocumentDatabase($className) { if (isset($this->documentDatabases[$className])) { return $this->documentDatabases[$className]; } $metadata = $this->metadataFactory->getMetadataFor($className); $db = $metadata->getDatabase(); $db = $db ? $db : $this->config->getDefaultDB(); $db = $db ? $db : 'doctrine'; $this->documentDatabases[$className] = $this->connection->selectDatabase($db); return $this->documentDatabases[$className]; }
protected function setUp() { // comment the following line, and run only this test, if you need to benchmark $this->markTestSkipped('Benchmarking skipped'); if (!class_exists('Doctrine\\MongoDB\\Connection')) { $this->markTestSkipped('Doctrine2 MongoDB is required for this test'); } $database = 'aclBenchmark'; $mongo = new \Doctrine\MongoDB\Connection(); $this->con = $mongo->selectDatabase($database); $this->options = $this->getOptions(); }
protected function setUp() { if (!class_exists('Doctrine\\MongoDB\\Connection')) { $this->markTestSkipped('Doctrine2 MongoDB is required for this test'); } $database = 'aclTest'; $this->connection = $mongo = new \Doctrine\MongoDB\Connection(); $this->con = $mongo->selectDatabase($database); $options = $this->getOptions(); // populate the db with some test data $fields = array('classType'); $classes = array(); foreach ($this->getClassData() as $data) { $id = array_shift($data); $query = array_combine($fields, $data); $classes[$id] = $query; } $fields = array('identifier', 'username'); $sids = array(); foreach ($this->getSidData() as $data) { $id = array_shift($data); $sids[$id] = $data; } $this->oidCollection = $this->con->selectCollection($options['oid_collection']); $this->oids = array(); foreach ($this->getOidData() as $data) { $query = array(); $id = $data[0]; $classId = $data[1]; $query['identifier'] = $data[2]; $query['type'] = $classes[$classId]['classType']; $parentId = $data[3]; if ($parentId) { $parent = $this->oids[$parentId]; if (isset($parent['ancestors'])) { $ancestors = $parent['ancestors']; } $ancestors[] = $parent['_id']; $query['ancestors'] = $ancestors; $query['parent'] = $parent; } $query['entriesInheriting'] = $data[4]; $this->oidCollection->insert($query); $this->oids[$id] = $query; } $fields = array('id', 'class', 'objectIdentity', 'fieldName', 'aceOrder', 'securityIdentity', 'mask', 'granting', 'grantingStrategy', 'auditSuccess', 'auditFailure'); $this->entryCollection = $this->con->selectCollection($options['entry_collection']); foreach ($this->getEntryData() as $data) { $query = array_combine($fields, $data); unset($query['id']); unset($query['class']); $oid = $query['objectIdentity']; $query['objectIdentity'] = array('$ref' => $options['oid_collection'], '$id' => $this->oids[$oid]['_id']); $sid = $query['securityIdentity']; if ($sid) { $query['securityIdentity'] = $sids[$sid]; } $this->entryCollection->insert($query); } }
public function selectDatabase($name) { $name = $this->getDbNameFromEnv($name); return parent::selectDatabase($name); }
/** * @param Name $name * @return \Doctrine\MongoDB\Database */ public function getDatabaseForTestingMigration(Name $name) { $connection = new Connection($this->configuration->getDatabaseServerUri(), [], new DoctrineConfiguration()); return $connection->selectDatabase('mongrate_test_' . $name); }