Logger::backtrace PHP Method

backtrace() public method

public backtrace ( $sh = null, $backtrace = null )
    public function backtrace($sh = null, $backtrace = null)
    {
        $output = "<div >\n";
        // TODO: allow extending backtrace option, so that
        $output .= "<b>Stack trace:</b><br />" . "<table style='border: 1px solid black; padding: 3px; text-align: left; font-family: verdana; " . "font-size: 10px' width=100% cellspacing=0 cellpadding=0 border=0>\n";
        $output .= "<tr><th align='right'>File</th><th>&nbsp;</th><th>Object Name</th><th>Stack Trace</th></tr>";
        if (!isset($backtrace)) {
            $backtrace = debug_backtrace();
        }
        $sh -= 2;
        $n = 0;
        foreach ($backtrace as $bt) {
            ++$n;
            $args = '';
            if (!isset($bt['args'])) {
                continue;
            }
            foreach ($bt['args'] as $a) {
                if (!empty($args)) {
                    $args .= ', ';
                }
                switch (gettype($a)) {
                    case 'integer':
                    case 'double':
                        $args .= $a;
                        break;
                    case 'string':
                        $a = htmlspecialchars(substr($a, 0, 128)) . (strlen($a) > 128 ? '...' : '');
                        $args .= "\"{$a}\"";
                        break;
                    case 'array':
                        $args .= 'Array(' . count($a) . ')';
                        break;
                    case 'object':
                        $args .= 'Object(' . get_class($a) . ')';
                        break;
                    case 'resource':
                        $args .= 'Resource(' . strstr((string) $a, '#') . ')';
                        break;
                    case 'boolean':
                        $args .= $a ? 'True' : 'False';
                        break;
                    case 'NULL':
                        $args .= 'Null';
                        break;
                    default:
                        $args .= 'Unknown';
                }
            }
            if ($sh == null && strpos($bt['file'], '/atk4/lib/') === false || !is_int($sh) && $bt['function'] == $sh) {
                $sh = $n;
            }
            $output .= '<tr><td valign=top align=right><font color=' . ($sh == $n ? 'red' : 'blue') . '>' . htmlspecialchars(dirname($bt['file'])) . '/' . '<b>' . htmlspecialchars(basename($bt['file'])) . '</b></font></td>';
            $output .= '<td valign=top nowrap><font color=' . ($sh == $n ? 'red' : 'blue') . ">:{$bt['line']}</font>&nbsp;</td>";
            $name = !isset($bt['object']->name) ? get_class($bt['object']) : $bt['object']->name;
            $output .= '<td>' . ($bt['object'] ? $name : '') . '</td>';
            $output .= '<td valign=top><font color=' . ($sh == $n ? 'red' : 'green') . '>' . get_class($bt['object']) . "{$bt['type']}<b>{$bt['function']}</b>({$args})</font></td></tr>\n";
        }
        $output .= "</table></div>\n";
        return $output;
    }

Usage Example

Example #1
0
 public static function transform($xml, $xsltName, $mimeType = 'text/html', $status = 200)
 {
     if (null !== self::$lock) {
         Logger::backtrace('XSLT recursion: ' . $xsltName . ' while in ' . self::$lock);
         throw new RuntimeException(t('Рекурсия в XSLT недопустима.'));
     }
     $mode = empty($_GET['xslt']) ? 'server' : $_GET['xslt'];
     $xml = self::fixEntities($xml);
     if ('none' == $mode or empty($xsltName)) {
         return new Response('<?xml version="1.0"?>' . $xml, 'text/xml', $status);
     }
     if (!file_exists($xsltName)) {
         throw new RuntimeException(t('Шаблон %name не найден.', array('%name' => $xsltName)));
     }
     if ('client' == $mode) {
         $xml = str_replace('?>', '?><?xml-stylesheet type="text/xsl" href="' . $xsltName . '"?>', $xml);
         return new Response($xml, 'text/xml');
     }
     $nocache = !empty($_GET['nocache']);
     $cache = cache::getInstance();
     $ckey = 'xml:xsl:' . md5($xml) . ',' . filemtime($xsltName);
     if (false === ($output = $cache->{$ckey}) or $nocache) {
         set_error_handler(array(__CLASS__, 'eh'));
         $doc = new DOMDocument();
         $doc->loadXML($xml);
         if (class_exists('xsltCache') and !$nocache) {
             $proc = new xsltCache();
             $proc->importStyleSheet($xsltName);
         } else {
             $xsl = new DOMDocument();
             @$xsl->load($xsltName);
             $proc = new XSLTProcessor();
             $proc->importStyleSheet($xsl);
         }
         self::$lock = $xsltName;
         if ($output = str_replace(' xmlns=""', '', $proc->transformToXML($doc))) {
             $cache->{$ckey} = $output;
         }
         self::$lock = null;
         restore_error_handler();
     }
     if (empty($output)) {
         throw new RuntimeException(t('Шаблон %xslt ничего не вернул.', array('%xslt' => $xsltName)));
     }
     if (null === $mimeType) {
         return trim(str_replace('<?xml version="1.0"?>', '', $output));
     }
     return new Response($output, $mimeType, $status);
 }
All Usage Examples Of Logger::backtrace