public function testGetDefault() { $config = array('one' => array('two' => array('three' => 'failed'))); $this->assertEquals('value', Config::get($config, 'one.two.three.four', 'value')); }
/** * Get connection, create if required * * @return \PDO */ protected function getConnection() { if (!$this->connection instanceof \PDO) { if (!isset($this->dbConfig['host'])) { throw new \InvalidArgumentException('Missing host config param'); } $dsn = "mysql:host={$this->dbConfig['host']}"; if (isset($this->dbConfig['port'])) { $dsn .= ";port={$this->dbConfig['port']}"; } $timeout = filter_var(Config::get($this->dbConfig, 'timeout'), FILTER_VALIDATE_INT, array('options' => array('default' => 2, 'min_range' => 0, 'max_range' => 120))); $options = array(\PDO::ATTR_TIMEOUT => $timeout, \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC); $this->connection = new \PDO($dsn, Config::get($this->dbConfig, 'username', ''), Config::get($this->dbConfig, 'password', ''), $options); } return $this->connection; }