varToString example

// call controller         $response = $controller(...$arguments);

        // view         if (!$response instanceof Response) {
            $event = new ViewEvent($this$request$type$response$event);
            $this->dispatcher->dispatch($event, KernelEvents::VIEW);

            if ($event->hasResponse()) {
                $response = $event->getResponse();
            } else {
                $msg = sprintf('The controller must return a "Symfony\Component\HttpFoundation\Response" object but it returned %s.', $this->varToString($response));

                // the user may have forgotten to return something                 if (null === $response) {
                    $msg .= ' Did you forget to add a return statement somewhere in your controller?';
                }

                throw new ControllerDoesNotReturnResponseException($msg$controller, __FILE__, __LINE__ - 17);
            }
        }

        return $this->filterResponse($response$request$type);
    }
namespace Symfony\Component\Config\Exception;

/** * Exception class for when a circular reference is detected when importing resources. * * @author Fabien Potencier <fabien@symfony.com> */
class FileLoaderImportCircularReferenceException extends LoaderLoadException
{
    public function __construct(array $resources, int $code = 0, \Throwable $previous = null)
    {
        $message = sprintf('Circular reference detected in "%s" ("%s" > "%s").', $this->varToString($resources[0])implode('" > "', $resources)$resources[0]);

        \Exception::__construct($message$code$previous);
    }
}
// call controller         $response = $controller(...$arguments);

        // view         if (!$response instanceof Response) {
            $event = new ViewEvent($this$request$type$response$event);
            $this->dispatcher->dispatch($event, KernelEvents::VIEW);

            if ($event->hasResponse()) {
                $response = $event->getResponse();
            } else {
                $msg = sprintf('The controller must return a "Symfony\Component\HttpFoundation\Response" object but it returned %s.', $this->varToString($response));

                // the user may have forgotten to return something                 if (null === $response) {
                    $msg .= ' Did you forget to add a return statement somewhere in your controller?';
                }

                throw new ControllerDoesNotReturnResponseException($msg$controller, __FILE__, __LINE__ - 17);
            }
        }

        return $this->filterResponse($response$request$type);
    }

    protected function varToString(mixed $var)
    {
        if (\is_object($var)) {
            return sprintf('Object(%s)', $var::class);
        }

        if (\is_array($var)) {
            $a = [];
            foreach ($var as $k => $v) {
                $a[] = sprintf('%s => %s', $k$this->varToString($v));
            }

            return sprintf('Array(%s)', implode(', ', $a));
        }

        if (\is_resource($var)) {
            return sprintf('Resource(%s)', get_resource_type($var));
        }

        if (null === $var) {
            return 'null';
        }
Home | Imprint | This part of the site doesn't use cookies.