Beispiel #1
0
 /** Dump function - displays debug info on all arguments
  * @return void
  */
 function v()
 {
     $trace = debug_backtrace();
     $var = func_get_args();
     if (count($var) == 1) {
         $var = $var[0];
     }
     $path = '';
     if (isset($trace[0]['file'])) {
         $path .= basename($trace[0]['file']);
         if (isset($trace[0]['line'])) {
             $path .= ":" . $trace[0]['line'];
         }
         $path .= ", ";
     }
     if (isset($trace[0]['class'])) {
         $path .= $trace[0]['class'] . '::' . $trace[0]['function'] . "()";
     } elseif (isset($trace[0]['function'])) {
         $path .= $trace[0]['function'] . "()";
     }
     try {
         $cli = \System\Status::on_cli();
     } catch (\Exception $e) {
         $cli = true;
     }
     if (!$cli) {
         echo '<div class="debug dump"><b>' . $path . "</b><pre>";
     }
     function_exists('var_export') && !is_string($var) ? var_dump($var) : print_r($var);
     if ($cli) {
         echo "\n";
     } else {
         echo '</pre></div>';
     }
 }
Beispiel #2
0
 /** Create request object from current hit
  * @return self
  */
 public static function from_hit()
 {
     if (\System\Status::on_cli()) {
         $data = array("time" => def($_SERVER['REQUEST_TIME_FLOAT'], microtime(true)), "cli" => true, "secure" => false);
     } else {
         $data = array("cli" => false, "ajax" => strtolower(def($_SERVER['HTTP_X_REQUESTED_WITH'])) == self::IDENT_XHR, "host" => def($_SERVER['HTTP_HOST']), "path" => def($_SERVER['REQUEST_URI']), "protocol" => def($_SERVER['REQUEST_SCHEME']), "referrer" => def($_SERVER['HTTP_REFERER']), "agent" => def($_SERVER['HTTP_USER_AGENT']), "query" => def($_SERVER['QUERY_STRING']), "time" => def($_SERVER['REQUEST_TIME_FLOAT'], microtime(true)), "secure" => any($_SERVER['HTTPS']), "method" => strtolower(def($_SERVER['REQUEST_METHOD'])), "cookies" => &$_COOKIE, "session" => &$_SESSION);
         if ($data['query']) {
             $path = explode('?', $data['path']);
             $data['path'] = $path[0];
         }
         if (isset($_GET['path'])) {
             $data['path'] = $_GET['path'];
         }
     }
     $obj = new self($data);
     return $obj->prepare_input();
 }
Beispiel #3
0
 public function slot_check($name)
 {
     try {
         $debug = \System\Settings::get('dev', 'debug', 'backend');
     } catch (\System\Error $e) {
         $debug = true;
     }
     if (!isset($this->content['slots'][$name])) {
         $this->content['slots'][$name] = array();
         if ($debug && strpos($this->format, 'html') !== false && !\System\Status::on_cli()) {
             $this->content['slots'][$name][] = '<!-- Slot: "' . $name . '" -->';
         }
     }
 }
Beispiel #4
0
 /** Send HTTP headers
  * @return void
  */
 public function send_headers()
 {
     if (\System\Status::on_cli()) {
         return $this;
     }
     session_write_close();
     def($this->headers['Content-Encoding'], 'gz');
     def($this->headers['Generator'], 'pwf');
     if (!isset($this->headers['Content-Type'])) {
         if ($this->mime) {
             $mime = $this->mime;
         } else {
             try {
                 $mime = \System\Output::get_mime($this->renderer->format);
             } catch (\System\Error\Argument $e) {
                 $mime = 'text/html; charset=utf-8';
             }
         }
         def($this->headers["Content-Type"], $mime . ";charset=utf-8");
     }
     if (isset($this->size)) {
         def($this->headers['Content-Length'], $this->size);
     }
     if ($this->status == self::OK && empty($this->content)) {
         $this->status(self::NO_CONTENT);
     }
     header(self::get_status($this->status));
     foreach ($this->headers as $name => $content) {
         if (is_numeric($name)) {
             header($content);
         } else {
             $name = implode('-', array_map('ucfirst', explode('-', $name)));
             header($name . ": " . $content);
         }
     }
     return $this;
 }