Inheritance: extends Exception
Ejemplo n.º 1
0
 public function formatMessage($html = null)
 {
     if ($html === null) {
         $html = ini_get('html_errors') ? true : false;
     }
     $message = trim(parent::formatMessage($html));
     if ($this->command) {
         $message .= ($message ? '.' : '') . ($html ? '<code class="command">' : "\n\ncommand: ") . h($this->command) . ($html ? '</code>' : '');
     }
     return $message;
 }
Ejemplo n.º 2
0
 /**
  * Rebuild caches, indexes, etc.
  */
 static function rebuild($forceFullRebuild = false)
 {
     gb::log(LOG_NOTICE, 'rebuilding cache' . ($forceFullRebuild ? ' (forcing full rebuild)' : ''));
     $time_started = microtime(1);
     $failures = array();
     # Load rebuild plugins
     gb::load_plugins('rebuild');
     # Load rebuilders if needed
     if (empty(self::$rebuilders)) {
         self::loadRebuilders();
     }
     # Create rebuilder instances
     $rebuilders = array();
     foreach (self::$rebuilders as $cls) {
         $rebuilders[] = new $cls($forceFullRebuild);
     }
     # Load rebuild plugins (2nd offer)
     gb::load_plugins('rebuild');
     # Query ls-tree
     $ls = rtrim(git::exec('ls-files --stage'));
     if ($ls) {
         # Iterate objects
         $ls = explode("\n", $ls);
         foreach ($ls as $line) {
             try {
                 # <mode> SP <object> SP <stage no> TAB <name>
                 if (!$line) {
                     continue;
                 }
                 $line = explode(' ', $line, 3);
                 $id = $line[1];
                 $name = gb_normalize_git_name(substr($line[2], strpos($line[2], "\t") + 1));
                 foreach ($rebuilders as $rebuilder) {
                     $rebuilder->onObject($name, $id);
                 }
             } catch (RuntimeException $e) {
                 gb::log(LOG_ERR, 'failed to rebuild object %s %s: %s', var_export($name, 1), $e->getMessage(), $e->getTraceAsString());
                 $failures[] = array($rebuilder, $name);
             }
         }
     }
     # Let rebuilders finalize
     foreach ($rebuilders as $rebuilder) {
         try {
             $rebuilder->finalize();
         } catch (RuntimeException $e) {
             gb::log(LOG_ERR, 'rebuilder %s (0x%x) failed to finalize: %s', get_class($rebuilder), spl_object_hash($rebuilder), GBException::format($e, true, false, null, 0));
             $failures[] = array($rebuilder, null);
         }
     }
     gb::log(LOG_NOTICE, 'cache updated -- time spent: %s', gb_format_duration(microtime(1) - $time_started));
     return $failures;
 }
Ejemplo n.º 3
0
        foreach ($state_fields as $k => $discard) {
            if ($k === 'body') {
                $modified_state[$k] = $post->rawBody();
            } else {
                $v = $post->{$k};
                if ($v instanceof GBDateTime) {
                    $v = strval($v);
                }
                $modified_state[$k] = $v;
            }
        }
    }
    # commit?
    if ($input['commit']) {
        git::add($post->name);
        git::commit(($created ? 'Created' : 'Updated') . ' post ' . r($post->title), gb::$authorized, $post->name);
    }
    # build response entity
    $rsp = array('name' => $post->name, 'version' => $post->id, 'exists' => $post->exists(), 'isTracked' => $post->isTracked(), 'isDirty' => $post->isDirty(), 'state' => $modified_state);
    # status
    $status = '200 OK';
    if ($created) {
        $status = '201 Created';
    }
    # send JSON response
    gb_admin::json_rsp($rsp, $status);
    gb::log('saved post %s', $post->name);
} catch (Exception $e) {
    gb::log('failed to save post: %s', GBException::format($e, true, false, null, 0));
    gb_admin::json_rsp($e->getMessage(), '400 Bad Request');
}
Ejemplo n.º 4
0
function gb_exception_handler($e)
{
    if (ini_get('html_errors')) {
        if (headers_sent()) {
            $msg = GBException::formatHTMLBlock($e);
        } else {
            $msg = GBException::formatHTMLDocument($e);
        }
    } else {
        $msg = GBException::format($e, true, false, null, 0);
    }
    exit($msg);
}
Ejemplo n.º 5
0
        $msg = self::format($e, $includingTrace, true, $skip, $context_lines);
        if ($inc_css) {
            $msg = '<style type="text/css" media="screen">' . self::$css . '</style>' . $msg;
        }
        return '<div class="exception">' . $msg . '</div>';
    }
    public static function formatHTMLDocument(Exception $e, $includingTrace = true, $skip = null, $context_lines = 2)
    {
        $cls = get_class($e);
        $html = self::formatHTMLBlock($e, $includingTrace, $skip, $context_lines, false);
        $css = self::$css;
        return <<<HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
\t<head>
\t\t<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
\t\t<title>Error: {$cls}</title>
\t\t<style type="text/css" media="screen">
\t\t\t{$css}
\t\t</style>
\t</head>
\t<body>
\t\t<h1>An unrecoverable error occured</h1>
\t\t{$html}
\t</body>
</html>
HTML;
    }
}
GBException::$is_php53 = version_compare(PHP_VERSION, '5.3.0', '>=');
Ejemplo n.º 6
0
function rsp_exc($e)
{
    rsp_err(GBException::formatPlain($e, false, null, 0), '500 Internal Server Error', array_filter(array_map('trim', explode("\n", GBException::formatTrace($e, false, null, 0)))));
}