function debug_tables($schema)
{
    global $DEBUG_TABLES;
    if (!$DEBUG_TABLES) {
        return;
    }
    $tables = scraperwiki::show_tables($schema);
    print "Schema '" . $schema . "' contains " . count($tables) . " tables\n";
    foreach (array_keys($tables) as $tableName) {
        debug_table($schema, $tableName, TRUE);
    }
}
Пример #2
0
/**
 * Provides a nice print out of the stack trace when an exception is thrown.
 *
 * @param Exception $e Exception object.
 */
function framework_exception_handler($e)
{
    if (!DEBUG) {
        page_not_found();
    }
    echo '<style>h1,h2,h3,p,td {font-family:Verdana; font-weight:lighter;}</style>';
    echo '<p>Uncaught ' . get_class($e) . '</p>';
    echo '<h1>' . $e->getMessage() . '</h1>';
    $traces = $e->getTrace();
    if (count($traces) > 1) {
        echo '<p><b>Trace in execution order:</b></p>' . '<pre style="font-family:Verdana; line-height: 20px">';
        $level = 0;
        foreach (array_reverse($traces) as $trace) {
            ++$level;
            if (isset($trace['class'])) {
                echo $trace['class'] . '&rarr;';
            }
            $args = array();
            if (!empty($trace['args'])) {
                foreach ($trace['args'] as $arg) {
                    if (is_null($arg)) {
                        $args[] = 'null';
                    } else {
                        if (is_array($arg)) {
                            $args[] = 'array[' . sizeof($arg) . ']';
                        } else {
                            if (is_object($arg)) {
                                $args[] = get_class($arg) . ' Object';
                            } else {
                                if (is_bool($arg)) {
                                    $args[] = $arg ? 'true' : 'false';
                                } else {
                                    if (is_int($arg)) {
                                        $args[] = $arg;
                                    } else {
                                        $arg = htmlspecialchars(substr($arg, 0, 64));
                                        if (strlen($arg) >= 64) {
                                            $arg .= '...';
                                        }
                                        $args[] = "'" . $arg . "'";
                                    }
                                }
                            }
                        }
                    }
                }
            }
            echo '<b>' . $trace['function'] . '</b>(' . implode(', ', $args) . ')  ';
            echo 'on line <code>' . (isset($trace['line']) ? $trace['line'] : 'unknown') . '</code> ';
            echo 'in <code>' . (isset($trace['file']) ? $trace['file'] : 'unknown') . "</code>\n";
            echo str_repeat("   ", $level);
        }
        echo '</pre>';
    }
    echo "<p>Exception was thrown on line <code>" . $e->getLine() . "</code> in <code>" . $e->getFile() . "</code></p>";
    $dispatcher_status = Dispatcher::getStatus();
    $dispatcher_status['request method'] = get_request_method();
    debug_table($dispatcher_status, 'Dispatcher status');
    if (!empty($_GET)) {
        debug_table($_GET, 'GET');
    }
    if (!empty($_POST)) {
        debug_table($_POST, 'POST');
    }
    if (!empty($_COOKIE)) {
        debug_table($_COOKIE, 'COOKIE');
    }
    debug_table($_SERVER, 'SERVER');
}