‘, [‘exception’ => $notFoundException, ‘request’ => $request]);
} else {
$response = $this->fallback($request, $type, $notFoundException);
}
}
if ($this->debug) {
$e[‘exception’] = $e[‘exception’] ?? $exception;
$e[‘request’] = $request;
}
try {
return $response->setException($exception);
} finally {
$this->throw($e, $request, $exception);
}
}
private function throw(array $e, Request $request, FlattenException $exception): void
{
if (!$this->debug && $previous = $exception->getPrevious()) {
throw $previous;
}
throw $e[‘exception’] ?? $exception;
}
private function fallback(Request $request, int $type, FlattenException $exception): Response
{
$fallback = $this->fallback;
if ($fallback instanceof \Closure) {
return $fallback($request, $exception);
}
if (\is_string($fallback)) {
if (str_contains($fallback, ‘://’)) {
return $this->redirect($request, $exception, $fallback);
}
} elseif ($fallback instanceof RequestMatcherInterface) {
if ($fallback->matches($request)) {
if ($fallback instanceof \Closure) {
return $fallback($request, $exception);
}
if (\is_string($fallback)) {
if (str_contains($fallback, ‘://’)) {
return $this->redirect($request, $exception, $fallback);
}
}
}
}
return new Response(
$exception->getStatusText(),
$exception->getStatusCode(),
$exception->getHeaders()
);
}
private function redirect(Request $request, FlattenException $exception, string $location): Response
{
$this->session?->getFlashBag()->add(‘error’, $this->sessionSafe(
$exception->getStatusText() ?: $request->attributes->get(‘_route’)
));
return new Response(
sprintf(‘
Redirecting to %1$s.
‘, htmlspecialchars($location, \ENT_QUOTES, ‘UTF-8’)),
302,
[
‘Location’ => $location,
‘Content-Type’ => ‘text/html’,
]
);
}
private function sessionSafe(string $text): string
{
if (!$this->session || !$this->session->isStarted()) {
return $text;
}
if ($this->session instanceof Session || method_exists($this->session, ‘getMetadataBag’)) {
// maintain compatibility with sessions implemented without the new `getMetadataBag` method
$usageIndex = method_exists($this->session, ‘getMetadataBag’) ? $this->session->getMetadataBag()->getLastUsed() : 0;
$usageIndex = $usageIndex ?: time();
} else {
$usageIndex = time();
}
return $usageIndex.’;
}
}
- Top 10 Companies in the Semiconductor Active Solder Industry (2026): Market Leaders Powering Global Electronics Manufacturing - January 12, 2026
- Top 10 Companies in the Caprylhydroxamic Acid for Skincare Market (2026): Industry Leaders Developing Multi-Functional Cosmetic Ingredients - January 12, 2026
- Top 10 Companies in the Dichloromethyl-n-propylsilane Industry (2026): Market Leaders Powering Advanced Material Innovations - January 12, 2026
