dumpLog example

public function leave(Profile $profile): void
    {
        if (0 === --$this->stackLevel) {
            $this->dumper->setOutput($this->output = fopen('php://memory', 'r+'));
        }
    }

    public function getFunctions(): array
    {
        return [
            new TwigFunction('profiler_dump', $this->dumpData(...)['is_safe' => ['html'], 'needs_environment' => true]),
            new TwigFunction('profiler_dump_log', $this->dumpLog(...)['is_safe' => ['html'], 'needs_environment' => true]),
        ];
    }

    public function dumpData(Environment $env, Data $data, int $maxDepth = 0): string
    {
        $this->dumper->setCharset($env->getCharset());
        $this->dumper->dump($data, null, [
            'maxDepth' => $maxDepth,
        ]);

        $dump = stream_get_contents($this->output, -1, 0);
        

        class_exists(CoreExtension::class); // Load twig_convert_encoding()         class_exists(EscaperExtension::class); // Load twig_escape_filter()
        $twigEnvironment = $this->mockTwigEnvironment();
        $varCloner = new VarCloner();

        $webProfilerExtension = new WebProfilerExtension();

        $needle = 'window.Sfdump';

        $dump1 = $webProfilerExtension->dumpLog($twigEnvironment$message$varCloner->cloneVar($context));
        self::assertSame($dump1HasHeaderstr_contains($dump1$needle));

        $dump2 = $webProfilerExtension->dumpData($twigEnvironment$varCloner->cloneVar([]));
        self::assertSame($dump2HasHeaderstr_contains($dump2$needle));
    }

    public static function provideMessages(): iterable
    {
        yield ['Some message', ['foo' => 'foo', 'bar' => 'bar'], false, true];
        yield ['Some message {@see some text}', ['foo' => 'foo', 'bar' => 'bar'], false, true];
        yield ['Some message {foo}', ['foo' => 'foo', 'bar' => 'bar'], true, false];
        
Home | Imprint | This part of the site doesn't use cookies.