Exemple #1
0
 public function __construct($argv)
 {
     self::$instance = $this;
     while (ob_get_level()) {
         ob_end_clean();
     }
     $this->has_colors = posix_isatty(STDOUT);
     $this->args = $this->parseArguments($argv);
     $logger = Logger::getInstance();
     if (array_key_exists("v", $this->args)) {
         $logger->setLevel(Logger::DEBUG);
     }
     $this->commands = array();
     $this->options = array();
     $this->switches = array();
     $this->inputs = array();
     $this->addCommand("help", array($this, "printHelp"), "Help messages");
 }
Exemple #2
0
 public function send_error($code, $message = null, $body = null, $backtrace = 1)
 {
     if ($this->inerror) {
         Logger::critical("Already processing error (send_error) {$code} {$message} {$body}");
         return;
     }
     $this->inerror = true;
     $protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0';
     if ($message == null) {
         if (isset(self::$messagecode[$code])) {
             $message = self::$messagecode[$code];
         } else {
             $message = "Error #{$code}";
         }
     }
     if ($body === null) {
         $body = $message;
     }
     if ($code >= 500) {
         Logger::critical("[{$code}] {$message}: {$body}");
     } else {
         Logger::info("[{$code}] {$message}: {$body}");
     }
     if ($this->raise_exception) {
         throw new Exception($body);
     }
     header("{$protocol} {$code} {$message}");
     if ($code < 500 && $code != 404) {
         echo $body;
         Output::finish($code);
     }
     IS_CLI && Output::finish($code);
     if ($backtrace !== false) {
         $this->debugBacktrace($backtrace);
     }
     $this->formatErrorBody($code, $message, $body, $this->backtrace, array_slice(Logger::getInstance()->getLog(), 0, -1));
 }