public function run() { /* Get our system config */ $systemConfig = new ApiConfig(); /* Create a new Slim app */ $slimApp = $this->createSlim($systemConfig->get('debugMode')); /* Format the API Response as JSON */ //$slimApp->add(new \API\JsonResponseView()); /* Add API Routes */ $this->addRoutes($slimApp, $systemConfig->get('debugMode')); /* Start Slim */ $slimApp->run(); }
private static function connect() { // If a PDO instance does not already exist if (!self::$pdo) { // Get the system configuration file $config = new ApiConfig(); $c = $config->get(); // Create a set of PDO options $options = array(\PDO::ATTR_PERSISTENT => true, \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION); // $invocation = $c['dbHost'] ? "host={$c['dbHost']}" : "unix_socket={$c['dbUnixSocket']}"; try { self::$pdo = new \PDO("mysql:{$invocation};dbname={$c['db']}", $c["dbUser"], $c["dbPass"], $options); } catch (\PDOException $e) { self::logError("Could not connect to the DB \"mysql:{$invocation};dbname={$c['db']}\" from 'api.dbconn'."); // If we cant connect to the database die die('Could not connect to the database:<br/>' . $e); } } // Return the cached instance of PDO return self::$pdo; }
function __construct() { $config = new ApiConfig(); $this->config = $config->get(); $this->checkDirectories(); }