Автор: Nicolas Grekas (p@tchwork.com)
Наследование: extends Symfony\Component\VarDumper\Dumper\CliDumper
Пример #1
0
 public function dump(\Twig_Environment $env, $context)
 {
     if (!$env->isDebug() || !$this->cloner) {
         return;
     }
     if (2 === func_num_args()) {
         $vars = array();
         foreach ($context as $key => $value) {
             if (!$value instanceof \Twig_Template) {
                 $vars[$key] = $value;
             }
         }
         $vars = array($vars);
     } else {
         $vars = func_get_args();
         unset($vars[0], $vars[1]);
     }
     $html = '';
     $dumper = new HtmlDumper(function ($line, $depth) use(&$html) {
         if (-1 !== $depth) {
             $html .= str_repeat('  ', $depth) . $line . "\n";
         }
     });
     foreach ($vars as $value) {
         $dumper->dump($this->cloner->cloneVar($value));
     }
     return $html;
 }
 public function dump(\Twig_Environment $env, $context)
 {
     if (!$env->isDebug()) {
         return;
     }
     if (2 === func_num_args()) {
         $vars = array();
         foreach ($context as $key => $value) {
             if (!$value instanceof \Twig_Template) {
                 $vars[$key] = $value;
             }
         }
         $vars = array($vars);
     } else {
         $vars = func_get_args();
         unset($vars[0], $vars[1]);
     }
     $dump = fopen('php://memory', 'r+b');
     $dumper = new HtmlDumper($dump);
     foreach ($vars as $value) {
         $dumper->dump($this->cloner->cloneVar($value));
     }
     rewind($dump);
     return stream_get_contents($dump);
 }
Пример #3
0
 public function __invoke($var)
 {
     ob_start();
     $this->dumper->dump($this->cloner->cloneVar($var));
     $result = ob_get_contents();
     ob_end_clean();
     return $result;
 }
Пример #4
0
 public function geny_dump($data)
 {
     $stream = fopen('php://memory', 'r+b');
     $dumper = new HtmlDumper($stream);
     $cloner = new VarCloner();
     $dumper->dump($cloner->cloneVar($data));
     rewind($stream);
     return stream_get_contents($stream);
 }
Пример #5
0
 public function dumpData(\Twig_Environment $env, Data $data, $maxDepth = 0)
 {
     $this->dumper->setCharset($env->getCharset());
     $this->dumper->dump($data, null, array('maxDepth' => $maxDepth));
     $dump = stream_get_contents($this->output, -1, 0);
     rewind($this->output);
     ftruncate($this->output, 0);
     return str_replace("\n</pre", '</pre', rtrim($dump));
 }
 private function getDumper()
 {
     if (!$this->htmlDumper && class_exists('Symfony\\Component\\VarDumper\\Cloner\\VarCloner')) {
         $this->htmlDumperOutput = new HtmlDumperOutput();
         // re-use the same var-dumper instance, so it won't re-render the global styles/scripts on each dump.
         $this->htmlDumper = new HtmlDumper($this->htmlDumperOutput);
         $styles = array('default' => 'color:#FFFFFF; line-height:normal; font:12px "Inconsolata", "Fira Mono", "Source Code Pro", Monaco, Consolas, "Lucida Console", monospace !important; word-wrap: break-word; white-space: pre-wrap; position:relative; z-index:99999; word-break: normal', 'num' => 'color:#BCD42A', 'const' => 'color: #4bb1b1;', 'str' => 'color:#BCD42A', 'note' => 'color:#ef7c61', 'ref' => 'color:#A0A0A0', 'public' => 'color:#FFFFFF', 'protected' => 'color:#FFFFFF', 'private' => 'color:#FFFFFF', 'meta' => 'color:#FFFFFF', 'key' => 'color:#BCD42A', 'index' => 'color:#ef7c61');
         $this->htmlDumper->setStyles($styles);
     }
     return $this->htmlDumper;
 }
 /**
  * It dumps the contents of the given variable. It tries several dumpers in
  * turn (VarDumper component, Yaml::dump, etc.) and if none is available, it
  * falls back to PHP's var_export().
  *
  * @param mixed $variable
  *
  * @return string
  */
 public function dump($variable)
 {
     if (class_exists('Symfony\\Component\\VarDumper\\Dumper\\HtmlDumper')) {
         $cloner = new VarCloner();
         $dumper = new HtmlDumper();
         return $dumper->dump($cloner->cloneVar($variable));
     } elseif (class_exists('Symfony\\Component\\Yaml\\Yaml')) {
         return sprintf('<pre class="sf-dump">%s</pre>', Yaml::dump((array) $variable, 1024));
     } else {
         return sprintf('<pre class="sf-dump">%s</pre>', var_export($variable, true));
     }
 }
