コード例 #1
0
ファイル: EpiApi.php プロジェクト: digideskio/community
 /**
  * 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']}"));
 }
コード例 #2
0
ファイル: EpiConfig.php プロジェクト: Jpsstack/epiphany
 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;
                 }
             }
         }
     }
 }
コード例 #3
0
ファイル: EpiCurl.php プロジェクト: yllus/epiphany
 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);
 }
コード例 #4
0
ファイル: EpiTemplate.php プロジェクト: Jpsstack/epiphany
 /**
  * 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));
     }
 }
コード例 #5
0
ファイル: EpiConfig_File.php プロジェクト: nicolargo/frontend
 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);
 }
コード例 #6
0
 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;
 }
コード例 #7
0
ファイル: EpiConfig.php プロジェクト: nicolargo/frontend
 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];
 }
コード例 #8
0
 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'));
 }
コード例 #9
0
ファイル: EpiSession.php プロジェクト: digideskio/community
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));
    }
}
コード例 #10
0
ファイル: EpiCache.php プロジェクト: Jpsstack/epiphany
 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];
 }
コード例 #11
0
 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'));
 }
コード例 #12
0
ファイル: EpiRoute.php プロジェクト: gg1977/frontend
 /**
  * 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"));
 }
コード例 #13
0
ファイル: EpiConfig_MySql.php プロジェクト: gg1977/frontend
 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;
 }
コード例 #14
0
ファイル: EpiDatabase.php プロジェクト: Hulth/API
 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'));
     }
 }
コード例 #15
0
ファイル: EpiApi.php プロジェクト: epals/epiphany
 /**
  * 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);
         }
     }
 }
コード例 #16
0
ファイル: EpiDatabase.php プロジェクト: digideskio/community
 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()));
     }
 }
コード例 #17
0
ファイル: EpiDatabase.php プロジェクト: gg1977/frontend
 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()));
     }
 }