Example #1
0
 /**
  * Constructor
  */
 public function __construct()
 {
     $this->_request = new Request();
     $this->_response = new Response();
     $this->_method = Connection::getMethod();
     $this->setBasePath(dirname(@$_SERVER["DOCUMENT_ROOT"]) . "/areas");
     $this->setPublicPath(@$_SERVER["DOCUMENT_ROOT"]);
     $this->setRoute(Connection::getPath());
 }
Example #2
0
 /**
  * Constructor
  */
 public function __construct(Session $session)
 {
     $this->session = $session;
     $this->unique = Connection::getHash();
     if ($this->session->active() !== true) {
         throw new Exception("Session needs to be started before using the " . __CLASS__ . " class.");
     }
     $this->session->setOnce($this->key . ".info", array("fail_count" => 0, "fail_total" => 0, "last_attempt" => 0, "last_active" => 0, "login_time" => 0, "login_hash" => ""));
 }
Example #3
0
 /**
  * Constructor
  */
 public function __construct($name = "", $expire = null)
 {
     // factory options
     $this->setOption("name", "session");
     $this->setOption("cookie_lifetime", 0);
     $this->setOption("cookie_path", "/");
     $this->setOption("cookie_domain", Server::getHost());
     $this->setOption("cookie_secure", Connection::isSecure());
     $this->setOption("cookie_httponly", true);
     $this->setOption("use_only_cookies", true);
     $this->setOption("use_trans_sid", false);
     $this->setOption("entropy_file", "/dev/urandom");
     $this->setOption("entropy_length", 256);
     $this->setOption("hash_function", "sha256");
     $this->setOption("hash_bits_per_character", 6);
     $this->setOption("gc_maxlifetime", 86400);
     // 24h
     // set custom values
     $this->setName($name);
     $this->setExpire($expire);
 }
Example #4
0
 /**
  * Get current script/route url
  */
 public static function getRouteUrl($append = null)
 {
     $path = str_replace(self::getBasePath(), "", Connection::getPath());
     $append = self::_append($append);
     return self::getScriptUrl($path . $append);
 }
Example #5
0
 /**
  * Renders an error template for PHP errors and Exceptions
  */
 public function _onException($e)
 {
     $response = new Response();
     $error = $this->_filterError($e);
     $data = ["status" => $this->_status, "title" => $this->_status . ": " . $error["type"], "description" => "There has been a problem of type (" . $error["type"] . ").", "address" => Server::getUrl(), "method" => Connection::getMethod(), "date" => date("F jS Y h:i:s A T"), "headers" => getallheaders(), "error" => $error];
     // send error data to log file
     $this->log($error["type"] . ": " . $error["message"] . " in " . $error["file"] . " on line " . $error["line"] . ".");
     // send http reposnse
     if (Connection::isMethod("GET")) {
         // template has been set...
         if (!empty($this->_template) && is_file($this->_template)) {
             // send all data to template to be rendered as needed
             $response->sendTemplate($this->_status, $this->_template, $data);
         }
         // no template, send just error description for security reasons
         $response->sendText($this->_status, $data["description"]);
     }
     // non-GET, send error description data as JSON
     $response->sendJson($this->_status, ["status" => $this->_status, "error" => $data["description"]]);
 }
Example #6
0
 /**
  * Send default response depending on request method and response type
  */
 public function sendDefault($status, $response = null, $data = [])
 {
     if (Connection::isMethod("GET")) {
         if (is_object($response)) {
             $this->sendView($status, $response);
         }
         if (is_array($response)) {
             $this->sendText($status, print_r($response, true));
         }
         if (is_string($response)) {
             if (is_file($response)) {
                 $this->sendTemplate($status, $response, $data);
             }
             $this->sendText($status, $response);
         }
         $this->sendText($status, "Empty response.");
     }
     $this->sendJson($status, array_merge(Sanitize::toArray($response), $data));
 }
Example #7
0
 /**
  * Send a rendered template file HTML message
  */
 public function sendTemplate($file, $data = [])
 {
     $view = new View();
     $view->setTemplate($file);
     $view->setKey("url", Server::getUrl());
     $view->setKey("baseurl", Server::getBaseUrl());
     $view->setKey("browser", Connection::getAgent());
     $view->setKey("ip", Connection::getIp());
     $view->setKey("date", date("r T"));
     $view->mergeData($data);
     return $this->sendHtml($view->render());
 }