public function __construct() { // Open New Redis Connection $this->connection = @fsockopen(Config::getRequiredVal('redis', 'host'), Config::getRequiredVal('redis', 'port'), $errno, $errstr); // Test Connection if (!$this->connection) { throw new ConnectionFailureException("Could not connect to Redis"); } }
public static function factory() { // Find Engine Classname $engine_namespace = 'Atomic\\Database\\Engines\\'; $engine = Config::getRequiredVal('db', 'engine'); $class_name = $engine_namespace . $engine; // Check if Class Exists and Load it if (@class_exists($class_name)) { return $class_name::getInstance(); } else { throw new EngineNotFoundException("Engine '{$engine}' is not supported"); } }
public static function getInstance() { // Check if a Database Instance Doesn't Already Exist if (!static::$_instance) { $sqlite_file = Config::getRequiredVal('db', 'sqlite_file'); try { $dsn = "sqlite:{$sqlite_file}"; static::$_instance = new PDO($dsn, null, null); } catch (PDOException $e) { throw new ConnectionFailureException($e->getMessage()); } } return static::$_instance; }
public static function getInstance() { // Check if a Database Instance Doesn't Already Exist if (!static::$_instance) { // Get Connection Information from Configuration $host = Config::getRequiredVal('db', 'host'); $port = Config::getRequiredVal('db', 'port'); $user = Config::getRequiredVal('db', 'user'); $pass = Config::getRequiredVal('db', 'pass'); $name = Config::getRequiredVal('db', 'name'); try { // Open a new Connection $dsn = "pgsql:host={$host};port={$port};dbname={$name}"; static::$_instance = new PDO($dsn, $user, $pass); } catch (PDOException $e) { throw new ConnectionFailureException($e->getMessage()); } } return static::$_instance; }
/** * Passes the request by loading the controller, executing * the function requested and passing any required parameters. * @param $controller The Requested Controller * @param $function The requested function * @param $args The Parameters of the function * @param $namespace Controller namespace, defaults if not specified */ public static function passRequest($controller, $function, $args = false, $namespace = false) { if ($namespace === false) { $namespace = Config::getRequiredVal("app", "controller_namespace"); } $class = $namespace . $controller; if (@class_exists($class)) { $obj = $class::getInstance(); $obj->setParameters($parameters); try { call_user_func_array(array($obj, $function), array()); } catch (PassRequestException $e) { throw new PassRequestException($e->getMessage()); } } else { throw new MissingClassException("Could not find controller {$controller}"); } }