Пример #8
0
 public static function dumper($obj)
 {
     ob_start();
     $cloner = new VarCloner();
     $dumper = new HtmlDumper();
     self::$handler = function ($obj) use($cloner, $dumper) {
         $dumper->dump($cloner->cloneVar($obj));
     };
     call_user_func(self::$handler, $obj);
     $ret = ob_get_contents();
     ob_end_clean();
     return $ret;
 }
 /**
  * It dumps the contents of the given variable. It tries several dumpers in
  * turn (VarDumper component, Yaml::dump, etc.) and if none is available, it
  * falls back to PHP's var_export().
  *
  * @param mixed $variable
  *
  * @return string
  */
 public function dump($variable)
 {
     $dumpedData = '';
     if (class_exists('Symfony\\Component\\VarDumper\\Dumper\\HtmlDumper')) {
         $cloner = new VarCloner();
         $dumper = new HtmlDumper();
         $dumper->dump($cloner->cloneVar($variable), $output = fopen('php://memory', 'r+b'));
         $dumpedData = stream_get_contents($output, -1, 0);
     } elseif (class_exists('Symfony\\Component\\Yaml\\Yaml')) {
         $dumpedData = sprintf('<pre class="sf-dump">%s</pre>', Yaml::dump((array) $variable, 1024));
     } else {
         $dumpedData = sprintf('<pre class="sf-dump">%s</pre>', var_export($variable, true));
     }
     return $dumpedData;
 }
Пример #10
0
 /**
  * Format the given value into a human readable string.
  *
  * @param  mixed $value
  * @return string
  */
 public function dump($value)
 {
     if (class_exists('Symfony\\Component\\VarDumper\\Cloner\\VarCloner')) {
         static $dumper = null;
         // re-use the same var-dumper instance, so it won't re-render the global styles/scripts on each dump.
         if (!$dumper) {
             $dumper = new HtmlDumper();
             $styles = array('default' => '', 'num' => '', 'const' => '', 'str' => '', 'note' => '', 'ref' => '', 'public' => '', 'protected' => '', 'private' => '', 'meta' => '', 'key' => '', 'index' => '');
             $dumper->setStyles($styles);
         }
         $cloner = new VarCloner();
         return $dumper->dump($cloner->cloneVar($value));
     }
     return print_r($value, true);
 }
Пример #11
0
 /**
  * {@inheritdoc}
  */
 protected function dumpLine($depth, $endOfValue = false)
 {
     if (-1 === $this->lastDepth && isset($_SERVER['REQUEST_TIME_FLOAT'])) {
         $this->dumpPrefix = $this->originalDumpPrefix . $this->prefix() . '<br />';
     }
     parent::dumpLine($depth, $endOfValue);
 }
Пример #12
0
 public function testCustomDumper()
 {
     $output = '';
     $lineDumper = function ($line) use(&$output) {
         $output .= $line;
     };
     $dumper = new HtmlDumper($lineDumper);
     $dumper->setDumpHeader('');
     $dumper->setDumpBoundaries('<pre class=sf-dump-test id=%s data-indent-pad="%s">', '</pre><script>Sfdump("%s")</script>');
     $extension = new DumpExtension(new VarCloner(), $dumper);
     $twig = new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('debug' => true, 'cache' => false, 'optimizations' => 0));
     $dump = $extension->dump($twig, array(), 'foo');
     $dump = preg_replace('/sf-dump-\\d+/', 'sf-dump', $dump);
     $this->assertEquals('<pre class=sf-dump-test id=sf-dump data-indent-pad="  ">"' . "<span class=sf-dump-str title=\"3 characters\">foo</span>\"\n" . "</pre><script>Sfdump(\"sf-dump\")</script>\n", $dump, 'Custom dumper should be used to dump data.');
     $this->assertEmpty($output, 'Dumper output should be ignored.');
 }
Пример #13
0
    public function testClassStubWithNotExistingMethod()
    {
        $var = array(new ClassStub('hello', array(FooInterface::class, 'missing')));
        $cloner = new VarCloner();
        $dumper = new HtmlDumper();
        $dumper->setDumpHeader('<foo></foo>');
        $dumper->setDumpBoundaries('<bar>', '</bar>');
        $dump = $dumper->dump($cloner->cloneVar($var), true);
        $expectedDump = <<<'EODUMP'
<foo></foo><bar><span class=sf-dump-note>array:1</span> [<samp>
  <span class=sf-dump-index>0</span> => "<a data-file="%sFooInterface.php" data-line="5"><span class=sf-dump-str title="5 characters">hello</span></a>"
</samp>]
</bar>
EODUMP;
        $this->assertStringMatchesFormat($expectedDump, $dump);
    }
