Ejemplo n.º 1
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];
 }
Ejemplo n.º 2
0
 /**
  * Get mutator alias if presented. Aliases used to simplify schema definition.
  *
  * @param string $alias
  * @return string|array
  */
 public function mutatorAlias($alias)
 {
     return $this->config->mutatorAlias($alias);
 }