/** * EpiApi::getRoute($route); * @name getRoute * @author Jaisen Mathai <*****@*****.**> * @param string $route * @method getRoute * @static method */ public function getRoute($route, $httpMethod) { foreach ($this->regexes as $ind => $regex) { if (preg_match($regex, $route, $arguments)) { array_shift($arguments); $def = $this->routes[$ind]; if ($httpMethod != $def['httpMethod']) { continue; } else { if (is_array($def['callback']) && method_exists($def['callback'][0], $def['callback'][1])) { if (Epi::getSetting('debug')) { getDebug()->addMessage(__CLASS__, sprintf('Matched %s : %s : %s : %s', $httpMethod, $this->route, json_encode($def['callback']), json_encode($arguments))); } return array('callback' => $def['callback'], 'args' => $arguments, 'postprocess' => true); } else { if (function_exists($def['callback'])) { if (Epi::getSetting('debug')) { getDebug()->addMessage(__CLASS__, sprintf('Matched %s : %s : %s : %s', $httpMethod, $this->route, json_encode($def['callback']), json_encode($arguments))); } return array('callback' => $def['callback'], 'args' => $arguments, 'postprocess' => true); } } } EpiException::raise(new EpiException('Could not call ' . json_encode($def) . " for route {$regex}")); } } EpiException::raise(new EpiException("Could not find route {$this->route} from {$_SERVER['REQUEST_URI']}")); }
public function load() { $args = func_get_args(); foreach ($args as $file) { // Prepend config directory if the path doesn't start with . or / if ($file[0] != '.' && $file[0] != '/') { $file = Epi::getPath('config') . "/{$file}"; } if (!file_exists($file)) { EpiException::raise(new EpiConfigException("Config file ({$file}) does not exist")); break; // need to simulate same behavior if exceptions are turned off } $parsed_array = parse_ini_file($file, true); foreach ($parsed_array as $key => $value) { if (!is_array($value)) { $this->config->{$key} = $value; } else { if (!isset($this->config->{$key})) { $this->config->{$key} = new stdClass(); } foreach ($value as $innerKey => $innerValue) { $this->config->{$key}->{$innerKey} = $innerValue; } } } } }
function __construct() { if (self::$singleton == 0) { EpiException::raise(new EpiException('This class cannot be instantiated by the new keyword. You must instantiate it using: $obj = EpiCurl::getInstance();')); } $this->mc = curl_multi_init(); $this->properties = array('code' => CURLINFO_HTTP_CODE, 'time' => CURLINFO_TOTAL_TIME, 'length' => CURLINFO_CONTENT_LENGTH_DOWNLOAD, 'type' => CURLINFO_CONTENT_TYPE, 'url' => CURLINFO_EFFECTIVE_URL); }
/** * EpiRoute::json($variable); * @name json * @author Jaisen Mathai <*****@*****.**> * @param mixed $data * @return string * @method json * @static method */ public function json($data) { if ($retval = json_encode($data)) { return $retval; } else { $dataDump = var_export($dataDump, 1); EpiException::raise(new EpiException("json_encode failed for {$dataDump}", 404)); } }
public function getString($file) { $file = $this->getFilePath($file); if (!file_exists($file)) { EpiException::raise(new EpiConfigException("Config file ({$file}) does not exist")); return; // need to simulate same behavior if exceptions are turned off } return file_get_contents($file); }
public function getRecord($file) { $file = $this->getFilePath($file); $res = $this->db->one("SELECT * FROM `{$this->table}` WHERE `id`=:file OR `aliasOf`=:aliasOf", array(':file' => $file, ':aliasOf' => $file)); if (!$res) { EpiException::raise(new EpiConfigException("Config file ({$file}) does not exist in db")); return; // need to simulate same behavior if exceptions are turned off } return $res; }
public static function getInstance() { $params = func_get_args(); $hash = md5(json_encode($params)); if (isset(self::$instances[$hash])) { return self::$instances[$hash]; } $type = $params[0]; if (!file_exists($file = dirname(__FILE__) . "/{$type}.php")) { EpiException::raise(new EpiConfigTypeDoesNotExistException("EpiConfig type does not exist: ({$type}). Tried loading {$file}", 404)); } self::$instances[$hash] = new $type($params[1]); self::$instances[$hash]->hash = $hash; return self::$instances[$hash]; }
private function connect() { if (self::$connected === true) { return true; } if (class_exists('Memcached')) { $this->memcached = new Memcached(); if ($this->memcached->addServer($this->host, $this->port)) { return self::$connected = true; } else { EpiException::raise(new EpiCacheMemcacheConnectException('Could not connect to memcache server')); } } EpiException::raise(new EpiCacheMemcacheClientDneException('No memcache client exists')); }
function getSession() { $employ = EpiSession::employ(); if ($employ && class_exists($employ)) { return EpiSession::getInstance($employ); } elseif (class_exists(EpiSession::PHP)) { return EpiSession::getInstance(EpiSession::PHP); } elseif (class_exists(EpiSession::APC)) { return EpiSession::getInstance(EpiSession::APC); } elseif (class_exists(EpiSession::MEMCACHED)) { return EpiSession::getInstance(EpiSession::MEMCACHED); } else { EpiException::raise(new EpiSessionException('Could not determine which session handler to load', 404)); } }
public static function getInstance() { $params = func_get_args(); $hash = md5(implode('.', $params)); if (isset(self::$instances[$hash])) { return self::$instances[$hash]; } $type = array_shift($params); if (!file_exists($file = dirname(__FILE__) . "/{$type}.php")) { EpiException::raise(EpiCacheTypeDoesNotExistException("EpiCache type does not exist: ({$type}). Tried loading {$file}", 404)); } require_once $file; self::$instances[$hash] = new $type($params); self::$instances[$hash]->hash = $hash; return self::$instances[$hash]; }
private function connect($params = null) { if (self::$connected) { return true; } if (class_exists('Memcached')) { $this->memcached = new Memcached(); if ($this->memcached->addServer($this->host, $this->port)) { self::$connected = true; $this->key = empty($key) ? $_COOKIE[EpiSession::COOKIE] : $key; $this->store = $this->getAll(); return true; } else { EpiException::raise(new EpiSessionMemcacheConnectException('Could not connect to memcache server')); } } EpiException::raise(new EpiSessionMemcacheClientDneException('Could not connect to memcache server')); }
/** * EpiRoute::redirect($url); * @name redirect * @author Jaisen Mathai <*****@*****.**> * @param string $url * @method redirect * @static method */ public function redirect($url, $code = null, $offDomain = false) { $continue = !empty($url); if ($offDomain === false && preg_match('#^https?://#', $url)) { $continue = false; } if ($continue) { if ($code != null && (int) $code == $code) { header("Status: {$code}"); } header("Location: {$url}"); die; } EpiException::raise(new EpiException("Redirect to {$url} failed")); }
public function getRecord($file) { if ($file == '') { EpiException::raise(new EpiConfigException("Configuration file cannot be empty when calling getRecord")); return; // need to simulate same behavior if exceptions are turned off } $file = $this->getFilePath($file); if ($this->cacheObj) { $value = $this->cache($file); if ($value !== null) { return $value; } } $res = $this->db->one("SELECT * FROM `{$this->table}` WHERE `id`=:file OR `aliasOf`=:aliasOf", array(':file' => $file, ':aliasOf' => $file)); if (!$res) { EpiException::raise(new EpiConfigException("Config file ({$file}) does not exist in db")); return; // need to simulate same behavior if exceptions are turned off } if ($this->cacheObj) { $this->cache($file, $res); } return $res; }
private function init() { if ($this->dbh) { return; } try { $this->dbh = new PDO($this->_type . ':host=' . $this->_host . ';dbname=' . $this->_name . '', $this->_user, $this->_pass, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")); $this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (Exception $e) { EpiException::raise(new EpiDatabaseConnectionException('Could not connect to database')); } }
/** * load('api_config.ini') * @name load * @author Steve Mulligan <*****@*****.**> * @param string $api_config_ini_filename */ public function load($file) { $file = Epi::getPath('config') . "/{$file}"; if (!file_exists($file)) { EpiException::raise(new EpiException("Config file ({$file}) does not exist")); break; // need to simulate same behavior if exceptions are turned off } $parsed_array = parse_ini_file($file, true); foreach ($parsed_array as $route) { $method = strtolower($route['method']); $vis = strtolower($route['visibility']); // default visibiltiy is false. you MUST explcitly allow external access by adding visibility = external to the ini file $visibility = self::internal; if ($vis == "external") { $visibility = self::external; } if (isset($route['class']) && isset($route['function'])) { $this->{$method}($route['path'], array($route['class'], $route['function']), $visibility); } if (isset($route['instance']) && isset($route['function'])) { $this->{$method}($route['path'], array(new $route['instance'](), $route['function']), $visibility); } elseif (isset($route['function'])) { $this->{$method}($route['path'], $route['function'], $visibility); } } }
private function init() { if ($this->dbh) { return; } try { $this->dbh = new PDO($this->_type . ':host=' . $this->_host . ';dbname=' . $this->_name, $this->_user, $this->_pass); $this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (Exception $e) { EpiException::raise(new EpiDatabaseConnectionException('Could not connect to database: ' . $e->getMessage())); } }
private function init() { if ($this->dbh) { return; } try { // eventually split host to use a different // sql port $host = $this->_host; $host = strtok($host, ":"); $port = strtok(":"); $dsn = sprintf('%s:host=%s', $this->_type, $host); if ($port != '') { $dsn .= sprintf(';port=%s', $port); } if ($this->_name != '') { $dsn .= sprintf(';dbname=%s', $this->_name); } $dsn .= ';charset=utf8'; $this->dbh = new PDO($dsn, $this->_user, $this->_pass, array(PDO::ATTR_PERSISTENT => true)); $this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (Exception $e) { EpiException::raise(new EpiDatabaseConnectionException('Could not connect to database: ' . $e->getMessage())); } }