dumpData example


        $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];
        yield ['Some message {foo}', ['bar' => 'bar'], false, true];
    }

    
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,
        ]);

        
return $records;
    }

    private function doFormat(array|LogRecord $record): mixed
    {
        if ($record instanceof LogRecord) {
            $record = $record->toArray();
        }
        $record = $this->replacePlaceHolder($record);

        if (!$this->options['ignore_empty_context_and_extra'] || !empty($record['context'])) {
            $context = ($this->options['multiline'] ? "\n" : ' ').$this->dumpData($record['context']);
        } else {
            $context = '';
        }

        if (!$this->options['ignore_empty_context_and_extra'] || !empty($record['extra'])) {
            $extra = ($this->options['multiline'] ? "\n" : ' ').$this->dumpData($record['extra']);
        } else {
            $extra = '';
        }

        $formatted = strtr($this->options['format'][
            
Home | Imprint | This part of the site doesn't use cookies.