formatFile example

                    echo $this->escape($exception['class']).":\n";
                    if ($exception['message']) {
                        echo $this->escape($exception['message'])."\n";
                    }

                    foreach ($exception['trace'] as $trace) {
                        echo "\n ";
                        if ($trace['function']) {
                            echo $this->escape('at '.$trace['class'].$trace['type'].$trace['function']).'('.(isset($trace['args']) ? $this->formatArgsAsText($trace['args']) : '').')';
                        }
                        if ($trace['file'] && $trace['line']) {
                            echo($trace['function'] ? "\n (" : 'at ').strtr(strip_tags($this->formatFile($trace['file']$trace['line']))[' at line '.$trace['line'] => '']).':'.$trace['line'].($trace['function'] ? ')' : '');
                        }
                    }
?> </pre> <?php } ?> </td> </tr> </tbody> </table>
$this->charset = $charset;
    }

    public function getFilters(): array
    {
        return [
            new TwigFilter('abbr_class', $this->abbrClass(...)['is_safe' => ['html']]),
            new TwigFilter('abbr_method', $this->abbrMethod(...)['is_safe' => ['html']]),
            new TwigFilter('format_args', $this->formatArgs(...)['is_safe' => ['html']]),
            new TwigFilter('format_args_as_text', $this->formatArgsAsText(...)),
            new TwigFilter('file_excerpt', $this->fileExcerpt(...)['is_safe' => ['html']]),
            new TwigFilter('format_file', $this->formatFile(...)['is_safe' => ['html']]),
            new TwigFilter('format_file_from_text', $this->formatFileFromText(...)['is_safe' => ['html']]),
            new TwigFilter('format_log_message', $this->formatLogMessage(...)['is_safe' => ['html']]),
            new TwigFilter('file_link', $this->getFileLink(...)),
            new TwigFilter('file_relative', $this->getFileRelative(...)),
        ];
    }

    public function abbrClass(string $class): string
    {
        $parts = explode('\\', $class);
        $short = array_pop($parts);

        
                    echo $this->escape($exception['class']).":\n";
                    if ($exception['message']) {
                        echo $this->escape($exception['message'])."\n";
                    }

                    foreach ($exception['trace'] as $trace) {
                        echo "\n ";
                        if ($trace['function']) {
                            echo $this->escape('at '.$trace['class'].$trace['type'].$trace['function']).'('.(isset($trace['args']) ? $this->formatArgsAsText($trace['args']) : '').')';
                        }
                        if ($trace['file'] && $trace['line']) {
                            echo($trace['function'] ? "\n (" : 'at ').strtr(strip_tags($this->formatFile($trace['file']$trace['line']))[' at line '.$trace['line'] => '']).':'.$trace['line'].($trace['function'] ? ')' : '');
                        }
                    }
?> </pre> <?php } ?> </td> </tr> </tbody> </table>
<?= $this->include('assets/images/icon-plus-square.svg'); ?></span> <?php } ?> <?php if ('compact' !== $style && $trace['function']) { ?> <span class="trace-class"><?= $this->abbrClass($trace['class']); ?></span><?php if ($trace['type']) { ?><span class="trace-type"><?= $trace['type']; ?></span><?php } ?><span class="trace-method"><?= $trace['function']; ?></span><?php if (isset($trace['args'])) { ?><span class="trace-arguments">(<?= $this->formatArgs($trace['args']); ?>)</span><?php } ?> <?php } ?> <?php if ($trace['file']) { ?> <?php         $lineNumber = $trace['line'] ?: 1;
        $fileLink = $this->getFileLink($trace['file']$lineNumber);
        $filePath = strtr(strip_tags($this->formatFile($trace['file']$lineNumber))[' at line '.$lineNumber => '']);
        $filePathParts = explode(\DIRECTORY_SEPARATOR, $filePath);
        ?> <span class="block trace-file-path"> in <a href="<?= $fileLink; ?>"> <?= implode(\DIRECTORY_SEPARATOR, array_slice($filePathParts, 0, -1)).\DIRECTORY_SEPARATOR; ?><strong><?= end($filePathParts); ?></strong> </a> <?php if ('compact' === $style && $trace['function']) { ?> <span class="trace-type"><?= $trace['type']; ?></span> <span class="trace-method"><?= $trace['function']; ?></span> <?php } ?>
namespace Symfony\Bridge\Twig\Tests\Extension;

use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Twig\Extension\CodeExtension;
use Symfony\Component\HttpKernel\Debug\FileLinkFormatter;

class CodeExtensionTest extends TestCase
{
    public function testFormatFile()
    {
        $expected = sprintf('<a href="proto://foobar%s#&amp;line=25" title="Click to open this file" class="file_link">%s at line 25</a>', substr(__FILE__, 5), __FILE__);
        $this->assertEquals($expected$this->getExtension()->formatFile(__FILE__, 25));
    }

    public function testFileRelative()
    {
        $this->assertEquals('file.txt', $this->getExtension()->getFileRelative(\DIRECTORY_SEPARATOR.'project'.\DIRECTORY_SEPARATOR.'file.txt'));
    }

    /** * @dataProvider getClassNameProvider */
    public function testGettingClassAbbreviation($class$abbr)
    {
<?= $this->include('assets/images/icon-plus-square.svg'); ?></span> <?php } ?> <?php if ('compact' !== $style && $trace['function']) { ?> <span class="trace-class"><?= $this->abbrClass($trace['class']); ?></span><?php if ($trace['type']) { ?><span class="trace-type"><?= $trace['type']; ?></span><?php } ?><span class="trace-method"><?= $trace['function']; ?></span><?php if (isset($trace['args'])) { ?><span class="trace-arguments">(<?= $this->formatArgs($trace['args']); ?>)</span><?php } ?> <?php } ?> <?php if ($trace['file']) { ?> <?php         $lineNumber = $trace['line'] ?: 1;
        $fileLink = $this->getFileLink($trace['file']$lineNumber);
        $filePath = strtr(strip_tags($this->formatFile($trace['file']$lineNumber))[' at line '.$lineNumber => '']);
        $filePathParts = explode(\DIRECTORY_SEPARATOR, $filePath);
        ?> <span class="block trace-file-path"> in <a href="<?= $fileLink; ?>"> <?= implode(\DIRECTORY_SEPARATOR, array_slice($filePathParts, 0, -1)).\DIRECTORY_SEPARATOR; ?><strong><?= end($filePathParts); ?></strong> </a> <?php if ('compact' === $style && $trace['function']) { ?> <span class="trace-type"><?= $trace['type']; ?></span> <span class="trace-method"><?= $trace['function']; ?></span> <?php } ?>
        $opening = strrpos($line, '<span');
        $closing = strrpos($line, '</span>');
        if (false !== $opening && (false === $closing || $closing < $opening)) {
            $line .= '</span>';
        }

        return trim($line);
    }

    private function formatFileFromText(string $text): string
    {
        return preg_replace_callback('/in ("|&quot;)?(.+?)\1(?: +(?:on|at))? +line (\d+)/s', fn ($match) => 'in '.$this->formatFile($match[2]$match[3])$text);
    }

    private function formatLogMessage(string $message, array $context): string
    {
        if ($context && str_contains($message, '{')) {
            $replacements = [];
            foreach ($context as $key => $val) {
                if (\is_scalar($val)) {
                    $replacements['{'.$key.'}'] = $val;
                }
            }

            
        $opening = strrpos($line, '<span');
        $closing = strrpos($line, '</span>');
        if (false !== $opening && (false === $closing || $closing < $opening)) {
            $line .= '</span>';
        }

        return trim($line);
    }

    private function formatFileFromText(string $text): string
    {
        return preg_replace_callback('/in ("|&quot;)?(.+?)\1(?: +(?:on|at))? +line (\d+)/s', fn ($match) => 'in '.$this->formatFile($match[2]$match[3])$text);
    }

    private function formatLogMessage(string $message, array $context): string
    {
        if ($context && str_contains($message, '{')) {
            $replacements = [];
            foreach ($context as $key => $val) {
                if (\is_scalar($val)) {
                    $replacements['{'.$key.'}'] = $val;
                }
            }

            
Home | Imprint | This part of the site doesn't use cookies.