From 90c9a80863c67edb49129c6f83578f328a1a95d1 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 2 Dec 2019 17:36:40 +0100 Subject: [PATCH 1/5] [Config] never try loading failed classes twice with ClassExistenceResource --- .../Resource/ClassExistenceResource.php | 37 +++++++++++++++---- .../Config/Tests/Fixtures/BadFileName.php | 9 +++++ .../Resource/ClassExistenceResourceTest.php | 19 ++++++++++ 3 files changed, 57 insertions(+), 8 deletions(-) create mode 100644 src/Symfony/Component/Config/Tests/Fixtures/BadFileName.php diff --git a/src/Symfony/Component/Config/Resource/ClassExistenceResource.php b/src/Symfony/Component/Config/Resource/ClassExistenceResource.php index 4e0d0d834e..685da72850 100644 --- a/src/Symfony/Component/Config/Resource/ClassExistenceResource.php +++ b/src/Symfony/Component/Config/Resource/ClassExistenceResource.php @@ -36,7 +36,7 @@ class ClassExistenceResource implements SelfCheckingResourceInterface, \Serializ { $this->resource = $resource; if (null !== $exists) { - $this->exists = (bool) $exists; + $this->exists = [(bool) $exists, null]; } } @@ -65,9 +65,13 @@ class ClassExistenceResource implements SelfCheckingResourceInterface, \Serializ { $loaded = class_exists($this->resource, false) || interface_exists($this->resource, false) || trait_exists($this->resource, false); - if (null !== $exists = &self::$existsCache[(int) (0 >= $timestamp)][$this->resource]) { - $exists = $exists || $loaded; - } elseif (!$exists = $loaded) { + if (null !== $exists = &self::$existsCache[$this->resource]) { + if ($loaded) { + $exists = [true, null]; + } elseif (0 >= $timestamp && !$exists[0] && null !== $exists[1]) { + throw new \ReflectionException($exists[1]); + } + } elseif ([false, null] === $exists = [$loaded, null]) { if (!self::$autoloadLevel++) { spl_autoload_register(__CLASS__.'::throwOnRequiredClass'); } @@ -75,16 +79,19 @@ class ClassExistenceResource implements SelfCheckingResourceInterface, \Serializ self::$autoloadedClass = ltrim($this->resource, '\\'); try { - $exists = class_exists($this->resource) || interface_exists($this->resource, false) || trait_exists($this->resource, false); + $exists[0] = class_exists($this->resource) || interface_exists($this->resource, false) || trait_exists($this->resource, false); } catch (\Exception $e) { + $exists[1] = $e->getMessage(); + try { self::throwOnRequiredClass($this->resource, $e); } catch (\ReflectionException $e) { if (0 >= $timestamp) { - unset(self::$existsCache[1][$this->resource]); throw $e; } } + } catch (\Throwable $e) { + $exists[1] = $e->getMessage(); } finally { self::$autoloadedClass = $autoloadedClass; if (!--self::$autoloadLevel) { @@ -97,7 +104,7 @@ class ClassExistenceResource implements SelfCheckingResourceInterface, \Serializ $this->exists = $exists; } - return $this->exists xor !$exists; + return $this->exists[0] xor !$exists[0]; } /** @@ -118,6 +125,10 @@ class ClassExistenceResource implements SelfCheckingResourceInterface, \Serializ public function unserialize($serialized) { list($this->resource, $this->exists) = unserialize($serialized); + + if (\is_bool($this->exists)) { + $this->exists = [$this->exists, null]; + } } /** @@ -155,7 +166,17 @@ class ClassExistenceResource implements SelfCheckingResourceInterface, \Serializ throw $previous; } - $e = new \ReflectionException(sprintf('Class "%s" not found while loading "%s".', $class, self::$autoloadedClass), 0, $previous); + $message = sprintf('Class "%s" not found.', $class); + + if (self::$autoloadedClass !== $class) { + $message = substr_replace($message, sprintf(' while loading "%s"', self::$autoloadedClass), -1, 0); + } + + if (null !== $previous) { + $message = $previous->getMessage(); + } + + $e = new \ReflectionException($message, 0, $previous); if (null !== $previous) { throw $e; diff --git a/src/Symfony/Component/Config/Tests/Fixtures/BadFileName.php b/src/Symfony/Component/Config/Tests/Fixtures/BadFileName.php new file mode 100644 index 0000000000..0f79bdd523 --- /dev/null +++ b/src/Symfony/Component/Config/Tests/Fixtures/BadFileName.php @@ -0,0 +1,9 @@ +isFresh(0); } + public function testBadFileName() + { + $this->expectException('ReflectionException'); + $this->expectExceptionMessage('Mismatch between file name and class name.'); + + $res = new ClassExistenceResource(BadFileName::class, false); + $res->isFresh(0); + } + + public function testBadFileNameBis() + { + $this->expectException('ReflectionException'); + $this->expectExceptionMessage('Mismatch between file name and class name.'); + + $res = new ClassExistenceResource(BadFileName::class, false); + $res->isFresh(0); + } + public function testConditionalClass() { $res = new ClassExistenceResource(ConditionalClass::class, false); From de03cee8466d4e70c3dca7451002142b0631c617 Mon Sep 17 00:00:00 2001 From: Thomas Calvet Date: Tue, 3 Dec 2019 18:42:58 +0100 Subject: [PATCH 2/5] [SecurityBundle] Properly escape regex in AddSessionDomainConstraintPass --- .../Compiler/AddSessionDomainConstraintPass.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Compiler/AddSessionDomainConstraintPass.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Compiler/AddSessionDomainConstraintPass.php index 27098f8b19..7fd323a5f2 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Compiler/AddSessionDomainConstraintPass.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Compiler/AddSessionDomainConstraintPass.php @@ -31,7 +31,7 @@ class AddSessionDomainConstraintPass implements CompilerPassInterface } $sessionOptions = $container->getParameter('session.storage.options'); - $domainRegexp = empty($sessionOptions['cookie_domain']) ? '%s' : sprintf('(?:%%s|(?:.+\.)?%s)', preg_quote(trim($sessionOptions['cookie_domain'], '.'))); + $domainRegexp = empty($sessionOptions['cookie_domain']) ? '%%s' : sprintf('(?:%%%%s|(?:.+\.)?%s)', preg_quote(trim($sessionOptions['cookie_domain'], '.'))); $domainRegexp = (empty($sessionOptions['cookie_secure']) ? 'https?://' : 'https://').$domainRegexp; $container->findDefinition('security.http_utils')->addArgument(sprintf('{^%s$}i', $domainRegexp)); From 7ab53f9a397f07e1189411a6ac9e7c8241b9fc9b Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Wed, 4 Dec 2019 12:33:46 +0100 Subject: [PATCH 3/5] fix parsing negative octal numbers --- src/Symfony/Component/Yaml/Inline.php | 10 +++++----- src/Symfony/Component/Yaml/Tests/InlineTest.php | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/Symfony/Component/Yaml/Inline.php b/src/Symfony/Component/Yaml/Inline.php index 7d3218a35e..aef68c7b2f 100644 --- a/src/Symfony/Component/Yaml/Inline.php +++ b/src/Symfony/Component/Yaml/Inline.php @@ -735,11 +735,11 @@ class Inline // Optimize for returning strings. // no break case '+' === $scalar[0] || '-' === $scalar[0] || '.' === $scalar[0] || is_numeric($scalar[0]): + if (Parser::preg_match('{^[+-]?[0-9][0-9_]*$}', $scalar)) { + $scalar = str_replace('_', '', (string) $scalar); + } + switch (true) { - case Parser::preg_match('{^[+-]?[0-9][0-9_]*$}', $scalar): - $scalar = str_replace('_', '', (string) $scalar); - // omitting the break / return as integers are handled in the next case - // no break case ctype_digit($scalar): $raw = $scalar; $cast = (int) $scalar; @@ -749,7 +749,7 @@ class Inline $raw = $scalar; $cast = (int) $scalar; - return '0' == $scalar[1] ? octdec($scalar) : (((string) $raw === (string) $cast) ? $cast : $raw); + return '0' == $scalar[1] ? -octdec(substr($scalar, 1)) : (($raw === (string) $cast) ? $cast : $raw); case is_numeric($scalar): case Parser::preg_match(self::getHexRegex(), $scalar): $scalar = str_replace('_', '', $scalar); diff --git a/src/Symfony/Component/Yaml/Tests/InlineTest.php b/src/Symfony/Component/Yaml/Tests/InlineTest.php index 014a12a706..3f3b913f7b 100644 --- a/src/Symfony/Component/Yaml/Tests/InlineTest.php +++ b/src/Symfony/Component/Yaml/Tests/InlineTest.php @@ -781,4 +781,20 @@ class InlineTest extends TestCase $this->expectExceptionMessage('Unexpected end of line, expected one of ",}" at line 1 (near "{abc: \'def\'").'); Inline::parse("{abc: 'def'"); } + + /** + * @dataProvider getTestsForOctalNumbers + */ + public function testParseOctalNumbers($expected, $yaml) + { + self::assertSame($expected, Inline::parse($yaml)); + } + + public function getTestsForOctalNumbers() + { + return [ + 'positive octal number' => [28, '034'], + 'negative octal number' => [-28, '-034'], + ]; + } } From 4194c4c56d4759e70b4ec4e7a4d504acb3ba38f4 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 5 Dec 2019 18:09:30 +0100 Subject: [PATCH 4/5] [Cache] fix memory leak when using PhpArrayAdapter --- .../Component/Cache/Adapter/PhpArrayAdapter.php | 5 ++--- src/Symfony/Component/Cache/Simple/PhpArrayCache.php | 6 +++--- .../Cache/Tests/Adapter/PhpArrayAdapterTest.php | 2 ++ .../Adapter/PhpArrayAdapterWithFallbackTest.php | 2 ++ .../Cache/Tests/Simple/PhpArrayCacheTest.php | 2 ++ .../Tests/Simple/PhpArrayCacheWithFallbackTest.php | 2 ++ src/Symfony/Component/Cache/Traits/PhpArrayTrait.php | 12 +++++++++++- 7 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Component/Cache/Adapter/PhpArrayAdapter.php b/src/Symfony/Component/Cache/Adapter/PhpArrayAdapter.php index e03d37b94d..6df00d1d33 100644 --- a/src/Symfony/Component/Cache/Adapter/PhpArrayAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/PhpArrayAdapter.php @@ -61,14 +61,13 @@ class PhpArrayAdapter implements AdapterInterface, PruneableInterface, Resettabl * fallback pool with this adapter only if the current PHP version is supported. * * @param string $file The PHP file were values are cached - * @param CacheItemPoolInterface $fallbackPool Fallback for old PHP versions or opcache disabled + * @param CacheItemPoolInterface $fallbackPool A pool to fallback on when an item is not hit * * @return CacheItemPoolInterface */ public static function create($file, CacheItemPoolInterface $fallbackPool) { - // Shared memory is available in PHP 7.0+ with OPCache enabled and in HHVM - if ((\PHP_VERSION_ID >= 70000 && filter_var(ini_get('opcache.enable'), FILTER_VALIDATE_BOOLEAN)) || \defined('HHVM_VERSION')) { + if (\PHP_VERSION_ID >= 70000) { if (!$fallbackPool instanceof AdapterInterface) { $fallbackPool = new ProxyAdapter($fallbackPool); } diff --git a/src/Symfony/Component/Cache/Simple/PhpArrayCache.php b/src/Symfony/Component/Cache/Simple/PhpArrayCache.php index 607555e93b..5ded7ee741 100644 --- a/src/Symfony/Component/Cache/Simple/PhpArrayCache.php +++ b/src/Symfony/Component/Cache/Simple/PhpArrayCache.php @@ -44,14 +44,14 @@ class PhpArrayCache implements CacheInterface, PruneableInterface, ResettableInt * stores arrays in its latest versions. This factory method decorates the given * fallback pool with this adapter only if the current PHP version is supported. * - * @param string $file The PHP file were values are cached + * @param string $file The PHP file were values are cached + * @param CacheInterface $fallbackPool A pool to fallback on when an item is not hit * * @return CacheInterface */ public static function create($file, CacheInterface $fallbackPool) { - // Shared memory is available in PHP 7.0+ with OPCache enabled and in HHVM - if ((\PHP_VERSION_ID >= 70000 && filter_var(ini_get('opcache.enable'), FILTER_VALIDATE_BOOLEAN)) || \defined('HHVM_VERSION')) { + if (\PHP_VERSION_ID >= 70000) { return new static($file, $fallbackPool); } diff --git a/src/Symfony/Component/Cache/Tests/Adapter/PhpArrayAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/PhpArrayAdapterTest.php index 751f758cc2..f88a718739 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/PhpArrayAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/PhpArrayAdapterTest.php @@ -62,6 +62,8 @@ class PhpArrayAdapterTest extends AdapterTestCase protected function tearDown() { + $this->createCachePool()->clear(); + if (file_exists(sys_get_temp_dir().'/symfony-cache')) { FilesystemAdapterTest::rmdir(sys_get_temp_dir().'/symfony-cache'); } diff --git a/src/Symfony/Component/Cache/Tests/Adapter/PhpArrayAdapterWithFallbackTest.php b/src/Symfony/Component/Cache/Tests/Adapter/PhpArrayAdapterWithFallbackTest.php index 4bdd7580fc..0bfd5c3947 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/PhpArrayAdapterWithFallbackTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/PhpArrayAdapterWithFallbackTest.php @@ -37,6 +37,8 @@ class PhpArrayAdapterWithFallbackTest extends AdapterTestCase protected function tearDown() { + $this->createCachePool()->clear(); + if (file_exists(sys_get_temp_dir().'/symfony-cache')) { FilesystemAdapterTest::rmdir(sys_get_temp_dir().'/symfony-cache'); } diff --git a/src/Symfony/Component/Cache/Tests/Simple/PhpArrayCacheTest.php b/src/Symfony/Component/Cache/Tests/Simple/PhpArrayCacheTest.php index c18f714429..bcd7dea553 100644 --- a/src/Symfony/Component/Cache/Tests/Simple/PhpArrayCacheTest.php +++ b/src/Symfony/Component/Cache/Tests/Simple/PhpArrayCacheTest.php @@ -56,6 +56,8 @@ class PhpArrayCacheTest extends CacheTestCase protected function tearDown() { + $this->createSimpleCache()->clear(); + if (file_exists(sys_get_temp_dir().'/symfony-cache')) { FilesystemAdapterTest::rmdir(sys_get_temp_dir().'/symfony-cache'); } diff --git a/src/Symfony/Component/Cache/Tests/Simple/PhpArrayCacheWithFallbackTest.php b/src/Symfony/Component/Cache/Tests/Simple/PhpArrayCacheWithFallbackTest.php index eba749cece..b08c16043c 100644 --- a/src/Symfony/Component/Cache/Tests/Simple/PhpArrayCacheWithFallbackTest.php +++ b/src/Symfony/Component/Cache/Tests/Simple/PhpArrayCacheWithFallbackTest.php @@ -43,6 +43,8 @@ class PhpArrayCacheWithFallbackTest extends CacheTestCase protected function tearDown() { + $this->createSimpleCache()->clear(); + if (file_exists(sys_get_temp_dir().'/symfony-cache')) { FilesystemAdapterTest::rmdir(sys_get_temp_dir().'/symfony-cache'); } diff --git a/src/Symfony/Component/Cache/Traits/PhpArrayTrait.php b/src/Symfony/Component/Cache/Traits/PhpArrayTrait.php index ea996a217c..2400486f80 100644 --- a/src/Symfony/Component/Cache/Traits/PhpArrayTrait.php +++ b/src/Symfony/Component/Cache/Traits/PhpArrayTrait.php @@ -28,6 +28,8 @@ trait PhpArrayTrait private $values; private $zendDetectUnicode; + private static $valuesCache = []; + /** * Store an array of cached values. * @@ -107,6 +109,7 @@ EOF; unset($serialized, $unserialized, $value, $dump); @rename($tmpFile, $this->file); + unset(self::$valuesCache[$this->file]); $this->initialize(); } @@ -119,6 +122,7 @@ EOF; $this->values = []; $cleared = @unlink($this->file) || !file_exists($this->file); + unset(self::$valuesCache[$this->file]); return $this->pool->clear() && $cleared; } @@ -128,11 +132,17 @@ EOF; */ private function initialize() { + if (isset(self::$valuesCache[$this->file])) { + $this->values = self::$valuesCache[$this->file]; + + return; + } + if ($this->zendDetectUnicode) { $zmb = ini_set('zend.detect_unicode', 0); } try { - $this->values = file_exists($this->file) ? (include $this->file ?: []) : []; + $this->values = self::$valuesCache[$this->file] = file_exists($this->file) ? (include $this->file ?: []) : []; } finally { if ($this->zendDetectUnicode) { ini_set('zend.detect_unicode', $zmb); From d4ae85fc72794ce7e9231ce6e15466925544f39a Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 6 Dec 2019 14:04:56 +0100 Subject: [PATCH 5/5] gracefully handle missing event dispatchers --- .../Messenger/Middleware/SendMessageMiddleware.php | 8 +++++++- src/Symfony/Component/Messenger/Worker.php | 8 +++++++- .../Security/Core/Authorization/Voter/TraceableVoter.php | 7 ++++++- .../Security/Guard/GuardAuthenticatorHandler.php | 8 +++++++- .../Http/Firewall/AbstractAuthenticationListener.php | 8 +++++++- .../Http/Firewall/AbstractPreAuthenticatedListener.php | 7 ++++++- .../Component/Security/Http/Firewall/ContextListener.php | 8 +++++++- .../Security/Http/Firewall/RememberMeListener.php | 8 +++++++- .../Http/Firewall/SimplePreAuthenticationListener.php | 8 +++++++- .../Security/Http/Firewall/SwitchUserListener.php | 8 +++++++- .../UsernamePasswordJsonAuthenticationListener.php | 8 +++++++- src/Symfony/Component/Workflow/Workflow.php | 8 +++++++- 12 files changed, 82 insertions(+), 12 deletions(-) diff --git a/src/Symfony/Component/Messenger/Middleware/SendMessageMiddleware.php b/src/Symfony/Component/Messenger/Middleware/SendMessageMiddleware.php index 7d25cd5735..4ed900e1fb 100644 --- a/src/Symfony/Component/Messenger/Middleware/SendMessageMiddleware.php +++ b/src/Symfony/Component/Messenger/Middleware/SendMessageMiddleware.php @@ -39,7 +39,13 @@ class SendMessageMiddleware implements MiddlewareInterface public function __construct(SendersLocatorInterface $sendersLocator, EventDispatcherInterface $eventDispatcher = null) { $this->sendersLocator = $sendersLocator; - $this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher); + + if (null !== $eventDispatcher && class_exists(LegacyEventDispatcherProxy::class)) { + $this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher); + } else { + $this->eventDispatcher = $eventDispatcher; + } + $this->logger = new NullLogger(); } diff --git a/src/Symfony/Component/Messenger/Worker.php b/src/Symfony/Component/Messenger/Worker.php index 6205baefd4..fbd8e56f42 100644 --- a/src/Symfony/Component/Messenger/Worker.php +++ b/src/Symfony/Component/Messenger/Worker.php @@ -52,7 +52,13 @@ class Worker implements WorkerInterface $this->receivers = $receivers; $this->bus = $bus; $this->retryStrategies = $retryStrategies; - $this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher); + + if (null !== $eventDispatcher && class_exists(LegacyEventDispatcherProxy::class)) { + $this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher); + } else { + $this->eventDispatcher = $eventDispatcher; + } + $this->logger = $logger; } diff --git a/src/Symfony/Component/Security/Core/Authorization/Voter/TraceableVoter.php b/src/Symfony/Component/Security/Core/Authorization/Voter/TraceableVoter.php index e5ce1f696b..81ec62c146 100644 --- a/src/Symfony/Component/Security/Core/Authorization/Voter/TraceableVoter.php +++ b/src/Symfony/Component/Security/Core/Authorization/Voter/TraceableVoter.php @@ -31,7 +31,12 @@ class TraceableVoter implements VoterInterface public function __construct(VoterInterface $voter, EventDispatcherInterface $eventDispatcher) { $this->voter = $voter; - $this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher); + + if (class_exists(LegacyEventDispatcherProxy::class)) { + $this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher); + } else { + $this->eventDispatcher = $eventDispatcher; + } } public function vote(TokenInterface $token, $subject, array $attributes) diff --git a/src/Symfony/Component/Security/Guard/GuardAuthenticatorHandler.php b/src/Symfony/Component/Security/Guard/GuardAuthenticatorHandler.php index b39d9b2700..39a102015f 100644 --- a/src/Symfony/Component/Security/Guard/GuardAuthenticatorHandler.php +++ b/src/Symfony/Component/Security/Guard/GuardAuthenticatorHandler.php @@ -46,7 +46,13 @@ class GuardAuthenticatorHandler public function __construct(TokenStorageInterface $tokenStorage, EventDispatcherInterface $eventDispatcher = null, array $statelessProviderKeys = []) { $this->tokenStorage = $tokenStorage; - $this->dispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher); + + if (null !== $eventDispatcher && class_exists(LegacyEventDispatcherProxy::class)) { + $this->dispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher); + } else { + $this->dispatcher = $eventDispatcher; + } + $this->statelessProviderKeys = $statelessProviderKeys; } diff --git a/src/Symfony/Component/Security/Http/Firewall/AbstractAuthenticationListener.php b/src/Symfony/Component/Security/Http/Firewall/AbstractAuthenticationListener.php index 6b35899073..1929e4cfc3 100644 --- a/src/Symfony/Component/Security/Http/Firewall/AbstractAuthenticationListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/AbstractAuthenticationListener.php @@ -93,7 +93,13 @@ abstract class AbstractAuthenticationListener implements ListenerInterface 'require_previous_session' => true, ], $options); $this->logger = $logger; - $this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher); + + if (null !== $dispatcher && class_exists(LegacyEventDispatcherProxy::class)) { + $this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher); + } else { + $this->dispatcher = $dispatcher; + } + $this->httpUtils = $httpUtils; } diff --git a/src/Symfony/Component/Security/Http/Firewall/AbstractPreAuthenticatedListener.php b/src/Symfony/Component/Security/Http/Firewall/AbstractPreAuthenticatedListener.php index 500ae43e49..6a3f1377c7 100644 --- a/src/Symfony/Component/Security/Http/Firewall/AbstractPreAuthenticatedListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/AbstractPreAuthenticatedListener.php @@ -52,7 +52,12 @@ abstract class AbstractPreAuthenticatedListener implements ListenerInterface $this->authenticationManager = $authenticationManager; $this->providerKey = $providerKey; $this->logger = $logger; - $this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher); + + if (null !== $dispatcher && class_exists(LegacyEventDispatcherProxy::class)) { + $this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher); + } else { + $this->dispatcher = $dispatcher; + } } /** diff --git a/src/Symfony/Component/Security/Http/Firewall/ContextListener.php b/src/Symfony/Component/Security/Http/Firewall/ContextListener.php index 1059dd6c5d..26b6239ab3 100644 --- a/src/Symfony/Component/Security/Http/Firewall/ContextListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/ContextListener.php @@ -66,7 +66,13 @@ class ContextListener implements ListenerInterface $this->userProviders = $userProviders; $this->sessionKey = '_security_'.$contextKey; $this->logger = $logger; - $this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher); + + if (null !== $dispatcher && class_exists(LegacyEventDispatcherProxy::class)) { + $this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher); + } else { + $this->dispatcher = $dispatcher; + } + $this->trustResolver = $trustResolver ?: new AuthenticationTrustResolver(AnonymousToken::class, RememberMeToken::class); } diff --git a/src/Symfony/Component/Security/Http/Firewall/RememberMeListener.php b/src/Symfony/Component/Security/Http/Firewall/RememberMeListener.php index ebc03db862..78841ecce0 100644 --- a/src/Symfony/Component/Security/Http/Firewall/RememberMeListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/RememberMeListener.php @@ -49,7 +49,13 @@ class RememberMeListener implements ListenerInterface $this->rememberMeServices = $rememberMeServices; $this->authenticationManager = $authenticationManager; $this->logger = $logger; - $this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher); + + if (null !== $dispatcher && class_exists(LegacyEventDispatcherProxy::class)) { + $this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher); + } else { + $this->dispatcher = $dispatcher; + } + $this->catchExceptions = $catchExceptions; $this->sessionStrategy = null === $sessionStrategy ? new SessionAuthenticationStrategy(SessionAuthenticationStrategy::MIGRATE) : $sessionStrategy; } diff --git a/src/Symfony/Component/Security/Http/Firewall/SimplePreAuthenticationListener.php b/src/Symfony/Component/Security/Http/Firewall/SimplePreAuthenticationListener.php index 2c444e823b..69f773269c 100644 --- a/src/Symfony/Component/Security/Http/Firewall/SimplePreAuthenticationListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/SimplePreAuthenticationListener.php @@ -65,7 +65,13 @@ class SimplePreAuthenticationListener implements ListenerInterface $this->providerKey = $providerKey; $this->simpleAuthenticator = $simpleAuthenticator; $this->logger = $logger; - $this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher); + + if (null !== $dispatcher && class_exists(LegacyEventDispatcherProxy::class)) { + $this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher); + } else { + $this->dispatcher = $dispatcher; + } + $this->trustResolver = $trustResolver ?: new AuthenticationTrustResolver(AnonymousToken::class, RememberMeToken::class); } diff --git a/src/Symfony/Component/Security/Http/Firewall/SwitchUserListener.php b/src/Symfony/Component/Security/Http/Firewall/SwitchUserListener.php index 4b82fa1f8c..f605a279aa 100644 --- a/src/Symfony/Component/Security/Http/Firewall/SwitchUserListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/SwitchUserListener.php @@ -70,7 +70,13 @@ class SwitchUserListener implements ListenerInterface $this->usernameParameter = $usernameParameter; $this->role = $role; $this->logger = $logger; - $this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher); + + if (null !== $dispatcher && class_exists(LegacyEventDispatcherProxy::class)) { + $this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher); + } else { + $this->dispatcher = $dispatcher; + } + $this->stateless = $stateless; } diff --git a/src/Symfony/Component/Security/Http/Firewall/UsernamePasswordJsonAuthenticationListener.php b/src/Symfony/Component/Security/Http/Firewall/UsernamePasswordJsonAuthenticationListener.php index 8606899a7e..7089c89dcb 100644 --- a/src/Symfony/Component/Security/Http/Firewall/UsernamePasswordJsonAuthenticationListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/UsernamePasswordJsonAuthenticationListener.php @@ -69,7 +69,13 @@ class UsernamePasswordJsonAuthenticationListener implements ListenerInterface $this->successHandler = $successHandler; $this->failureHandler = $failureHandler; $this->logger = $logger; - $this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher); + + if (null !== $eventDispatcher && class_exists(LegacyEventDispatcherProxy::class)) { + $this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher); + } else { + $this->eventDispatcher = $eventDispatcher; + } + $this->options = array_merge(['username_path' => 'username', 'password_path' => 'password'], $options); $this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor(); } diff --git a/src/Symfony/Component/Workflow/Workflow.php b/src/Symfony/Component/Workflow/Workflow.php index 53fef69274..625086b2f1 100644 --- a/src/Symfony/Component/Workflow/Workflow.php +++ b/src/Symfony/Component/Workflow/Workflow.php @@ -43,7 +43,13 @@ class Workflow implements WorkflowInterface { $this->definition = $definition; $this->markingStore = $markingStore ?: new MultipleStateMarkingStore(); - $this->dispatcher = null !== $dispatcher ? LegacyEventDispatcherProxy::decorate($dispatcher) : null; + + if (null !== $dispatcher && class_exists(LegacyEventDispatcherProxy::class)) { + $this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher); + } else { + $this->dispatcher = $dispatcher; + } + $this->name = $name; }