コード例 #1
0
ファイル: Connection.php プロジェクト: reekoheek/norm-fdb
 public function __construct(array $options = array())
 {
     parent::__construct($options);
     if (!$this->option('dataDir')) {
         throw new \Exception('Data directory is not available "' . $this->option('dataDir') . '"');
     }
 }
コード例 #2
0
ファイル: Cursor.php プロジェクト: xinix-technology/norm
 /**
  * Extract data into array of models.
  *
  * @param boolean $plain When true will return array of associative array.
  *
  * @return array
  */
 public function toArray($plain = false)
 {
     $result = array();
     foreach ($this as $key => $value) {
         if ($plain) {
             $result[] = $value->toArray();
         } else {
             $result[] = $this->connection->unmarshall($value);
         }
     }
     return $result;
 }
コード例 #3
0
 /**
  * Class constructor
  *
  * @param array $options
  */
 public function __construct(array $options = array())
 {
     parent::__construct($options);
     if (!isset($this->options['dbPath'])) {
         $this->options['dbPath'] = 'data';
     }
     if (!isset($this->options['database'])) {
         throw new Exception("Please specify database name for your application", 1);
     }
     $dbPath = realpath('../' . $this->options['dbPath']);
     if (!$dbPath or !realpath($dbPath . '/' . $this->options['database'])) {
         $this->prepareDatabaseEcosystem();
     }
 }
コード例 #4
0
 /**
  * {@inheritDoc}
  */
 public function __construct(array $options = array())
 {
     parent::__construct($options);
     if (!isset($options['prefix'])) {
         throw new Exception('[Norm\\PDOConnection] Missing prefix, check your configuration!');
     }
     if (isset($options['dsn'])) {
         $dsn = $options['dsn'];
     } elseif ($options['prefix'] === 'sqlite') {
         $dsn = 'sqlite:' . $options['database'];
     } else {
         $dsnArray = array();
         foreach ($options as $key => $value) {
             if ($key === 'driver' || $key === 'prefix' || $key === 'username' || $key === 'password' || $key === 'name' || $key === 'dialect') {
                 continue;
             }
             $dsnArray[] = "{$key}={$value}";
         }
         $dsn = $options['prefix'] . ':' . implode(';', $dsnArray);
     }
     if (isset($options['username'])) {
         $this->raw = new PDO($dsn, $options['username'], $options['password']);
     } else {
         $this->raw = new PDO($dsn);
     }
     $this->raw->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     $this->raw->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
     if (isset($options['dialect'])) {
         $Dialect = $options['dialect'];
     } elseif (isset($this->DIALECT_MAP[$options['prefix']])) {
         $Dialect = $this->DIALECT_MAP[$options['prefix']];
     } else {
         throw new Exception('[Norm/PDOConnection] Missing dialect!');
     }
     $this->dialect = new $Dialect($this);
 }
コード例 #5
0
 /**
  * {@inheritDoc}
  */
 public function marshall($object)
 {
     if ($object instanceof NormDateTime) {
         return new MongoDate($object->getTimestamp());
     } elseif ($object instanceof NormArray) {
         return $object->toArray();
     } elseif ($object instanceof Object) {
         return $object->toObject();
     } else {
         return parent::marshall($object);
     }
 }
コード例 #6
0
 /**
  * {@inheritDoc}
  */
 public function marshall($object)
 {
     if ($object instanceof \Norm\Type\DateTime) {
         return $object->format('Y-m-d H:i:s');
     } elseif (is_array($object)) {
         $result = array();
         foreach ($object as $key => $value) {
             if ($key[0] === '$') {
                 if ($key === '$id' || $key === '$type') {
                     continue;
                 } else {
                     $result[substr($key, 1)] = $this->marshall($value);
                 }
             } else {
                 $result[$key] = $this->marshall($value);
             }
         }
         return $result;
     } else {
         return parent::marshall($object);
     }
 }