/**
  * Resolve database alias.
  *
  * @param string $database
  * @return string
  */
 public function databaseAlias($database)
 {
     if (empty($database)) {
         $database = $this->config->defaultDatabase();
     }
     //Spiral support ability to link multiple virtual databases together using aliases
     return $this->config->resolveAlias($database);
 }
Example #2
0
 /**
  * Create specified or select default instance of MongoDatabase.
  *
  * @param string $database Database name (internal).
  * @return MongoDatabase
  * @throws ODMException
  */
 public function database($database = null)
 {
     if (empty($database)) {
         $database = $this->config->defaultDatabase();
     }
     //Spiral support ability to link multiple virtual databases together using aliases
     $database = $this->config->resolveAlias($database);
     if (isset($this->databases[$database])) {
         return $this->databases[$database];
     }
     if (!$this->config->hasDatabase($database)) {
         throw new ODMException("Unable to initiate mongo database, no presets for '{$database}' found.");
     }
     $benchmark = $this->benchmark('database', $database);
     try {
         $this->databases[$database] = $this->factory->make(MongoDatabase::class, ['name' => $database, 'config' => $this->config->databaseConfig($database), 'odm' => $this]);
     } finally {
         $this->benchmark($benchmark);
     }
     return $this->databases[$database];
 }