Skip to content

Commit 8fe3475

Browse files
Merge branch '5.4' into 6.0
* 5.4: [DependencyInjection] Add `SubscribedService` attribute, deprecate current `ServiceSubscriberTrait` usage Use try/finally to restore error handlers Allow serializer default context configuration
2 parents bd2510b + 9a2cabe commit 8fe3475

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

Firewall/ContextListener.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -272,29 +272,28 @@ protected function refreshUser(TokenInterface $token): ?TokenInterface
272272

273273
private function safelyUnserialize(string $serializedToken)
274274
{
275-
$e = $token = null;
275+
$token = null;
276276
$prevUnserializeHandler = ini_set('unserialize_callback_func', __CLASS__.'::handleUnserializeCallback');
277277
$prevErrorHandler = set_error_handler(function ($type, $msg, $file, $line, $context = []) use (&$prevErrorHandler) {
278278
if (__FILE__ === $file) {
279-
throw new \ErrorException($msg, 0x37313bc, $type, $file, $line);
279+
throw new \ErrorException($msg, 0x37313BC, $type, $file, $line);
280280
}
281281

282282
return $prevErrorHandler ? $prevErrorHandler($type, $msg, $file, $line, $context) : false;
283283
});
284284

285285
try {
286286
$token = unserialize($serializedToken);
287-
} catch (\Throwable $e) {
288-
}
289-
restore_error_handler();
290-
ini_set('unserialize_callback_func', $prevUnserializeHandler);
291-
if ($e) {
292-
if (!$e instanceof \ErrorException || 0x37313bc !== $e->getCode()) {
287+
} catch (\ErrorException $e) {
288+
if (0x37313BC !== $e->getCode()) {
293289
throw $e;
294290
}
295291
if ($this->logger) {
296292
$this->logger->warning('Failed to unserialize the security token from the session.', ['key' => $this->sessionKey, 'received' => $serializedToken, 'exception' => $e]);
297293
}
294+
} finally {
295+
restore_error_handler();
296+
ini_set('unserialize_callback_func', $prevUnserializeHandler);
298297
}
299298

300299
return $token;
@@ -347,6 +346,6 @@ private static function hasUserChanged(UserInterface $originalUser, TokenInterfa
347346
*/
348347
public static function handleUnserializeCallback(string $class)
349348
{
350-
throw new \ErrorException('Class not found: '.$class, 0x37313bc);
349+
throw new \ErrorException('Class not found: '.$class, 0x37313BC);
351350
}
352351
}

0 commit comments

Comments
 (0)