public function __construct(array $options = array()) { parent::__construct($options); if (!$this->option('dataDir')) { throw new \Exception('Data directory is not available "' . $this->option('dataDir') . '"'); } }
/** * 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(); } }
/** * {@inheritDoc} */ public function __construct($options) { parent::__construct($options); $defaultOptions = array('hostname' => MongoClient::DEFAULT_HOST, 'port' => MongoClient::DEFAULT_PORT); $this->options = $options + $defaultOptions; if (isset($this->options['connectionString'])) { $connectionString = $this->options['connectionString']; } else { $hostname = $this->options['hostname']; $port = $this->options['port']; if (isset($this->options['database'])) { $database = $this->options['database']; } else { throw new Exception('[Norm/MongoConnection] Missing database name, check your configuration!'); } $prefix = ''; if (isset($this->options['username'])) { $prefix = $this->options['username'] . ':' . $this->options['password'] . '@'; } $connectionString = "mongodb://{$prefix}{$hostname}:{$port}/{$database}"; } $this->client = new MongoClient($connectionString); $this->raw = $this->client->{$database}; }
/** * {@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); }