Пример #14
0
    public function testHtmlDump()
    {
        $e = $this->getTestException(1);
        ExceptionCaster::$srcContext = -1;
        $cloner = new VarCloner();
        $cloner->setMaxItems(1);
        $dumper = new HtmlDumper();
        $dumper->setDumpHeader('<foo></foo>');
        $dumper->setDumpBoundaries('<bar>', '</bar>');
        $dump = $dumper->dump($cloner->cloneVar($e)->withRefHandles(false), true);
        $expectedDump = <<<'EODUMP'
<foo></foo><bar><span class=sf-dump-note>Exception</span> {<samp>
  #<span class=sf-dump-protected title="Protected property">message</span>: "<span class=sf-dump-str title="3 characters">foo</span>"
  #<span class=sf-dump-protected title="Protected property">code</span>: <span class=sf-dump-num>0</span>
  #<span class=sf-dump-protected title="Protected property">file</span>: "<span class=sf-dump-str title="%sExceptionCasterTest.php
%d characters"><span class=sf-dump-ellipsis>%sTests</span>%eCaster%eExceptionCasterTest.php</span>"
  #<span class=sf-dump-protected title="Protected property">line</span>: <span class=sf-dump-num>25</span>
  -<span class=sf-dump-private title="Private property defined in class:&#10;`Exception`">trace</span>: {<samp>
    <span class=sf-dump-meta title="%sExceptionCasterTest.php
Stack level %d."><span class=sf-dump-ellipsis>%sVarDumper%eTests</span>%eCaster%eExceptionCasterTest.php</span>: <span class=sf-dump-num>25</span>
     &hellip;12
  </samp>}
</samp>}
</bar>
EODUMP;
        $this->assertStringMatchesFormat($expectedDump, $dump);
    }
Пример #15
0
    public function testCharset()
    {
        if (!extension_loaded('mbstring')) {
            $this->markTestSkipped('This test requires mbstring.');
        }
        $var = mb_convert_encoding('Словарь', 'CP1251', 'UTF-8');
        $dumper = new HtmlDumper('php://output', 'CP1251');
        $dumper->setDumpHeader('<foo></foo>');
        $dumper->setDumpBoundaries('<bar>', '</bar>');
        $cloner = new VarCloner();
        $data = $cloner->cloneVar($var);
        $out = fopen('php://memory', 'r+b');
        $dumper->dump($data, $out);
        rewind($out);
        $out = stream_get_contents($out);
        $this->assertStringMatchesFormat(<<<EOTXT
<foo></foo><bar>b"<span class=sf-dump-str title="7 binary or non-UTF-8 characters">&#1057;&#1083;&#1086;&#1074;&#1072;&#1088;&#1100;</span>"
</bar>

EOTXT
, $out);
    }
Пример #16
0
 /**
  * Replaces the default output stream of Symfony's
  * CliDumper and HtmlDumper classes in order to
  * be able to run on Google App Engine.
  *
  * 'php://stdout' is used by CliDumper,
  * 'php://output' is used by HtmlDumper,
  * both are not supported on GAE.
  */
 protected function replaceDefaultSymfonyLineDumpers()
 {
     HtmlDumper::$defaultOutput = CliDumper::$defaultOutput = function ($line, $depth, $indentPad) {
         if (-1 !== $depth) {
             echo str_repeat($indentPad, $depth) . $line . PHP_EOL;
         }
     };
 }
