* @param int $line The selected line number
* @param int $srcContext The number of displayed lines around or -1 for the whole file
*/
private function fileExcerpt(string $file, int $line, int $srcContext = 3): string
{
if (is_file($file) && is_readable($file)) {
// highlight_file could throw warnings
// see https://bugs.php.net/25725
$code = @highlight_file($file, true);
if (\PHP_VERSION_ID >= 80300) {
// remove main pre/code tags
</span>
<?php } ?>
</div>
<?php if ($trace['file']) { ?>
<div id="trace-html-<?= $prefix.'-'.$i; ?>" class="trace-code sf-toggle-content">
<?= strtr($this->fileExcerpt($trace['file'], $trace['line'], 5), [
'var(--highlight-string)' => 'var(--highlight-string)',
'var(--highlight-keyword)' => 'var(--highlight-keyword)',
'var(--highlight-default)' => 'var(--highlight-default)',
'var(--highlight-comment)' => 'var(--highlight-comment)',
]); ?>
private function include(string $name, array $context = []): string
{
extract($context, \EXTR_SKIP);
ob_start();
include is_file(\dirname(__DIR__).'/Resources/'.$name) ? \dirname(__DIR__).'/Resources/'.$name : $name;
return trim(ob_get_clean());
}
/**
<div class="trace-line <?= $isVendorTrace ? 'trace-from-vendor' : ''; ?>">
<?= $this->include('views/trace.html.php', [
'prefix' => $index,
'i' => $i,
'trace' => $trace,
'style' => $isVendorTrace ? 'compact' : ($displayCodeSnippet ? 'expanded' : ''),
]); ?>
</div>
<?php
} ?>
</div>
private function include(string $name, array $context = []): string
{
extract($context, \EXTR_SKIP);
ob_start();
include is_file(\dirname(__DIR__).'/Resources/'.$name) ? \dirname(__DIR__).'/Resources/'.$name : $name;
return trim(ob_get_clean());
}
/**
<?php
foreach ($exceptionAsArray as $i => $e) {
echo $this->include('views/traces.html.php', [
'exception' => $e,
'index' => $i + 1,
'expand' => in_array($i, $exceptionWithUserCode, true) || ([] === $exceptionWithUserCode && 0 === $i),
]);
}
?>
</div>
</div>
private function include(string $name, array $context = []): string
{
extract($context, \EXTR_SKIP);
ob_start();
include is_file(\dirname(__DIR__).'/Resources/'.$name) ? \dirname(__DIR__).'/Resources/'.$name : $name;
return trim(ob_get_clean());
}
/**
</div>
</div>
</header>
<?php } ?>
<?= $this->include('views/exception.html.php', $context); ?>
<script>
<?= $this->include('assets/js/exception.js'); ?>
</script>
</body>
private function include(string $name, array $context = []): string
{
extract($context, \EXTR_SKIP);
ob_start();
include is_file(\dirname(__DIR__).'/Resources/'.$name) ? \dirname(__DIR__).'/Resources/'.$name : $name;
return trim(ob_get_clean());
}
/**
'exception' => $exception,
'exceptionMessage' => $exceptionMessage,
'statusText' => $statusText,
'statusCode' => $statusCode,
'logger' => $this->logger instanceof DebugLoggerInterface ? $this->logger : null,
'currentContent' => \is_string($this->outputBuffer) ? $this->outputBuffer : ($this->outputBuffer)(),
]);
}
/**
* Formats an array as a string.
$headers['X-Debug-Exception-File'] = rawurlencode($exception->getFile()).':'.$exception->getLine();
}
$exception = FlattenException::createFromThrowable($exception, null, $headers);
return $exception->setAsString($this->renderException($exception));
}
/**
* Gets the HTML content associated with the given exception.
*/
/**
* {@inheritdoc}
*/
public function render(\Throwable $exception): FlattenException
{
$exception = $this->fallbackErrorRenderer->render($exception);
$debug = \is_bool($this->debug) ? $this->debug : ($this->debug)($exception);
if ($debug || !$template = $this->findTemplate($exception->getStatusCode())) {
return $exception;
}
$flattenException->setAsString($this->serializer->serialize($flattenException, $format, [
'exception' => $exception,
'debug' => $debug,
]));
} catch (NotEncodableValueException $e) {
$flattenException = $this->fallbackErrorRenderer->render($exception);
}
return $flattenException->setHeaders($flattenException->getHeaders() + $headers);
}
$this->errorRenderer = $errorRenderer;
}
public function __invoke(\Throwable $exception): Response
{
$exception = $this->errorRenderer->render($exception);
return new Response($exception->getAsString(), $exception->getStatusCode(), $exception->getHeaders());
}
public function preview(Request $request, int $code): Response
$this->dispatcher->dispatch($event, KernelEvents::CONTROLLER_ARGUMENTS);
$controller = $event->getController();
$arguments = $event->getArguments();
// call controller
$response = $controller(...$arguments);
// view
if (!$response instanceof Response) {
$event = new ViewEvent($this, $request, $type, $response);
$this->dispatcher->dispatch($event, KernelEvents::VIEW);
{
$request->headers->set('X-Php-Ob-Level', (string) ob_get_level());
$this->requestStack->push($request);
try {
return $this->handleRaw($request, $type);
} catch (\Exception $e) {
if ($e instanceof RequestExceptionInterface) {
$e = new BadRequestHttpException($e->getMessage(), $e);
}
if (false === $catch) {
$throwable = $event->getThrowable();
$request = $this->duplicateRequest($throwable, $event->getRequest());
try {
$response = $event->getKernel()->handle($request, HttpKernelInterface::SUB_REQUEST, false);
} catch (\Exception $e) {
$f = FlattenException::createFromThrowable($e);
$this->logException($e, sprintf('Exception thrown when handling an exception (%s: %s at %s line %s)', $f->getClass(), $f->getMessage(), $e->getFile(), $e->getLine()));
$this->priority = $dispatcher->getListenerPriority($eventName, $this->listener);
$e = $this->stopwatch->start($this->name, 'event_listener');
try {
($this->optimizedListener ?? $this->listener)($event, $eventName, $dispatcher);
} finally {
if ($e->isStarted()) {
$e->stop();
}
}
foreach ($listeners as $listener) {
if ($stoppable && $event->isPropagationStopped()) {
break;
}
$listener($event, $eventName, $this);
}
}
/**
* Sorts the internal list of listeners for the given event by priority.
} else {
$listeners = $this->getListeners($eventName);
}
if ($listeners) {
$this->callListeners($listeners, $eventName, $event);
}
return $event;
}
try {
$this->beforeDispatch($eventName, $event);
try {
$e = $this->stopwatch->start($eventName, 'section');
try {
$this->dispatcher->dispatch($event, $eventName);
} finally {
if ($e->isStarted()) {
$e->stop();
}
}
* @throws \Exception
*/
private function handleThrowable(\Throwable $e, Request $request, int $type): Response
{
$event = new ExceptionEvent($this, $request, $type, $e);
$this->dispatcher->dispatch($event, KernelEvents::EXCEPTION);
// a listener might have replaced the exception
$e = $event->getThrowable();
if (!$event->hasResponse()) {
$this->finishRequest($request, $type);
throw $e;
}
return $this->handleThrowable($e, $request, $type);
} finally {
$this->requestStack->pop();
}
}
$this->boot();
++$this->requestStackSize;
$this->resetServices = true;
try {
return $this->getHttpKernel()->handle($request, $type, $catch);
} finally {
--$this->requestStackSize;
}
}
$this->request = $request;
}
public function run(): int
{
$response = $this->kernel->handle($this->request);
$response->send();
if ($this->kernel instanceof TerminableInterface) {
$this->kernel->terminate($this->request, $response);
}
$app = $app(...$args);
exit(
$runtime
->getRunner($app)
->run()
);
<?php
use App\Kernel;
require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
return function (array $context) {
return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
};
* @param int $line The selected line number
* @param int $srcContext The number of displayed lines around or -1 for the whole file
*/
private function fileExcerpt(string $file, int $line, int $srcContext = 3): string
{
if (is_file($file) && is_readable($file)) {
// highlight_file could throw warnings
// see https://bugs.php.net/25725
$code = @highlight_file($file, true);
if (\PHP_VERSION_ID >= 80300) {
// remove main pre/code tags
</span>
<?php } ?>
</div>
<?php if ($trace['file']) { ?>
<div id="trace-html-<?= $prefix.'-'.$i; ?>" class="trace-code sf-toggle-content">
<?= strtr($this->fileExcerpt($trace['file'], $trace['line'], 5), [
'var(--highlight-string)' => 'var(--highlight-string)',
'var(--highlight-keyword)' => 'var(--highlight-keyword)',
'var(--highlight-default)' => 'var(--highlight-default)',
'var(--highlight-comment)' => 'var(--highlight-comment)',
]); ?>
private function include(string $name, array $context = []): string
{
extract($context, \EXTR_SKIP);
ob_start();
include is_file(\dirname(__DIR__).'/Resources/'.$name) ? \dirname(__DIR__).'/Resources/'.$name : $name;
return trim(ob_get_clean());
}
/**
<div class="trace-line <?= $isVendorTrace ? 'trace-from-vendor' : ''; ?>">
<?= $this->include('views/trace.html.php', [
'prefix' => $index,
'i' => $i,
'trace' => $trace,
'style' => $isVendorTrace ? 'compact' : ($displayCodeSnippet ? 'expanded' : ''),
]); ?>
</div>
<?php
} ?>
</div>
private function include(string $name, array $context = []): string
{
extract($context, \EXTR_SKIP);
ob_start();
include is_file(\dirname(__DIR__).'/Resources/'.$name) ? \dirname(__DIR__).'/Resources/'.$name : $name;
return trim(ob_get_clean());
}
/**
<?php
foreach ($exceptionAsArray as $i => $e) {
echo $this->include('views/traces.html.php', [
'exception' => $e,
'index' => $i + 1,
'expand' => in_array($i, $exceptionWithUserCode, true) || ([] === $exceptionWithUserCode && 0 === $i),
]);
}
?>
</div>
</div>
private function include(string $name, array $context = []): string
{
extract($context, \EXTR_SKIP);
ob_start();
include is_file(\dirname(__DIR__).'/Resources/'.$name) ? \dirname(__DIR__).'/Resources/'.$name : $name;
return trim(ob_get_clean());
}
/**
</div>
</div>
</header>
<?php } ?>
<?= $this->include('views/exception.html.php', $context); ?>
<script>
<?= $this->include('assets/js/exception.js'); ?>
</script>
</body>
private function include(string $name, array $context = []): string
{
extract($context, \EXTR_SKIP);
ob_start();
include is_file(\dirname(__DIR__).'/Resources/'.$name) ? \dirname(__DIR__).'/Resources/'.$name : $name;
return trim(ob_get_clean());
}
/**
'exception' => $exception,
'exceptionMessage' => $exceptionMessage,
'statusText' => $statusText,
'statusCode' => $statusCode,
'logger' => $this->logger instanceof DebugLoggerInterface ? $this->logger : null,
'currentContent' => \is_string($this->outputBuffer) ? $this->outputBuffer : ($this->outputBuffer)(),
]);
}
/**
* Formats an array as a string.
$headers['X-Debug-Exception-File'] = rawurlencode($exception->getFile()).':'.$exception->getLine();
}
$exception = FlattenException::createFromThrowable($exception, null, $headers);
return $exception->setAsString($this->renderException($exception));
}
/**
* Gets the HTML content associated with the given exception.
*/
/**
* {@inheritdoc}
*/
public function render(\Throwable $exception): FlattenException
{
$exception = $this->fallbackErrorRenderer->render($exception);
$debug = \is_bool($this->debug) ? $this->debug : ($this->debug)($exception);
if ($debug || !$template = $this->findTemplate($exception->getStatusCode())) {
return $exception;
}
$flattenException->setAsString($this->serializer->serialize($flattenException, $format, [
'exception' => $exception,
'debug' => $debug,
]));
} catch (NotEncodableValueException $e) {
$flattenException = $this->fallbackErrorRenderer->render($exception);
}
return $flattenException->setHeaders($flattenException->getHeaders() + $headers);
}
$this->errorRenderer = $errorRenderer;
}
public function __invoke(\Throwable $exception): Response
{
$exception = $this->errorRenderer->render($exception);
return new Response($exception->getAsString(), $exception->getStatusCode(), $exception->getHeaders());
}
public function preview(Request $request, int $code): Response
$this->dispatcher->dispatch($event, KernelEvents::CONTROLLER_ARGUMENTS);
$controller = $event->getController();
$arguments = $event->getArguments();
// call controller
$response = $controller(...$arguments);
// view
if (!$response instanceof Response) {
$event = new ViewEvent($this, $request, $type, $response);
$this->dispatcher->dispatch($event, KernelEvents::VIEW);
{
$request->headers->set('X-Php-Ob-Level', (string) ob_get_level());
$this->requestStack->push($request);
try {
return $this->handleRaw($request, $type);
} catch (\Exception $e) {
if ($e instanceof RequestExceptionInterface) {
$e = new BadRequestHttpException($e->getMessage(), $e);
}
if (false === $catch) {
$throwable = $event->getThrowable();
$request = $this->duplicateRequest($throwable, $event->getRequest());
try {
$response = $event->getKernel()->handle($request, HttpKernelInterface::SUB_REQUEST, false);
} catch (\Exception $e) {
$f = FlattenException::createFromThrowable($e);
$this->logException($e, sprintf('Exception thrown when handling an exception (%s: %s at %s line %s)', $f->getClass(), $f->getMessage(), $e->getFile(), $e->getLine()));
$this->priority = $dispatcher->getListenerPriority($eventName, $this->listener);
$e = $this->stopwatch->start($this->name, 'event_listener');
try {
($this->optimizedListener ?? $this->listener)($event, $eventName, $dispatcher);
} finally {
if ($e->isStarted()) {
$e->stop();
}
}
foreach ($listeners as $listener) {
if ($stoppable && $event->isPropagationStopped()) {
break;
}
$listener($event, $eventName, $this);
}
}
/**
* Sorts the internal list of listeners for the given event by priority.
} else {
$listeners = $this->getListeners($eventName);
}
if ($listeners) {
$this->callListeners($listeners, $eventName, $event);
}
return $event;
}
try {
$this->beforeDispatch($eventName, $event);
try {
$e = $this->stopwatch->start($eventName, 'section');
try {
$this->dispatcher->dispatch($event, $eventName);
} finally {
if ($e->isStarted()) {
$e->stop();
}
}
* @throws \Exception
*/
private function handleThrowable(\Throwable $e, Request $request, int $type): Response
{
$event = new ExceptionEvent($this, $request, $type, $e);
$this->dispatcher->dispatch($event, KernelEvents::EXCEPTION);
// a listener might have replaced the exception
$e = $event->getThrowable();
if (!$event->hasResponse()) {
if ($pop = $request !== $this->requestStack->getMainRequest()) {
$this->requestStack->push($request);
}
try {
$response = $this->handleThrowable($exception, $request, self::MAIN_REQUEST);
} finally {
if ($pop) {
$this->requestStack->pop();
}
}
if ($hasRun) {
throw $e;
}
$hasRun = true;
$kernel->terminateWithException($e, $request);
};
}
} elseif ($event instanceof ConsoleEvent && $app = $event->getCommand()->getApplication()) {
$output = $event->getOutput();
if ($output instanceof ConsoleOutputInterface) {
$this->exceptionHandler = null;
}
try {
if (null !== $exceptionHandler) {
return $exceptionHandler($exception);
}
$handlerException = $handlerException ?: $exception;
} catch (\Throwable $handlerException) {
}
if ($exception === $handlerException && null === $this->exceptionHandler) {
* @param int $line The selected line number
* @param int $srcContext The number of displayed lines around or -1 for the whole file
*/
private function fileExcerpt(string $file, int $line, int $srcContext = 3): string
{
if (is_file($file) && is_readable($file)) {
// highlight_file could throw warnings
// see https://bugs.php.net/25725
$code = @highlight_file($file, true);
if (\PHP_VERSION_ID >= 80300) {
// remove main pre/code tags
</span>
<?php } ?>
</div>
<?php if ($trace['file']) { ?>
<div id="trace-html-<?= $prefix.'-'.$i; ?>" class="trace-code sf-toggle-content">
<?= strtr($this->fileExcerpt($trace['file'], $trace['line'], 5), [
'var(--highlight-string)' => 'var(--highlight-string)',
'var(--highlight-keyword)' => 'var(--highlight-keyword)',
'var(--highlight-default)' => 'var(--highlight-default)',
'var(--highlight-comment)' => 'var(--highlight-comment)',
]); ?>
private function include(string $name, array $context = []): string
{
extract($context, \EXTR_SKIP);
ob_start();
include is_file(\dirname(__DIR__).'/Resources/'.$name) ? \dirname(__DIR__).'/Resources/'.$name : $name;
return trim(ob_get_clean());
}
/**
<div class="trace-line <?= $isVendorTrace ? 'trace-from-vendor' : ''; ?>">
<?= $this->include('views/trace.html.php', [
'prefix' => $index,
'i' => $i,
'trace' => $trace,
'style' => $isVendorTrace ? 'compact' : ($displayCodeSnippet ? 'expanded' : ''),
]); ?>
</div>
<?php
} ?>
</div>
private function include(string $name, array $context = []): string
{
extract($context, \EXTR_SKIP);
ob_start();
include is_file(\dirname(__DIR__).'/Resources/'.$name) ? \dirname(__DIR__).'/Resources/'.$name : $name;
return trim(ob_get_clean());
}
/**
<?php
foreach ($exceptionAsArray as $i => $e) {
echo $this->include('views/traces.html.php', [
'exception' => $e,
'index' => $i + 1,
'expand' => in_array($i, $exceptionWithUserCode, true) || ([] === $exceptionWithUserCode && 0 === $i),
]);
}
?>
</div>
</div>
private function include(string $name, array $context = []): string
{
extract($context, \EXTR_SKIP);
ob_start();
include is_file(\dirname(__DIR__).'/Resources/'.$name) ? \dirname(__DIR__).'/Resources/'.$name : $name;
return trim(ob_get_clean());
}
/**
</div>
</div>
</header>
<?php } ?>
<?= $this->include('views/exception.html.php', $context); ?>
<script>
<?= $this->include('assets/js/exception.js'); ?>
</script>
</body>
private function include(string $name, array $context = []): string
{
extract($context, \EXTR_SKIP);
ob_start();
include is_file(\dirname(__DIR__).'/Resources/'.$name) ? \dirname(__DIR__).'/Resources/'.$name : $name;
return trim(ob_get_clean());
}
/**
'exception' => $exception,
'exceptionMessage' => $exceptionMessage,
'statusText' => $statusText,
'statusCode' => $statusCode,
'logger' => $this->logger instanceof DebugLoggerInterface ? $this->logger : null,
'currentContent' => \is_string($this->outputBuffer) ? $this->outputBuffer : ($this->outputBuffer)(),
]);
}
/**
* Formats an array as a string.
$headers['X-Debug-Exception-File'] = rawurlencode($exception->getFile()).':'.$exception->getLine();
}
$exception = FlattenException::createFromThrowable($exception, null, $headers);
return $exception->setAsString($this->renderException($exception));
}
/**
* Gets the HTML content associated with the given exception.
*/
/**
* {@inheritdoc}
*/
public function render(\Throwable $exception): FlattenException
{
$exception = $this->fallbackErrorRenderer->render($exception);
$debug = \is_bool($this->debug) ? $this->debug : ($this->debug)($exception);
if ($debug || !$template = $this->findTemplate($exception->getStatusCode())) {
return $exception;
}
$flattenException->setAsString($this->serializer->serialize($flattenException, $format, [
'exception' => $exception,
'debug' => $debug,
]));
} catch (NotEncodableValueException $e) {
$flattenException = $this->fallbackErrorRenderer->render($exception);
}
return $flattenException->setHeaders($flattenException->getHeaders() + $headers);
}
$this->errorRenderer = $errorRenderer;
}
public function __invoke(\Throwable $exception): Response
{
$exception = $this->errorRenderer->render($exception);
return new Response($exception->getAsString(), $exception->getStatusCode(), $exception->getHeaders());
}
public function preview(Request $request, int $code): Response
$this->dispatcher->dispatch($event, KernelEvents::CONTROLLER_ARGUMENTS);
$controller = $event->getController();
$arguments = $event->getArguments();
// call controller
$response = $controller(...$arguments);
// view
if (!$response instanceof Response) {
$event = new ViewEvent($this, $request, $type, $response);
$this->dispatcher->dispatch($event, KernelEvents::VIEW);
{
$request->headers->set('X-Php-Ob-Level', (string) ob_get_level());
$this->requestStack->push($request);
try {
return $this->handleRaw($request, $type);
} catch (\Exception $e) {
if ($e instanceof RequestExceptionInterface) {
$e = new BadRequestHttpException($e->getMessage(), $e);
}
if (false === $catch) {
$throwable = $event->getThrowable();
$request = $this->duplicateRequest($throwable, $event->getRequest());
try {
$response = $event->getKernel()->handle($request, HttpKernelInterface::SUB_REQUEST, false);
} catch (\Exception $e) {
$f = FlattenException::createFromThrowable($e);
$this->logException($e, sprintf('Exception thrown when handling an exception (%s: %s at %s line %s)', $f->getClass(), $f->getMessage(), $e->getFile(), $e->getLine()));
$this->priority = $dispatcher->getListenerPriority($eventName, $this->listener);
$e = $this->stopwatch->start($this->name, 'event_listener');
try {
($this->optimizedListener ?? $this->listener)($event, $eventName, $dispatcher);
} finally {
if ($e->isStarted()) {
$e->stop();
}
}
foreach ($listeners as $listener) {
if ($stoppable && $event->isPropagationStopped()) {
break;
}
$listener($event, $eventName, $this);
}
}
/**
* Sorts the internal list of listeners for the given event by priority.
} else {
$listeners = $this->getListeners($eventName);
}
if ($listeners) {
$this->callListeners($listeners, $eventName, $event);
}
return $event;
}
try {
$this->beforeDispatch($eventName, $event);
try {
$e = $this->stopwatch->start($eventName, 'section');
try {
$this->dispatcher->dispatch($event, $eventName);
} finally {
if ($e->isStarted()) {
$e->stop();
}
}
* @throws \Exception
*/
private function handleThrowable(\Throwable $e, Request $request, int $type): Response
{
$event = new ExceptionEvent($this, $request, $type, $e);
$this->dispatcher->dispatch($event, KernelEvents::EXCEPTION);
// a listener might have replaced the exception
$e = $event->getThrowable();
if (!$event->hasResponse()) {
$this->finishRequest($request, $type);
throw $e;
}
return $this->handleThrowable($e, $request, $type);
} finally {
$this->requestStack->pop();
}
}
$this->boot();
++$this->requestStackSize;
$this->resetServices = true;
try {
return $this->getHttpKernel()->handle($request, $type, $catch);
} finally {
--$this->requestStackSize;
}
}
$this->request = $request;
}
public function run(): int
{
$response = $this->kernel->handle($this->request);
$response->send();
if ($this->kernel instanceof TerminableInterface) {
$this->kernel->terminate($this->request, $response);
}
$app = $app(...$args);
exit(
$runtime
->getRunner($app)
->run()
);
<?php
use App\Kernel;
require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
return function (array $context) {
return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
};