setAsString example

public function render(\Throwable $exception): FlattenException
    {
        $headers = ['Content-Type' => 'text/html; charset='.$this->charset];
        if (\is_bool($this->debug) ? $this->debug : ($this->debug)($exception)) {
            $headers['X-Debug-Exception'] = rawurlencode($exception->getMessage());
            $headers['X-Debug-Exception-File'] = rawurlencode($exception->getFile()).':'.$exception->getLine();
        }

        $exception = FlattenException::createWithDataRepresentation($exception, null, $headers);

        return $exception->setAsString($this->renderException($exception));
    }

    /** * Gets the HTML content associated with the given exception. */
    public function getBody(FlattenException $exception): string
    {
        return $this->renderException($exception, 'views/exception.html.php');
    }

    /** * Gets the stylesheet associated with the given exception. */


    public function render(\Throwable $exception): FlattenException
    {
        $flattenException = FlattenException::createFromThrowable($exception);
        $debug = \is_bool($this->debug) ? $this->debug : ($this->debug)($flattenException);

        if ($debug || !$template = $this->findTemplate($flattenException->getStatusCode())) {
            return $this->fallbackErrorRenderer->render($exception);
        }

        return $flattenException->setAsString($this->twig->render($template[
            'exception' => $flattenException,
            'status_code' => $flattenException->getStatusCode(),
            'status_text' => $flattenException->getStatusText(),
        ]));
    }

    public static function isDebug(RequestStack $requestStack, bool $debug): \Closure
    {
        return static function D) use ($requestStack$debug): bool {
            if (!$request = $requestStack->getCurrentRequest()) {
                return $debug;
            }
if ($debug) {
            $headers['X-Debug-Exception'] = rawurlencode($exception->getMessage());
            $headers['X-Debug-Exception-File'] = rawurlencode($exception->getFile()).':'.$exception->getLine();
        }

        $flattenException = FlattenException::createFromThrowable($exception, null, $headers);

        try {
            $format = \is_string($this->format) ? $this->format : ($this->format)($flattenException);
            $headers['Content-Type'] = Request::getMimeTypes($format)[0] ?? $format;

            $flattenException->setAsString($this->serializer->serialize($flattenException$format[
                'exception' => $exception,
                'debug' => $debug,
            ]));
        } catch (NotEncodableValueException) {
            $flattenException = $this->fallbackErrorRenderer->render($exception);
        }

        return $flattenException->setHeaders($flattenException->getHeaders() + $headers);
    }

    public static function getPreferredFormat(RequestStack $requestStack): \Closure
    {
$this->outputStream = fopen('php://stdout', 'w');

                try {
                    return parent::supportsColors();
                } finally {
                    $this->outputStream = $outputStream;
                }
            }
        };

        return FlattenException::createFromThrowable($exception)
            ->setAsString($dumper->dump($cloner->cloneVar($exception), true));
    }
}
$this->outputStream = fopen('php://stdout', 'w');

                try {
                    return parent::supportsColors();
                } finally {
                    $this->outputStream = $outputStream;
                }
            }
        };

        return FlattenException::createFromThrowable($exception)
            ->setAsString($dumper->dump($cloner->cloneVar($exception), true));
    }
}
if ($debug) {
            $headers['X-Debug-Exception'] = rawurlencode($exception->getMessage());
            $headers['X-Debug-Exception-File'] = rawurlencode($exception->getFile()).':'.$exception->getLine();
        }

        $flattenException = FlattenException::createFromThrowable($exception, null, $headers);

        try {
            $format = \is_string($this->format) ? $this->format : ($this->format)($flattenException);
            $headers['Content-Type'] = Request::getMimeTypes($format)[0] ?? $format;

            $flattenException->setAsString($this->serializer->serialize($flattenException$format[
                'exception' => $exception,
                'debug' => $debug,
            ]));
        } catch (NotEncodableValueException) {
            $flattenException = $this->fallbackErrorRenderer->render($exception);
        }

        return $flattenException->setHeaders($flattenException->getHeaders() + $headers);
    }

    public static function getPreferredFormat(RequestStack $requestStack): \Closure
    {
public function render(\Throwable $exception): FlattenException
    {
        $headers = ['Content-Type' => 'text/html; charset='.$this->charset];
        if (\is_bool($this->debug) ? $this->debug : ($this->debug)($exception)) {
            $headers['X-Debug-Exception'] = rawurlencode($exception->getMessage());
            $headers['X-Debug-Exception-File'] = rawurlencode($exception->getFile()).':'.$exception->getLine();
        }

        $exception = FlattenException::createWithDataRepresentation($exception, null, $headers);

        return $exception->setAsString($this->renderException($exception));
    }

    /** * Gets the HTML content associated with the given exception. */
    public function getBody(FlattenException $exception): string
    {
        return $this->renderException($exception, 'views/exception.html.php');
    }

    /** * Gets the stylesheet associated with the given exception. */
Home | Imprint | This part of the site doesn't use cookies.