Пример #17
0
    public function testGet()
    {
        require __DIR__ . '/Fixtures/dumb-var.php';
        $dumper = new HtmlDumper('php://output');
        $dumper->setColors(false);
        $dumper->setDumpHeader('<foo></foo>');
        $dumper->setDumpBoundaries('<bar>', '</bar>');
        $cloner = new VarCloner();
        $cloner->addCasters(array(':stream' => function ($res, $a) {
            unset($a['uri']);
            return $a;
        }));
        $data = $cloner->cloneVar($var);
        ob_start();
        $dumper->dump($data);
        $out = ob_get_clean();
        $closureLabel = PHP_VERSION_ID >= 50400 ? 'public method' : 'function';
        $out = preg_replace('/[ \\t]+$/m', '', $out);
        $var['file'] = htmlspecialchars($var['file'], ENT_QUOTES, 'UTF-8');
        $intMax = PHP_INT_MAX;
        preg_match('/sf-dump-\\d+/', $out, $dumpId);
        $dumpId = $dumpId[0];
        $res1 = (int) $var['res'];
        $res2 = (int) $var[8];
        $this->assertStringMatchesFormat(<<<EOTXT
<foo></foo><bar><span class=sf-dump-note>array:25</span> [<samp>
  "<span class=sf-dump-key>number</span>" => <span class=sf-dump-num>1</span>
  <span class=sf-dump-key>0</span> => <a class=sf-dump-ref href=#{$dumpId}-ref01 title="2 occurrences">&amp;1</a> <span class=sf-dump-const>null</span>
  "<span class=sf-dump-key>const</span>" => <span class=sf-dump-num>1.1</span>
  <span class=sf-dump-key>1</span> => <span class=sf-dump-const>true</span>
  <span class=sf-dump-key>2</span> => <span class=sf-dump-const>false</span>
  <span class=sf-dump-key>3</span> => <span class=sf-dump-num>NAN</span>
  <span class=sf-dump-key>4</span> => <span class=sf-dump-num>INF</span>
  <span class=sf-dump-key>5</span> => <span class=sf-dump-num>-INF</span>
  <span class=sf-dump-key>6</span> => <span class=sf-dump-num>{$intMax}</span>
  "<span class=sf-dump-key>str</span>" => "<span class=sf-dump-str title="4 characters">d&#233;j&#224;</span>"
  <span class=sf-dump-key>7</span> => b"<span class=sf-dump-str title="2 binary or non-UTF-8 characters">&#233;<span class=sf-dump-cchr title=\\x00>&#9216;</span></span>"
  "<span class=sf-dump-key>[]</span>" => []
  "<span class=sf-dump-key>res</span>" => <abbr title="`stream` resource" class=sf-dump-note>:stream</abbr> {<a class=sf-dump-ref>@{$res1}</a><samp>
    <span class=sf-dump-meta>wrapper_type</span>: "<span class=sf-dump-str title="9 characters">plainfile</span>"
    <span class=sf-dump-meta>stream_type</span>: "<span class=sf-dump-str title="5 characters">STDIO</span>"
    <span class=sf-dump-meta>mode</span>: "<span class=sf-dump-str>r</span>"
    <span class=sf-dump-meta>unread_bytes</span>: <span class=sf-dump-num>0</span>
    <span class=sf-dump-meta>seekable</span>: <span class=sf-dump-const>true</span>
    <span class=sf-dump-meta>timed_out</span>: <span class=sf-dump-const>false</span>
    <span class=sf-dump-meta>blocked</span>: <span class=sf-dump-const>true</span>
    <span class=sf-dump-meta>eof</span>: <span class=sf-dump-const>false</span>
    <span class=sf-dump-meta>options</span>: []
  </samp>}
  <span class=sf-dump-key>8</span> => <abbr title="`Unknown` resource" class=sf-dump-note>:Unknown</abbr> {<a class=sf-dump-ref>@{$res2}</a>}
  "<span class=sf-dump-key>obj</span>" => <abbr title="Symfony\\Component\\VarDumper\\Tests\\Fixture\\DumbFoo" class=sf-dump-note>DumbFoo</abbr> {<a class=sf-dump-ref href=#{$dumpId}-ref2%d title="2 occurrences">#%d</a><samp id={$dumpId}-ref2%d>
    +<span class=sf-dump-public title="Public property">foo</span>: "<span class=sf-dump-str title="3 characters">foo</span>"
    +"<span class=sf-dump-public title="Runtime added dynamic property">bar</span>": "<span class=sf-dump-str title="3 characters">bar</span>"
  </samp>}
  "<span class=sf-dump-key>closure</span>" => <span class=sf-dump-note>Closure</span> {<a class=sf-dump-ref>#%d</a><samp>
    <span class=sf-dump-meta>reflection</span>: """
      <span class=sf-dump-str title="%d characters">Closure [ &lt;user&gt; {$closureLabel} Symfony\\Component\\VarDumper\\Tests\\Fixture\\{closure} ] {</span>
      <span class=sf-dump-str title="%d characters">  @@ {$var['file']} {$var['line']} - {$var['line']}</span>

      <span class=sf-dump-str title="%d characters">  - Parameters [2] {</span>
      <span class=sf-dump-str title="%d characters">    Parameter #0 [ &lt;required&gt; \$a ]</span>
      <span class=sf-dump-str title="%d characters">    Parameter #1 [ &lt;optional&gt; PDO or NULL &amp;\$b = NULL ]</span>
      <span class=sf-dump-str title="%d characters">  }</span>
      <span class=sf-dump-str title="%d characters">}</span>
      """
  </samp>}
  "<span class=sf-dump-key>line</span>" => <span class=sf-dump-num>{$var['line']}</span>
  "<span class=sf-dump-key>nobj</span>" => <span class=sf-dump-note>array:1</span> [<samp>
    <span class=sf-dump-index>0</span> => <a class=sf-dump-ref href=#{$dumpId}-ref03 title="2 occurrences">&amp;3</a> {<a class=sf-dump-ref href=#{$dumpId}-ref2%d title="3 occurrences">#%d</a>}
  </samp>]
  "<span class=sf-dump-key>recurs</span>" => <a class=sf-dump-ref href=#{$dumpId}-ref04 title="2 occurrences">&amp;4</a> <span class=sf-dump-note>array:1</span> [<samp id={$dumpId}-ref04>
    <span class=sf-dump-index>0</span> => <a class=sf-dump-ref href=#{$dumpId}-ref04 title="2 occurrences">&amp;4</a> <span class=sf-dump-note>array:1</span> [<a class=sf-dump-ref href=#{$dumpId}-ref04 title="2 occurrences">&amp;4</a>]
  </samp>]
  <span class=sf-dump-key>9</span> => <a class=sf-dump-ref href=#{$dumpId}-ref01 title="2 occurrences">&amp;1</a> <span class=sf-dump-const>null</span>
  "<span class=sf-dump-key>sobj</span>" => <abbr title="Symfony\\Component\\VarDumper\\Tests\\Fixture\\DumbFoo" class=sf-dump-note>DumbFoo</abbr> {<a class=sf-dump-ref href=#{$dumpId}-ref2%d title="2 occurrences">#%d</a>}
  "<span class=sf-dump-key>snobj</span>" => <a class=sf-dump-ref href=#{$dumpId}-ref03 title="2 occurrences">&amp;3</a> {<a class=sf-dump-ref href=#{$dumpId}-ref2%d title="3 occurrences">#%d</a>}
  "<span class=sf-dump-key>snobj2</span>" => {<a class=sf-dump-ref href=#{$dumpId}-ref2%d title="3 occurrences">#%d</a>}
  "<span class=sf-dump-key>file</span>" => "<span class=sf-dump-str title="%d characters">{$var['file']}</span>"
  b"<span class=sf-dump-key>bin-key-&#233;</span>" => ""
</samp>]
</bar>

EOTXT
, $out);
    }
Пример #18
0
 public function getDumps($format, $maxDepthLimit = -1, $maxItemsPerDepth = -1)
 {
     $data = fopen('php://memory', 'r+b');
     if ('html' === $format) {
         $dumper = new HtmlDumper($data);
     } else {
         throw new \InvalidArgumentException(sprintf('Invalid dump format: %s', $format));
     }
     $dumps = array();
     foreach ($this->data as $dump) {
         $dumper->dump($dump['data']->getLimitedClone($maxDepthLimit, $maxItemsPerDepth));
         rewind($data);
         $dump['data'] = stream_get_contents($data);
         ftruncate($data, 0);
         rewind($data);
         $dumps[] = $dump;
     }
     return $dumps;
 }
Пример #19
0
 public function getDumps($format, $maxDepthLimit = -1, $maxItemsPerDepth = -1)
 {
     if ('html' === $format) {
         $dumper = new HtmlDumper();
     } else {
         throw new \InvalidArgumentException(sprintf('Invalid dump format: %s', $format));
     }
     $dumps = array();
     foreach ($this->data as $dump) {
         $data = '';
         $dumper->dump($dump['data']->getLimitedClone($maxDepthLimit, $maxItemsPerDepth), function ($line, $depth) use(&$data) {
             if (-1 !== $depth) {
                 $data .= str_repeat('  ', $depth) . $line . "\n";
             }
         });
         $dump['data'] = $data;
         $dumps[] = $dump;
     }
     return $dumps;
 }
Пример #20
0
    /**
     * {@inheritdoc}
     *
     * /home/[-USER-]/.local/share/applications/pstorm.desktop
     * [Desktop Entry]
     * Version=1.0
     * Type=Application
     * Name=PhpStorm Url Handler
     * Icon=/opt/phpstorm/bin/webide.png
     * Exec=sh -c "echo %u | sed 's/phpstorm:\/\///' | xargs /usr/local/bin/pstorm"
     * Categories=Development;IDE;
     * Terminal=false
     *
     * /home/[-USER-]/.local/share/applications/mimeapps.list
     * [Default Applications]
     * x-scheme-handler/phpstorm=pstorm.desktop
     */
    public function render(\Throwable $exception, int $index) : string
    {
        $fileLinkFormat = ini_get('xdebug.file_link_format') ?: 'phpstorm://%f:%l';
        $stacks = $this->exceptionStackTrace($exception);
        $out = <<<EOF
            <script type="text/javascript">
                function showFullArgs(uid, index)
                {
                    var args = document.getElementsByClassName("fullargs");
                    for (var key in args) {
                        if (args.hasOwnProperty(key)) {
                            if (args[key].className.indexOf("args-" + index + "-index") != -1 && 
                                args[key].className.indexOf("args-" + uid + "-uid") != -1
                            ) {
                                args[key].style.display = "block";
                            } else {
                                args[key].style.display = "none";
                            }
                        }
                    }

                }
            </script>
            <style type="text/css">
                .cawaException {
                    background-color:#fff;
                    z-index: 99999;
                    position: relative;
                    border-radius: 4px;
                    border:1px solid #ccc;
                    margin: 10px;
                    overflow: hidden;
                    word-wrap: break-word;
                    box-shadow: 0px 0px 10px grey;
                }

                .cawaException * {
                   font-family: 'Source Code Pro', Menlo, Monaco, Consolas, monospace;
                    color: #333;
                }

                .cawaException h1, .cawaException h2, .cawaException h3 {
                    background-color: FireBrick ;
                    color: white;
                    text-shadow: -1px 0 #333, 0 1px #333, 1px 0 #333, 0 -1px #333;
                    padding: 5 10px;
                    margin: 0;
                    font-size: 16px;
                    cursor: pointer;
                }

                .cawaException h2 {
                    border-bottom:1px solid #ccc;
                    font-size: 13px;
                }

                .cawaException pre.extract {
                    background-color:#2b2b2b; 
                    color:#a1acb2;
                    font-size: 11px;
                    margin-top: 0;
                    padding: 5 10px;
                }

                .cawaException pre.extract span {
                    background-color:#323232;
                    color:#a1acb2;
                    display: block;
                }

                .cawaException ol {
                    margin: 10px;
                }

                .cawaException ol li {
                    padding: 0 5px;
                    font-size: 11px;
                }

                .cawaException .line, .cawaException .args {
                    color : DarkGrey;
                    text-decoration: none;
                }


                .cawaException abbr {
                    font-weight: bold;
                }

                .cawaException .fullargs {
                    display: none;
                    padding: 0 5px;
                }


            </style>

EOF;
        $exceptionUid = uniqid();
        $out .= '<div class="cawaException">';
        $out .= '<h1 onclick="javascript:showFullArgs(\'' . $exceptionUid . '\', 0)">' . '#' . $index . ' ' . htmlspecialchars($exception->getMessage()) . "</h1>\n";
        $out .= '<h2>' . get_class($exception) . ' code(' . $exception->getCode() . ') in ' . $stacks[0]['file'];
        if (isset($stacks[0]['line'])) {
            $out .= ' line ' . $stacks[0]['line'];
        }
        $out .= "</h2>\n";
        if ($stacks[0]['file'] && isset($stacks[0]['line'])) {
            $files = file($stacks[0]['file']);
            if (isset($files[$stacks[0]['line'] - 1])) {
                $begin = array_map('htmlspecialchars', array_slice($files, max(0, $stacks[0]['line'] - 3), 2));
                $current = htmlspecialchars(array_slice($files, $stacks[0]['line'] - 1, 1)[0]);
                $end = array_map('htmlspecialchars', array_slice($files, $stacks[0]['line'], 2));
                $extract = array_merge($begin, ['<span class="current">' . $current . '</span>'], $end);
                $out .= '<pre class="extract">' . implode('', $extract) . "</pre>\n";
            }
        }
        $out .= "<ol>\n";
        $uid = uniqid();
        foreach ($stacks as $index => $stack) {
            $out .= "  <li>\n";
            if ($type = $this->getType($stack)) {
                $out .= '    at <abbr>' . $type . '</abbr>' . "\n";
            }
            if (isset($stack['args'])) {
                $out .= '    <a href="javascript:showFullArgs(\'' . $uid . '\', ' . $index . ')" class="args">' . htmlspecialchars($stack['args']) . '</a>' . "\n";
            }
            $link = '';
            if ($stack['file'] != '[internal function]' && $stack['file'] != '{main}') {
                $link = ' href="' . str_replace(['%f', '%l'], [$stack['file'], $stack['line'] ?? 1], $fileLinkFormat) . '"';
            }
            $out .= '    in <a class="file"' . $link . ' title="' . htmlentities($stack['file']) . '">' . basename($stack['file']) . '</a>' . "\n";
            if (isset($stack['line'])) {
                $out .= '    <span class="line"> line ' . $stack['line'] . '</span>';
            }
            // $out .= '    <span class="line" href="" title="' . htmlentities($stack["file"]) . '">\n' .
            $out .= "  </li>\n";
        }
        $out .= "</ol>\n";
        ob_start();
        $cloner = new VarCloner();
        $dumper = new HtmlDumper();
        $dumper->dump($cloner->cloneVar($exception));
        $out .= '<div class="fullargs args-' . $exceptionUid . '-uid args-0-index">' . ob_get_clean() . '</div>' . "\n";
        foreach ($stacks as $index => $stack) {
            if (isset($stack['fullargs'])) {
                foreach ($stack['fullargs'] as $argsIndex => $args) {
                    ob_start();
                    $cloner = new VarCloner();
                    $dumper = new HtmlDumper();
                    $dumper->dump($cloner->cloneVar($args));
                    $out .= '<div class="fullargs args-' . $uid . '-uid args-' . $index . '-index">' . ob_get_clean() . '</div>' . "\n";
                }
            }
        }
        $out .= "</div>\n";
        return $out;
    }
Пример #21
0
    public function testAppend()
    {
        $out = fopen('php://memory', 'r+b');
        $dumper = new HtmlDumper();
        $dumper->setDumpHeader('<foo></foo>');
        $dumper->setDumpBoundaries('<bar>', '</bar>');
        $cloner = new VarCloner();
        $dumper->dump($cloner->cloneVar(123), $out);
        $dumper->dump($cloner->cloneVar(456), $out);
        $out = stream_get_contents($out, -1, 0);
        $this->assertSame(<<<'EOTXT'
<foo></foo><bar><span class=sf-dump-num>123</span>
</bar>
<bar><span class=sf-dump-num>456</span>
</bar>

EOTXT
, $out);
    }
Пример #22
0
    public function testGet()
    {
        require __DIR__ . '/Fixtures/dumb-var.php';
        $dumper = new HtmlDumper('php://output');
        $dumper->setColors(false);
        $dumper->setDumpHeader('<foo></foo>');
        $dumper->setDumpBoundaries('<bar>', '</bar>');
        $cloner = new VarCloner();
        $cloner->addCasters(array(':stream' => function ($res, $a) {
            unset($a['uri']);
            return $a;
        }));
        $data = $cloner->cloneVar($var);
        ob_start();
        $dumper->dump($data);
        $out = ob_get_clean();
        $closureLabel = PHP_VERSION_ID >= 50400 ? 'public method' : 'function';
        $out = preg_replace('/[ \\t]+$/m', '', $out);
        $var['file'] = htmlspecialchars($var['file'], ENT_QUOTES, 'UTF-8');
        $intMax = PHP_INT_MAX;
        preg_match('/sf-dump-\\d+/', $out, $dumpId);
        $dumpId = $dumpId[0];
        $this->assertSame(<<<EOTXT
<foo></foo><bar><span class=sf-dump-note>array:25</span> [<span name=sf-dump-child>
  "<span class=sf-dump-meta>number</span>" => <span class=sf-dump-num>1</span>
  <span class=sf-dump-meta>0</span> => <span class=sf-dump-const>null</span> <span class=sf-dump-ref name=sf-dump-ref id="{$dumpId}-ref1">#1</span>
  "<span class=sf-dump-meta>const</span>" => <span class=sf-dump-num>1.1</span>
  <span class=sf-dump-meta>1</span> => <span class=sf-dump-const>true</span>
  <span class=sf-dump-meta>2</span> => <span class=sf-dump-const>false</span>
  <span class=sf-dump-meta>3</span> => <span class=sf-dump-num>NAN</span>
  <span class=sf-dump-meta>4</span> => <span class=sf-dump-num>INF</span>
  <span class=sf-dump-meta>5</span> => <span class=sf-dump-num>-INF</span>
  <span class=sf-dump-meta>6</span> => <span class=sf-dump-num>{$intMax}</span>
  "<span class=sf-dump-meta>str</span>" => "<span class=sf-dump-str>d&#233;j&#224;</span>"
  <span class=sf-dump-meta>7</span> => b"<span class=sf-dump-str>&#233;</span>"
  "<span class=sf-dump-meta>[]</span>" => []
  "<span class=sf-dump-meta>res</span>" => <abbr title="Resource of type `stream`" class=sf-dump-note>:stream</abbr> {<span name=sf-dump-child>
    <span class=sf-dump-meta>wrapper_type</span>: "<span class=sf-dump-str>plainfile</span>"
    <span class=sf-dump-meta>stream_type</span>: "<span class=sf-dump-str>STDIO</span>"
    <span class=sf-dump-meta>mode</span>: "<span class=sf-dump-str>r</span>"
    <span class=sf-dump-meta>unread_bytes</span>: <span class=sf-dump-num>0</span>
    <span class=sf-dump-meta>seekable</span>: <span class=sf-dump-const>true</span>
    <span class=sf-dump-meta>timed_out</span>: <span class=sf-dump-const>false</span>
    <span class=sf-dump-meta>blocked</span>: <span class=sf-dump-const>true</span>
    <span class=sf-dump-meta>eof</span>: <span class=sf-dump-const>false</span>
    <span class=sf-dump-meta>options</span>: []
  </span>}
  <span class=sf-dump-meta>8</span> => <abbr title="Resource of type `Unknown`" class=sf-dump-note>:Unknown</abbr> {}
  "<span class=sf-dump-meta>obj</span>" => <abbr title="Symfony\\Component\\VarDumper\\Tests\\Fixture\\DumbFoo" class=sf-dump-note>DumbFoo</abbr> {<span name=sf-dump-child> <span class=sf-dump-ref name=sf-dump-ref id="{$dumpId}-ref2">#2</span>
    <span class=sf-dump-public>foo</span>: "<span class=sf-dump-str>foo</span>"
    "<span class=sf-dump-public>bar</span>": "<span class=sf-dump-str>bar</span>"
  </span>}
  "<span class=sf-dump-meta>closure</span>" => <span class=sf-dump-note>Closure</span> {<span name=sf-dump-child>
    <span class=sf-dump-meta>reflection</span>: """
      <span class=sf-dump-str>Closure [ &lt;user&gt; {$closureLabel} Symfony\\Component\\VarDumper\\Tests\\Fixture\\{closure} ] {</span>
      <span class=sf-dump-str>  @@ {$var['file']} {$var['line']} - {$var['line']}</span>

      <span class=sf-dump-str>  - Parameters [2] {</span>
      <span class=sf-dump-str>    Parameter #0 [ &lt;required&gt; \$a ]</span>
      <span class=sf-dump-str>    Parameter #1 [ &lt;optional&gt; PDO or NULL &amp;\$b = NULL ]</span>
      <span class=sf-dump-str>  }</span>
      <span class=sf-dump-str>}</span>
      """
  </span>}
  "<span class=sf-dump-meta>line</span>" => <span class=sf-dump-num>{$var['line']}</span>
  "<span class=sf-dump-meta>nobj</span>" => <span class=sf-dump-note>array:1</span> [<span name=sf-dump-child>
    <span class=sf-dump-meta>0</span> => {} <span class=sf-dump-ref name=sf-dump-ref id="{$dumpId}-ref3">#3</span>
  </span>]
  "<span class=sf-dump-meta>recurs</span>" => <span class=sf-dump-note>array:1</span> [<span name=sf-dump-child> <span class=sf-dump-ref name=sf-dump-ref id="{$dumpId}-ref4">#4</span>
    <span class=sf-dump-meta>0</span> => <a class=sf-dump-ref name=sf-dump-ref href="#{$dumpId}-ref4">&4</a> <span class=sf-dump-note>array:1</span> [<a class=sf-dump-ref name=sf-dump-ref href="#{$dumpId}-ref4">@4</a>]
  </span>]
  <span class=sf-dump-meta>9</span> => <a class=sf-dump-ref name=sf-dump-ref href="#{$dumpId}-ref1">&1</a> <span class=sf-dump-const>null</span>
  "<span class=sf-dump-meta>sobj</span>" => <abbr title="Symfony\\Component\\VarDumper\\Tests\\Fixture\\DumbFoo" class=sf-dump-note>DumbFoo</abbr> {<a class=sf-dump-ref name=sf-dump-ref href="#{$dumpId}-ref2">@2</a>}
  "<span class=sf-dump-meta>snobj</span>" => <a class=sf-dump-ref name=sf-dump-ref href="#{$dumpId}-ref3">&3</a> {<a class=sf-dump-ref name=sf-dump-ref href="#{$dumpId}-ref3">@3</a>}
  "<span class=sf-dump-meta>snobj2</span>" => {<a class=sf-dump-ref name=sf-dump-ref href="#{$dumpId}-ref3">@3</a>}
  "<span class=sf-dump-meta>file</span>" => "<span class=sf-dump-str>{$var['file']}</span>"
  b"<span class=sf-dump-meta>bin-key-&#233;</span>" => ""
</span>]
</bar>

EOTXT
, $out);
    }
 private function htmlEncode($s)
 {
     $html = '';
     $dumper = new HtmlDumper(function ($line) use(&$html) {
         $html .= $line;
     }, $this->charset);
     $dumper->setDumpHeader('');
     $dumper->setDumpBoundaries('', '');
     $cloner = new VarCloner();
     $dumper->dump($cloner->cloneVar($s));
     return substr(strip_tags($html), 1, -1);
 }
Пример #24
0
 public function dump($var)
 {
     $dumper = new HtmlDumper();
     $cloner = new VarCloner();
     return $dumper->dump($cloner->cloneVar($var));
 }