/** * Establishes a database connection * * @return \PDO * @throws \Exception */ public static function pdo() { $db_config = Config::get('database'); $instance = new \PDO(sprintf("%s:host=%s;dbname=%s;charset=utf8", $db_config['driver'], $db_config['host'], $db_config['database']), $db_config['user'], $db_config['pass']); $instance->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); $instance->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false); return $instance; }
/** * Creates origin and content-type headers then dumps JSON data * * @param string $json * @throws \Exception */ protected function outputJSON($json) { if (!is_string($json)) { throw new \Exception("This method will only accept a string parameter."); } array_map(function ($origin) { header(sprintf("Access-Control-Allow-Origin: %s", $origin)); }, Config::get('origins')); // @todo find out why nginx flat out ignores this header('Content-Type: application/json'); echo $json; }
/** * @expectedException \Exception * @expectedExceptionMessage This method requires the Config singleton to be initialized. * @throws \Exception */ public function testGetBeforeLoadThrowsException() { Config::get('foo'); }