Пример #1
0
 /**
  * Add database connection
  *
  * @param string $name Unique name for the connection
  * @param string $dsn DSN string for this connection
  * @param array $options Array of key => value options for adapter
  * @param boolean $defaut Use this connection as the default? The first connection added is automatically set as the default, even if this flag is false.
  * @return Spot_Adapter_Interface Spot adapter instance
  * @throws Spot_Exception
  */
 public function addConnection($name, $dsn, array $options = array(), $default = false)
 {
     // Connection name must be unique
     if (isset($this->_connections[$name])) {
         throw new Spot_Exception("Connection for '" . $name . "' already exists. Connection name must be unique.");
     }
     $dsnp = Spot_Adapter_Abstract::parseDSN($dsn);
     $adapterClass = "Spot_Adapter_" . ucfirst($dsnp['adapter']);
     $adapter = new $adapterClass($dsn, $options);
     // Set as default connection?
     if (true === $default || null === $this->_defaultConnection) {
         $this->_defaultConnection = $name;
     }
     // Store connection and return adapter instance
     $this->_connections[$name] = $adapter;
     return $adapter;
 }
Пример #2
0
 /**
  * Get datetime
  *
  * @return object MongoDate
  */
 public function dateTime($format = null)
 {
     // MongoDB only supports timestamps for now, not direct DateTime objects
     $format = parent::dateTime($format)->format('U');
     return new MongoDate($format);
 }