From 12b3977605094905e13765430069ae533878126c Mon Sep 17 00:00:00 2001 From: Fedik Date: Mon, 3 Mar 2025 18:37:04 +0200 Subject: [PATCH 01/29] CMSPlugin: use Lazy Object feature --- libraries/src/Plugin/CMSPlugin.php | 6 +- libraries/src/Plugin/PluginHelper.php | 12 ++-- .../schedulerunner/services/provider.php | 29 +++++++-- .../tasknotification/services/provider.php | 33 ++++++++-- plugins/system/webauthn/services/provider.php | 64 ++++++++++++------- 5 files changed, 103 insertions(+), 41 deletions(-) diff --git a/libraries/src/Plugin/CMSPlugin.php b/libraries/src/Plugin/CMSPlugin.php index 8abd0c02cf9c9..707d210d3a99f 100644 --- a/libraries/src/Plugin/CMSPlugin.php +++ b/libraries/src/Plugin/CMSPlugin.php @@ -227,9 +227,9 @@ public function registerListeners() { // Plugins which are SubscriberInterface implementations are handled without legacy layer support if ($this instanceof SubscriberInterface) { - $this->getDispatcher()->addSubscriber($this); - - return; + // The subscriber registration handled by PluginHelper::import(). + // Return boolean instead of void, to distinguish overridden registerListeners(), need for backward compatibility. + return true; } $reflectedObject = new \ReflectionObject($this); diff --git a/libraries/src/Plugin/PluginHelper.php b/libraries/src/Plugin/PluginHelper.php index b2681071f3282..4c46006ce302c 100644 --- a/libraries/src/Plugin/PluginHelper.php +++ b/libraries/src/Plugin/PluginHelper.php @@ -13,6 +13,7 @@ use Joomla\CMS\Factory; use Joomla\Event\DispatcherAwareInterface; use Joomla\Event\DispatcherInterface; +use Joomla\Event\SubscriberInterface; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -231,15 +232,18 @@ protected static function import($plugin, $autocreate = true, ?DispatcherInterfa $plugin = Factory::getApplication()->bootPlugin($plugin->name, $plugin->type); - if ($dispatcher && $plugin instanceof DispatcherAwareInterface) { - $plugin->setDispatcher($dispatcher); - } + // @TODO: This piece of code breaks everything, and triggering Lazy Object instantiation !!! +// if ($dispatcher && $plugin instanceof DispatcherAwareInterface) { +// $plugin->setDispatcher($dispatcher); +// } if (!$autocreate) { return; } - $plugin->registerListeners(); + if ($plugin->registerListeners() && $plugin instanceof SubscriberInterface) { + $dispatcher->addSubscriber($plugin); + } } /** diff --git a/plugins/system/schedulerunner/services/provider.php b/plugins/system/schedulerunner/services/provider.php index a8ff358f768e1..bac975d3d10f6 100644 --- a/plugins/system/schedulerunner/services/provider.php +++ b/plugins/system/schedulerunner/services/provider.php @@ -33,11 +33,30 @@ public function register(Container $container): void $container->set( PluginInterface::class, function (Container $container) { - $plugin = new ScheduleRunner( - $container->get(DispatcherInterface::class), - (array) PluginHelper::getPlugin('system', 'schedulerunner') - ); - $plugin->setApplication(Factory::getApplication()); + $construct = function(?ScheduleRunner $plugin = null) use ($container) { + $eager = !$plugin; + $params = [ + $container->get(DispatcherInterface::class), + (array) PluginHelper::getPlugin('system', 'schedulerunner'), + ]; + + if ($eager) { + $plugin = new ScheduleRunner(...$params); + } else { + $plugin->__construct(...$params); + } + + $plugin->setApplication(Factory::getApplication()); + + return $eager ? $plugin : null; + }; + + if (PHP_VERSION_ID >= 80400) { + $reflector = new ReflectionClass(ScheduleRunner::class); + $plugin = $reflector->newLazyGhost($construct); + } else { + $plugin = $construct(); + } return $plugin; } diff --git a/plugins/system/tasknotification/services/provider.php b/plugins/system/tasknotification/services/provider.php index c0cfbcd564d85..9f5a6c5359c6a 100644 --- a/plugins/system/tasknotification/services/provider.php +++ b/plugins/system/tasknotification/services/provider.php @@ -35,13 +35,32 @@ public function register(Container $container): void $container->set( PluginInterface::class, function (Container $container) { - $plugin = new TaskNotification( - $container->get(DispatcherInterface::class), - (array) PluginHelper::getPlugin('system', 'tasknotification') - ); - $plugin->setApplication(Factory::getApplication()); - $plugin->setDatabase($container->get(DatabaseInterface::class)); - $plugin->setUserFactory($container->get(UserFactoryInterface::class)); + $construct = function(?TaskNotification $plugin = null) use ($container) { + $eager = !$plugin; + $params = [ + $container->get(DispatcherInterface::class), + (array) PluginHelper::getPlugin('system', 'tasknotification'), + ]; + + if ($eager) { + $plugin = new TaskNotification(...$params); + } else { + $plugin->__construct(...$params); + } + + $plugin->setApplication(Factory::getApplication()); + $plugin->setDatabase($container->get(DatabaseInterface::class)); + $plugin->setUserFactory($container->get(UserFactoryInterface::class)); + + return $eager ? $plugin : null; + }; + + if (PHP_VERSION_ID >= 80400) { + $reflector = new ReflectionClass(TaskNotification::class); + $plugin = $reflector->newLazyGhost($construct); + } else { + $plugin = $construct(); + } return $plugin; } diff --git a/plugins/system/webauthn/services/provider.php b/plugins/system/webauthn/services/provider.php index c9517c55385b2..28da1f9895cc6 100644 --- a/plugins/system/webauthn/services/provider.php +++ b/plugins/system/webauthn/services/provider.php @@ -42,33 +42,53 @@ public function register(Container $container) $container->set( PluginInterface::class, function (Container $container) { - $app = Factory::getApplication(); - $session = $container->has('session') ? $container->get('session') : $this->getSession($app); + $construct = function(?Webauthn $plugin = null) use ($container) { + $eager = !$plugin; + $app = Factory::getApplication(); + $session = $container->has('session') ? $container->get('session') : $this->getSession($app); - $db = $container->get(DatabaseInterface::class); - $credentialsRepository = $container->has(PublicKeyCredentialSourceRepository::class) - ? $container->get(PublicKeyCredentialSourceRepository::class) - : new CredentialRepository($db); + $db = $container->get(DatabaseInterface::class); + $credentialsRepository = $container->has(PublicKeyCredentialSourceRepository::class) + ? $container->get(PublicKeyCredentialSourceRepository::class) + : new CredentialRepository($db); - $metadataRepository = null; - $params = new Registry($config['params'] ?? '{}'); + $metadataRepository = null; + $params = new Registry($config['params'] ?? '{}'); - if ($params->get('attestationSupport', 0) == 1) { - $metadataRepository = $container->has(MetadataStatementRepository::class) - ? $container->get(MetadataStatementRepository::class) - : new MetadataRepository(); - } + if ($params->get('attestationSupport', 0) == 1) + { + $metadataRepository = $container->has(MetadataStatementRepository::class) + ? $container->get(MetadataStatementRepository::class) + : new MetadataRepository(); + } + + $authenticationHelper = $container->has(Authentication::class) + ? $container->get(Authentication::class) + : new Authentication($app, $session, $credentialsRepository, $metadataRepository); + + $params = [ + $container->get(DispatcherInterface::class), + (array) PluginHelper::getPlugin('system', 'webauthn'), + $authenticationHelper, + ]; - $authenticationHelper = $container->has(Authentication::class) - ? $container->get(Authentication::class) - : new Authentication($app, $session, $credentialsRepository, $metadataRepository); + if ($eager) { + $plugin = new Webauthn(...$params); + } else { + $plugin->__construct(...$params); + } - $plugin = new Webauthn( - $container->get(DispatcherInterface::class), - (array) PluginHelper::getPlugin('system', 'webauthn'), - $authenticationHelper - ); - $plugin->setApplication($app); + $plugin->setApplication($app); + + return $eager ? $plugin : null; + }; + + if (PHP_VERSION_ID >= 80400) { + $reflector = new ReflectionClass(Webauthn::class); + $plugin = $reflector->newLazyGhost($construct); + } else { + $plugin = $construct(); + } return $plugin; } From 01e632ff9aa00bba58d43534ccd54d5715acc33e Mon Sep 17 00:00:00 2001 From: Fedik Date: Mon, 3 Mar 2025 18:59:17 +0200 Subject: [PATCH 02/29] CMSPlugin: use Lazy Object feature --- libraries/src/Plugin/PluginHelper.php | 6 +++--- plugins/system/schedulerunner/services/provider.php | 2 +- plugins/system/tasknotification/services/provider.php | 2 +- plugins/system/webauthn/services/provider.php | 5 ++--- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/libraries/src/Plugin/PluginHelper.php b/libraries/src/Plugin/PluginHelper.php index 4c46006ce302c..2c2998fdce236 100644 --- a/libraries/src/Plugin/PluginHelper.php +++ b/libraries/src/Plugin/PluginHelper.php @@ -233,9 +233,9 @@ protected static function import($plugin, $autocreate = true, ?DispatcherInterfa $plugin = Factory::getApplication()->bootPlugin($plugin->name, $plugin->type); // @TODO: This piece of code breaks everything, and triggering Lazy Object instantiation !!! -// if ($dispatcher && $plugin instanceof DispatcherAwareInterface) { -// $plugin->setDispatcher($dispatcher); -// } + // if ($dispatcher && $plugin instanceof DispatcherAwareInterface) { + // $plugin->setDispatcher($dispatcher); + // } if (!$autocreate) { return; diff --git a/plugins/system/schedulerunner/services/provider.php b/plugins/system/schedulerunner/services/provider.php index bac975d3d10f6..e94cc23248ad5 100644 --- a/plugins/system/schedulerunner/services/provider.php +++ b/plugins/system/schedulerunner/services/provider.php @@ -33,7 +33,7 @@ public function register(Container $container): void $container->set( PluginInterface::class, function (Container $container) { - $construct = function(?ScheduleRunner $plugin = null) use ($container) { + $construct = function (?ScheduleRunner $plugin = null) use ($container) { $eager = !$plugin; $params = [ $container->get(DispatcherInterface::class), diff --git a/plugins/system/tasknotification/services/provider.php b/plugins/system/tasknotification/services/provider.php index 9f5a6c5359c6a..0106670821512 100644 --- a/plugins/system/tasknotification/services/provider.php +++ b/plugins/system/tasknotification/services/provider.php @@ -35,7 +35,7 @@ public function register(Container $container): void $container->set( PluginInterface::class, function (Container $container) { - $construct = function(?TaskNotification $plugin = null) use ($container) { + $construct = function (?TaskNotification $plugin = null) use ($container) { $eager = !$plugin; $params = [ $container->get(DispatcherInterface::class), diff --git a/plugins/system/webauthn/services/provider.php b/plugins/system/webauthn/services/provider.php index 28da1f9895cc6..718cdebe49faa 100644 --- a/plugins/system/webauthn/services/provider.php +++ b/plugins/system/webauthn/services/provider.php @@ -42,7 +42,7 @@ public function register(Container $container) $container->set( PluginInterface::class, function (Container $container) { - $construct = function(?Webauthn $plugin = null) use ($container) { + $construct = function (?Webauthn $plugin = null) use ($container) { $eager = !$plugin; $app = Factory::getApplication(); $session = $container->has('session') ? $container->get('session') : $this->getSession($app); @@ -55,8 +55,7 @@ function (Container $container) { $metadataRepository = null; $params = new Registry($config['params'] ?? '{}'); - if ($params->get('attestationSupport', 0) == 1) - { + if ($params->get('attestationSupport', 0) == 1) { $metadataRepository = $container->has(MetadataStatementRepository::class) ? $container->get(MetadataStatementRepository::class) : new MetadataRepository(); From a6fb246733c5cf64e08df4065eedd878632c9b7a Mon Sep 17 00:00:00 2001 From: Fedir Zinchuk Date: Mon, 3 Mar 2025 19:10:01 +0200 Subject: [PATCH 03/29] Update libraries/src/Plugin/CMSPlugin.php Co-authored-by: Brian Teeman --- libraries/src/Plugin/CMSPlugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/src/Plugin/CMSPlugin.php b/libraries/src/Plugin/CMSPlugin.php index 707d210d3a99f..5f68f417da91e 100644 --- a/libraries/src/Plugin/CMSPlugin.php +++ b/libraries/src/Plugin/CMSPlugin.php @@ -228,7 +228,7 @@ public function registerListeners() // Plugins which are SubscriberInterface implementations are handled without legacy layer support if ($this instanceof SubscriberInterface) { // The subscriber registration handled by PluginHelper::import(). - // Return boolean instead of void, to distinguish overridden registerListeners(), need for backward compatibility. + // Return boolean instead of void, to distinguish overridden registerListeners(), needed for backward compatibility. return true; } From 4142bc77b97c6527e3e0f509a448c3f3c0b7abc5 Mon Sep 17 00:00:00 2001 From: Fedik Date: Mon, 3 Mar 2025 19:13:28 +0200 Subject: [PATCH 04/29] CMSPlugin: use Lazy Object feature --- tests/Unit/Libraries/Cms/Plugin/CMSPluginTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/Unit/Libraries/Cms/Plugin/CMSPluginTest.php b/tests/Unit/Libraries/Cms/Plugin/CMSPluginTest.php index 44ad0633a1614..93d0b59aacd49 100644 --- a/tests/Unit/Libraries/Cms/Plugin/CMSPluginTest.php +++ b/tests/Unit/Libraries/Cms/Plugin/CMSPluginTest.php @@ -254,7 +254,10 @@ public function unit() { } }; - $plugin->registerListeners(); + + if ($plugin->registerListeners()) { + $dispatcher->removeSubscriber($plugin); + } $this->assertEquals([[$plugin, 'unit']], $dispatcher->getListeners('test')); } From 6546c5525345b4f96ba3950f4bc347a641c6fb9f Mon Sep 17 00:00:00 2001 From: Fedik Date: Mon, 3 Mar 2025 19:20:26 +0200 Subject: [PATCH 05/29] CMSPlugin: use Lazy Object feature --- tests/Unit/Libraries/Cms/Plugin/CMSPluginTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/Libraries/Cms/Plugin/CMSPluginTest.php b/tests/Unit/Libraries/Cms/Plugin/CMSPluginTest.php index 93d0b59aacd49..d826d2d06a67c 100644 --- a/tests/Unit/Libraries/Cms/Plugin/CMSPluginTest.php +++ b/tests/Unit/Libraries/Cms/Plugin/CMSPluginTest.php @@ -256,7 +256,7 @@ public function unit() }; if ($plugin->registerListeners()) { - $dispatcher->removeSubscriber($plugin); + $dispatcher->addSubscriber($plugin); } $this->assertEquals([[$plugin, 'unit']], $dispatcher->getListeners('test')); From 23778ea42968ab6ce5180f72cf973d3ee6dcb739 Mon Sep 17 00:00:00 2001 From: Fedik Date: Mon, 3 Mar 2025 19:39:47 +0200 Subject: [PATCH 06/29] tst --- tests/Unit/Libraries/Cms/Plugin/CMSPluginTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/Libraries/Cms/Plugin/CMSPluginTest.php b/tests/Unit/Libraries/Cms/Plugin/CMSPluginTest.php index d826d2d06a67c..9038b4f16f2e7 100644 --- a/tests/Unit/Libraries/Cms/Plugin/CMSPluginTest.php +++ b/tests/Unit/Libraries/Cms/Plugin/CMSPluginTest.php @@ -253,7 +253,7 @@ public static function getSubscribedEvents(): array public function unit() { } - }; + };1; if ($plugin->registerListeners()) { $dispatcher->addSubscriber($plugin); From c7fa33add6fb74ff16f91d6313c0f6eff4175d11 Mon Sep 17 00:00:00 2001 From: Fedik Date: Mon, 3 Mar 2025 19:39:54 +0200 Subject: [PATCH 07/29] tst --- tests/Unit/Libraries/Cms/Plugin/CMSPluginTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/Libraries/Cms/Plugin/CMSPluginTest.php b/tests/Unit/Libraries/Cms/Plugin/CMSPluginTest.php index 9038b4f16f2e7..d826d2d06a67c 100644 --- a/tests/Unit/Libraries/Cms/Plugin/CMSPluginTest.php +++ b/tests/Unit/Libraries/Cms/Plugin/CMSPluginTest.php @@ -253,7 +253,7 @@ public static function getSubscribedEvents(): array public function unit() { } - };1; + }; if ($plugin->registerListeners()) { $dispatcher->addSubscriber($plugin); From d27ee97d1405e6c12ccab2dc77696b4b7882a0fa Mon Sep 17 00:00:00 2001 From: Fedik Date: Mon, 3 Mar 2025 20:31:04 +0200 Subject: [PATCH 08/29] Use lazy proxy --- .../schedulerunner/services/provider.php | 35 ++++------ .../tasknotification/services/provider.php | 39 +++++------ plugins/system/webauthn/services/provider.php | 69 +++++++++---------- 3 files changed, 64 insertions(+), 79 deletions(-) diff --git a/plugins/system/schedulerunner/services/provider.php b/plugins/system/schedulerunner/services/provider.php index e94cc23248ad5..156ccb754096c 100644 --- a/plugins/system/schedulerunner/services/provider.php +++ b/plugins/system/schedulerunner/services/provider.php @@ -31,31 +31,26 @@ public function register(Container $container): void { $container->set( - PluginInterface::class, + ScheduleRunner::class, function (Container $container) { - $construct = function (?ScheduleRunner $plugin = null) use ($container) { - $eager = !$plugin; - $params = [ - $container->get(DispatcherInterface::class), - (array) PluginHelper::getPlugin('system', 'schedulerunner'), - ]; - - if ($eager) { - $plugin = new ScheduleRunner(...$params); - } else { - $plugin->__construct(...$params); - } - - $plugin->setApplication(Factory::getApplication()); - - return $eager ? $plugin : null; - }; + $plugin = new ScheduleRunner( + $container->get(DispatcherInterface::class), + (array) PluginHelper::getPlugin('system', 'schedulerunner') + ); + $plugin->setApplication(Factory::getApplication()); + return $plugin; + } + )->set( + PluginInterface::class, + function (Container $container) { if (PHP_VERSION_ID >= 80400) { $reflector = new ReflectionClass(ScheduleRunner::class); - $plugin = $reflector->newLazyGhost($construct); + $plugin = $reflector->newLazyProxy(function () use ($container) { + return $container->get(ScheduleRunner::class); + }); } else { - $plugin = $construct(); + $plugin = $container->get(ScheduleRunner::class); } return $plugin; diff --git a/plugins/system/tasknotification/services/provider.php b/plugins/system/tasknotification/services/provider.php index 0106670821512..36056b97d67c5 100644 --- a/plugins/system/tasknotification/services/provider.php +++ b/plugins/system/tasknotification/services/provider.php @@ -33,33 +33,28 @@ public function register(Container $container): void { $container->set( - PluginInterface::class, + TaskNotification::class, function (Container $container) { - $construct = function (?TaskNotification $plugin = null) use ($container) { - $eager = !$plugin; - $params = [ - $container->get(DispatcherInterface::class), - (array) PluginHelper::getPlugin('system', 'tasknotification'), - ]; - - if ($eager) { - $plugin = new TaskNotification(...$params); - } else { - $plugin->__construct(...$params); - } - - $plugin->setApplication(Factory::getApplication()); - $plugin->setDatabase($container->get(DatabaseInterface::class)); - $plugin->setUserFactory($container->get(UserFactoryInterface::class)); - - return $eager ? $plugin : null; - }; + $plugin = new TaskNotification( + $container->get(DispatcherInterface::class), + (array) PluginHelper::getPlugin('system', 'tasknotification') + ); + $plugin->setApplication(Factory::getApplication()); + $plugin->setDatabase($container->get(DatabaseInterface::class)); + $plugin->setUserFactory($container->get(UserFactoryInterface::class)); + return $plugin; + } + )->set( + PluginInterface::class, + function (Container $container) { if (PHP_VERSION_ID >= 80400) { $reflector = new ReflectionClass(TaskNotification::class); - $plugin = $reflector->newLazyGhost($construct); + $plugin = $reflector->newLazyProxy(function () use ($container) { + return $container->get(TaskNotification::class); + }); } else { - $plugin = $construct(); + $plugin = $container->get(TaskNotification::class); } return $plugin; diff --git a/plugins/system/webauthn/services/provider.php b/plugins/system/webauthn/services/provider.php index 718cdebe49faa..6704628385b41 100644 --- a/plugins/system/webauthn/services/provider.php +++ b/plugins/system/webauthn/services/provider.php @@ -40,53 +40,48 @@ public function register(Container $container) { $container->set( - PluginInterface::class, + Webauthn::class, function (Container $container) { - $construct = function (?Webauthn $plugin = null) use ($container) { - $eager = !$plugin; - $app = Factory::getApplication(); - $session = $container->has('session') ? $container->get('session') : $this->getSession($app); - - $db = $container->get(DatabaseInterface::class); - $credentialsRepository = $container->has(PublicKeyCredentialSourceRepository::class) - ? $container->get(PublicKeyCredentialSourceRepository::class) - : new CredentialRepository($db); - - $metadataRepository = null; - $params = new Registry($config['params'] ?? '{}'); + $app = Factory::getApplication(); + $session = $container->has('session') ? $container->get('session') : $this->getSession($app); - if ($params->get('attestationSupport', 0) == 1) { - $metadataRepository = $container->has(MetadataStatementRepository::class) - ? $container->get(MetadataStatementRepository::class) - : new MetadataRepository(); - } + $db = $container->get(DatabaseInterface::class); + $credentialsRepository = $container->has(PublicKeyCredentialSourceRepository::class) + ? $container->get(PublicKeyCredentialSourceRepository::class) + : new CredentialRepository($db); - $authenticationHelper = $container->has(Authentication::class) - ? $container->get(Authentication::class) - : new Authentication($app, $session, $credentialsRepository, $metadataRepository); + $metadataRepository = null; + $params = new Registry($config['params'] ?? '{}'); - $params = [ - $container->get(DispatcherInterface::class), - (array) PluginHelper::getPlugin('system', 'webauthn'), - $authenticationHelper, - ]; - - if ($eager) { - $plugin = new Webauthn(...$params); - } else { - $plugin->__construct(...$params); - } + if ($params->get('attestationSupport', 0) == 1) { + $metadataRepository = $container->has(MetadataStatementRepository::class) + ? $container->get(MetadataStatementRepository::class) + : new MetadataRepository(); + } - $plugin->setApplication($app); + $authenticationHelper = $container->has(Authentication::class) + ? $container->get(Authentication::class) + : new Authentication($app, $session, $credentialsRepository, $metadataRepository); - return $eager ? $plugin : null; - }; + $plugin = new Webauthn( + $container->get(DispatcherInterface::class), + (array) PluginHelper::getPlugin('system', 'webauthn'), + $authenticationHelper + ); + $plugin->setApplication($app); + return $plugin; + } + )->set( + PluginInterface::class, + function (Container $container) { if (PHP_VERSION_ID >= 80400) { $reflector = new ReflectionClass(Webauthn::class); - $plugin = $reflector->newLazyGhost($construct); + $plugin = $reflector->newLazyProxy(function () use ($container) { + return $container->get(Webauthn::class); + }); } else { - $plugin = $construct(); + $plugin = $container->get(Webauthn::class); } return $plugin; From 36fe142f5eb119aa731e9a5347ce16d7f3fbfbec Mon Sep 17 00:00:00 2001 From: Fedik Date: Sun, 9 Mar 2025 12:54:28 +0200 Subject: [PATCH 09/29] tst --- libraries/src/Plugin/CMSPlugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/src/Plugin/CMSPlugin.php b/libraries/src/Plugin/CMSPlugin.php index 2f40fb83ea087..96974d95923f2 100644 --- a/libraries/src/Plugin/CMSPlugin.php +++ b/libraries/src/Plugin/CMSPlugin.php @@ -227,7 +227,7 @@ public function registerListeners() { // Plugins which are SubscriberInterface implementations are handled without legacy layer support if ($this instanceof SubscriberInterface) { - // The subscriber registration handled by PluginHelper::import(). + // The subscriber registration handled by PluginHelper::import().1 // Return boolean instead of void, to distinguish overridden registerListeners(), needed for backward compatibility. return true; } From b76f77fa57733b857ee17b360b6b5317f05b5ba3 Mon Sep 17 00:00:00 2001 From: Fedik Date: Sun, 9 Mar 2025 12:54:33 +0200 Subject: [PATCH 10/29] tst --- libraries/src/Plugin/CMSPlugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/src/Plugin/CMSPlugin.php b/libraries/src/Plugin/CMSPlugin.php index 96974d95923f2..2f40fb83ea087 100644 --- a/libraries/src/Plugin/CMSPlugin.php +++ b/libraries/src/Plugin/CMSPlugin.php @@ -227,7 +227,7 @@ public function registerListeners() { // Plugins which are SubscriberInterface implementations are handled without legacy layer support if ($this instanceof SubscriberInterface) { - // The subscriber registration handled by PluginHelper::import().1 + // The subscriber registration handled by PluginHelper::import(). // Return boolean instead of void, to distinguish overridden registerListeners(), needed for backward compatibility. return true; } From 50a7386bd5af9569fe1365e3297b3927a0fc81fb Mon Sep 17 00:00:00 2001 From: Fedik Date: Wed, 12 Mar 2025 10:25:01 +0200 Subject: [PATCH 11/29] LazySubscriberInterface --- .../src/Event/LazySubscriberInterface.php | 28 +++++++++++++++++++ libraries/src/Plugin/CMSPlugin.php | 4 +-- libraries/src/Plugin/PluginHelper.php | 10 +++---- .../src/Extension/ScheduleRunner.php | 3 +- .../src/Extension/TaskNotification.php | 3 +- .../webauthn/src/Extension/Webauthn.php | 3 +- 6 files changed, 39 insertions(+), 12 deletions(-) create mode 100644 libraries/src/Event/LazySubscriberInterface.php diff --git a/libraries/src/Event/LazySubscriberInterface.php b/libraries/src/Event/LazySubscriberInterface.php new file mode 100644 index 0000000000000..6d467bc7761d7 --- /dev/null +++ b/libraries/src/Event/LazySubscriberInterface.php @@ -0,0 +1,28 @@ + + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace Joomla\CMS\Event; + +// phpcs:disable PSR1.Files.SideEffects +\defined('_JEXEC') or die; +// phpcs:enable PSR1.Files.SideEffects + +use Joomla\Event\SubscriberInterface; + +/** + * An interface to help transitioning to SubscriberInterface for plugins that implement Lazy Object. + * For plugins which implement this interface method registerListeners() will not be called. + * + * @TODO Remove in 8.0 + * + * @since __DEPLOY_VERSION__ + */ +interface LazySubscriberInterface extends SubscriberInterface +{ +} diff --git a/libraries/src/Plugin/CMSPlugin.php b/libraries/src/Plugin/CMSPlugin.php index 2f40fb83ea087..77699285cc858 100644 --- a/libraries/src/Plugin/CMSPlugin.php +++ b/libraries/src/Plugin/CMSPlugin.php @@ -227,9 +227,7 @@ public function registerListeners() { // Plugins which are SubscriberInterface implementations are handled without legacy layer support if ($this instanceof SubscriberInterface) { - // The subscriber registration handled by PluginHelper::import(). - // Return boolean instead of void, to distinguish overridden registerListeners(), needed for backward compatibility. - return true; + $this->getDispatcher()->addSubscriber($this); } $reflectedObject = new \ReflectionObject($this); diff --git a/libraries/src/Plugin/PluginHelper.php b/libraries/src/Plugin/PluginHelper.php index 2c2998fdce236..c79d615dd78a2 100644 --- a/libraries/src/Plugin/PluginHelper.php +++ b/libraries/src/Plugin/PluginHelper.php @@ -10,6 +10,7 @@ namespace Joomla\CMS\Plugin; use Joomla\CMS\Cache\Exception\CacheExceptionInterface; +use Joomla\CMS\Event\LazySubscriberInterface; use Joomla\CMS\Factory; use Joomla\Event\DispatcherAwareInterface; use Joomla\Event\DispatcherInterface; @@ -232,17 +233,14 @@ protected static function import($plugin, $autocreate = true, ?DispatcherInterfa $plugin = Factory::getApplication()->bootPlugin($plugin->name, $plugin->type); - // @TODO: This piece of code breaks everything, and triggering Lazy Object instantiation !!! - // if ($dispatcher && $plugin instanceof DispatcherAwareInterface) { - // $plugin->setDispatcher($dispatcher); - // } - if (!$autocreate) { return; } - if ($plugin->registerListeners() && $plugin instanceof SubscriberInterface) { + if ($plugin instanceof LazySubscriberInterface) { $dispatcher->addSubscriber($plugin); + } else { + $plugin->registerListeners(); } } diff --git a/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php b/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php index b285b7e844795..329bc66943a8d 100644 --- a/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php +++ b/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php @@ -11,6 +11,7 @@ namespace Joomla\Plugin\System\ScheduleRunner\Extension; use Joomla\CMS\Component\ComponentHelper; +use Joomla\CMS\Event\LazySubscriberInterface; use Joomla\CMS\Event\Model; use Joomla\CMS\Factory; use Joomla\CMS\Log\Log; @@ -42,7 +43,7 @@ * * @since 4.1.0 */ -final class ScheduleRunner extends CMSPlugin implements SubscriberInterface +final class ScheduleRunner extends CMSPlugin implements SubscriberInterface, LazySubscriberInterface { /** * Length of auto-generated webcron key. diff --git a/plugins/system/tasknotification/src/Extension/TaskNotification.php b/plugins/system/tasknotification/src/Extension/TaskNotification.php index 2fd2861e94549..579dfcbac7ce1 100644 --- a/plugins/system/tasknotification/src/Extension/TaskNotification.php +++ b/plugins/system/tasknotification/src/Extension/TaskNotification.php @@ -10,6 +10,7 @@ namespace Joomla\Plugin\System\TaskNotification\Extension; +use Joomla\CMS\Event\LazySubscriberInterface; use Joomla\CMS\Event\Model; use Joomla\CMS\Factory; use Joomla\CMS\Log\Log; @@ -40,7 +41,7 @@ * * @since 4.1.0 */ -final class TaskNotification extends CMSPlugin implements SubscriberInterface +final class TaskNotification extends CMSPlugin implements SubscriberInterface, LazySubscriberInterface { use DatabaseAwareTrait; use UserFactoryAwareTrait; diff --git a/plugins/system/webauthn/src/Extension/Webauthn.php b/plugins/system/webauthn/src/Extension/Webauthn.php index 4f468bdaae40d..20e08f4b09eed 100644 --- a/plugins/system/webauthn/src/Extension/Webauthn.php +++ b/plugins/system/webauthn/src/Extension/Webauthn.php @@ -11,6 +11,7 @@ namespace Joomla\Plugin\System\Webauthn\Extension; use Joomla\CMS\Event\CoreEventAware; +use Joomla\CMS\Event\LazySubscriberInterface; use Joomla\CMS\Factory; use Joomla\CMS\Log\Log; use Joomla\CMS\Plugin\CMSPlugin; @@ -42,7 +43,7 @@ * * @since 4.0.0 */ -final class Webauthn extends CMSPlugin implements SubscriberInterface +final class Webauthn extends CMSPlugin implements SubscriberInterface, LazySubscriberInterface { // Add WebAuthn buttons use AdditionalLoginButtons; From def84d051fb169648f431394dbe1e540dc2129ff Mon Sep 17 00:00:00 2001 From: Fedik Date: Wed, 12 Mar 2025 10:27:47 +0200 Subject: [PATCH 12/29] simplify --- plugins/system/schedulerunner/services/provider.php | 7 ++----- plugins/system/tasknotification/services/provider.php | 7 ++----- plugins/system/webauthn/services/provider.php | 7 ++----- 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/plugins/system/schedulerunner/services/provider.php b/plugins/system/schedulerunner/services/provider.php index 156ccb754096c..566e366a0e6fe 100644 --- a/plugins/system/schedulerunner/services/provider.php +++ b/plugins/system/schedulerunner/services/provider.php @@ -45,15 +45,12 @@ function (Container $container) { PluginInterface::class, function (Container $container) { if (PHP_VERSION_ID >= 80400) { - $reflector = new ReflectionClass(ScheduleRunner::class); - $plugin = $reflector->newLazyProxy(function () use ($container) { + return (new ReflectionClass(ScheduleRunner::class))->newLazyProxy(function () use ($container) { return $container->get(ScheduleRunner::class); }); - } else { - $plugin = $container->get(ScheduleRunner::class); } - return $plugin; + return $container->get(ScheduleRunner::class); } ); } diff --git a/plugins/system/tasknotification/services/provider.php b/plugins/system/tasknotification/services/provider.php index 36056b97d67c5..3c66e85e6d56b 100644 --- a/plugins/system/tasknotification/services/provider.php +++ b/plugins/system/tasknotification/services/provider.php @@ -49,15 +49,12 @@ function (Container $container) { PluginInterface::class, function (Container $container) { if (PHP_VERSION_ID >= 80400) { - $reflector = new ReflectionClass(TaskNotification::class); - $plugin = $reflector->newLazyProxy(function () use ($container) { + return (new ReflectionClass(TaskNotification::class))->newLazyProxy(function () use ($container) { return $container->get(TaskNotification::class); }); - } else { - $plugin = $container->get(TaskNotification::class); } - return $plugin; + return $container->get(TaskNotification::class); } ); } diff --git a/plugins/system/webauthn/services/provider.php b/plugins/system/webauthn/services/provider.php index 6704628385b41..b10a730b5ac1a 100644 --- a/plugins/system/webauthn/services/provider.php +++ b/plugins/system/webauthn/services/provider.php @@ -76,15 +76,12 @@ function (Container $container) { PluginInterface::class, function (Container $container) { if (PHP_VERSION_ID >= 80400) { - $reflector = new ReflectionClass(Webauthn::class); - $plugin = $reflector->newLazyProxy(function () use ($container) { + return (new ReflectionClass(Webauthn::class))->newLazyProxy(function () use ($container) { return $container->get(Webauthn::class); }); - } else { - $plugin = $container->get(Webauthn::class); } - return $plugin; + return $container->get(Webauthn::class); } ); } From 02486fbd6b124e87ea26d13bd903efd057b985a0 Mon Sep 17 00:00:00 2001 From: Fedik Date: Wed, 12 Mar 2025 10:28:45 +0200 Subject: [PATCH 13/29] fix --- libraries/src/Plugin/CMSPlugin.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libraries/src/Plugin/CMSPlugin.php b/libraries/src/Plugin/CMSPlugin.php index 77699285cc858..37a93a302106d 100644 --- a/libraries/src/Plugin/CMSPlugin.php +++ b/libraries/src/Plugin/CMSPlugin.php @@ -228,6 +228,8 @@ public function registerListeners() // Plugins which are SubscriberInterface implementations are handled without legacy layer support if ($this instanceof SubscriberInterface) { $this->getDispatcher()->addSubscriber($this); + + return; } $reflectedObject = new \ReflectionObject($this); From c16cc08cc2e73a41bb5452b491bd096f99b154d4 Mon Sep 17 00:00:00 2001 From: Fedik Date: Wed, 12 Mar 2025 10:29:09 +0200 Subject: [PATCH 14/29] fix --- libraries/src/Event/LazySubscriberInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/src/Event/LazySubscriberInterface.php b/libraries/src/Event/LazySubscriberInterface.php index 6d467bc7761d7..c40c93ad54c91 100644 --- a/libraries/src/Event/LazySubscriberInterface.php +++ b/libraries/src/Event/LazySubscriberInterface.php @@ -3,7 +3,7 @@ /** * Joomla! Content Management System * - * @copyright (C) 2019 Open Source Matters, Inc. + * @copyright (C) 2025 Open Source Matters, Inc. * @license GNU General Public License version 2 or later; see LICENSE.txt */ From 1ebfa852104c2524f37cc3216a6029643ccaa029 Mon Sep 17 00:00:00 2001 From: Fedik Date: Wed, 12 Mar 2025 10:32:57 +0200 Subject: [PATCH 15/29] fix --- tests/Unit/Libraries/Cms/Plugin/CMSPluginTest.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/Unit/Libraries/Cms/Plugin/CMSPluginTest.php b/tests/Unit/Libraries/Cms/Plugin/CMSPluginTest.php index d826d2d06a67c..f3b4881da2919 100644 --- a/tests/Unit/Libraries/Cms/Plugin/CMSPluginTest.php +++ b/tests/Unit/Libraries/Cms/Plugin/CMSPluginTest.php @@ -255,9 +255,7 @@ public function unit() } }; - if ($plugin->registerListeners()) { - $dispatcher->addSubscriber($plugin); - } + $dispatcher->addSubscriber($plugin); $this->assertEquals([[$plugin, 'unit']], $dispatcher->getListeners('test')); } From 56ff36f50981c53e3f3c09c881cf45f637bf14be Mon Sep 17 00:00:00 2001 From: Fedik Date: Wed, 12 Mar 2025 10:33:16 +0200 Subject: [PATCH 16/29] fix --- tests/Unit/Libraries/Cms/Plugin/CMSPluginTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Unit/Libraries/Cms/Plugin/CMSPluginTest.php b/tests/Unit/Libraries/Cms/Plugin/CMSPluginTest.php index f3b4881da2919..be764a7a0d185 100644 --- a/tests/Unit/Libraries/Cms/Plugin/CMSPluginTest.php +++ b/tests/Unit/Libraries/Cms/Plugin/CMSPluginTest.php @@ -254,7 +254,6 @@ public function unit() { } }; - $dispatcher->addSubscriber($plugin); $this->assertEquals([[$plugin, 'unit']], $dispatcher->getListeners('test')); From b1edeba4e09e9d32746f3439094c49aed281d7e3 Mon Sep 17 00:00:00 2001 From: Fedik Date: Wed, 12 Mar 2025 10:33:36 +0200 Subject: [PATCH 17/29] fix --- tests/Unit/Libraries/Cms/Plugin/CMSPluginTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/Libraries/Cms/Plugin/CMSPluginTest.php b/tests/Unit/Libraries/Cms/Plugin/CMSPluginTest.php index be764a7a0d185..44ad0633a1614 100644 --- a/tests/Unit/Libraries/Cms/Plugin/CMSPluginTest.php +++ b/tests/Unit/Libraries/Cms/Plugin/CMSPluginTest.php @@ -254,7 +254,7 @@ public function unit() { } }; - $dispatcher->addSubscriber($plugin); + $plugin->registerListeners(); $this->assertEquals([[$plugin, 'unit']], $dispatcher->getListeners('test')); } From eaad966bb31e929382c7f33f3932b53bdfabb25e Mon Sep 17 00:00:00 2001 From: Fedik Date: Wed, 12 Mar 2025 10:37:49 +0200 Subject: [PATCH 18/29] fix --- libraries/src/Plugin/PluginHelper.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/libraries/src/Plugin/PluginHelper.php b/libraries/src/Plugin/PluginHelper.php index c79d615dd78a2..a5d64d8465b67 100644 --- a/libraries/src/Plugin/PluginHelper.php +++ b/libraries/src/Plugin/PluginHelper.php @@ -12,9 +12,7 @@ use Joomla\CMS\Cache\Exception\CacheExceptionInterface; use Joomla\CMS\Event\LazySubscriberInterface; use Joomla\CMS\Factory; -use Joomla\Event\DispatcherAwareInterface; use Joomla\Event\DispatcherInterface; -use Joomla\Event\SubscriberInterface; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; From d768e430193906c82907d3f9ed99ca71f91601a2 Mon Sep 17 00:00:00 2001 From: Fedik Date: Thu, 13 Mar 2025 11:07:41 +0200 Subject: [PATCH 19/29] implement once --- plugins/system/schedulerunner/src/Extension/ScheduleRunner.php | 3 +-- .../system/tasknotification/src/Extension/TaskNotification.php | 3 +-- plugins/system/webauthn/src/Extension/Webauthn.php | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php b/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php index 329bc66943a8d..6afdcad94e7e5 100644 --- a/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php +++ b/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php @@ -25,7 +25,6 @@ use Joomla\Component\Scheduler\Administrator\Task\Task; use Joomla\Event\Event; use Joomla\Event\EventInterface; -use Joomla\Event\SubscriberInterface; use Joomla\Registry\Registry; // phpcs:disable PSR1.Files.SideEffects @@ -43,7 +42,7 @@ * * @since 4.1.0 */ -final class ScheduleRunner extends CMSPlugin implements SubscriberInterface, LazySubscriberInterface +final class ScheduleRunner extends CMSPlugin implements LazySubscriberInterface { /** * Length of auto-generated webcron key. diff --git a/plugins/system/tasknotification/src/Extension/TaskNotification.php b/plugins/system/tasknotification/src/Extension/TaskNotification.php index 579dfcbac7ce1..77c30c1594122 100644 --- a/plugins/system/tasknotification/src/Extension/TaskNotification.php +++ b/plugins/system/tasknotification/src/Extension/TaskNotification.php @@ -22,7 +22,6 @@ use Joomla\Component\Scheduler\Administrator\Task\Task; use Joomla\Database\DatabaseAwareTrait; use Joomla\Event\Event; -use Joomla\Event\SubscriberInterface; use Joomla\Filesystem\Path; use PHPMailer\PHPMailer\Exception as MailerException; @@ -41,7 +40,7 @@ * * @since 4.1.0 */ -final class TaskNotification extends CMSPlugin implements SubscriberInterface, LazySubscriberInterface +final class TaskNotification extends CMSPlugin implements LazySubscriberInterface { use DatabaseAwareTrait; use UserFactoryAwareTrait; diff --git a/plugins/system/webauthn/src/Extension/Webauthn.php b/plugins/system/webauthn/src/Extension/Webauthn.php index 20e08f4b09eed..5e47d12083742 100644 --- a/plugins/system/webauthn/src/Extension/Webauthn.php +++ b/plugins/system/webauthn/src/Extension/Webauthn.php @@ -16,7 +16,6 @@ use Joomla\CMS\Log\Log; use Joomla\CMS\Plugin\CMSPlugin; use Joomla\Event\DispatcherInterface; -use Joomla\Event\SubscriberInterface; use Joomla\Plugin\System\Webauthn\Authentication; use Joomla\Plugin\System\Webauthn\PluginTraits\AdditionalLoginButtons; use Joomla\Plugin\System\Webauthn\PluginTraits\AjaxHandler; @@ -43,7 +42,7 @@ * * @since 4.0.0 */ -final class Webauthn extends CMSPlugin implements SubscriberInterface, LazySubscriberInterface +final class Webauthn extends CMSPlugin implements LazySubscriberInterface { // Add WebAuthn buttons use AdditionalLoginButtons; From fb10ee08e5f78de0af00c430b775e5fa0ea65d43 Mon Sep 17 00:00:00 2001 From: Fedik Date: Thu, 13 Mar 2025 11:23:05 +0200 Subject: [PATCH 20/29] PluginWithSubscriberInterface --- .../PluginWithSubscriberInterface.php} | 4 ++-- libraries/src/Plugin/PluginHelper.php | 4 ++-- .../system/schedulerunner/src/Extension/ScheduleRunner.php | 4 ++-- .../tasknotification/src/Extension/TaskNotification.php | 4 ++-- plugins/system/webauthn/src/Extension/Webauthn.php | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) rename libraries/src/{Event/LazySubscriberInterface.php => Extension/PluginWithSubscriberInterface.php} (86%) diff --git a/libraries/src/Event/LazySubscriberInterface.php b/libraries/src/Extension/PluginWithSubscriberInterface.php similarity index 86% rename from libraries/src/Event/LazySubscriberInterface.php rename to libraries/src/Extension/PluginWithSubscriberInterface.php index c40c93ad54c91..fa30ee4b6d241 100644 --- a/libraries/src/Event/LazySubscriberInterface.php +++ b/libraries/src/Extension/PluginWithSubscriberInterface.php @@ -7,7 +7,7 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ -namespace Joomla\CMS\Event; +namespace Joomla\CMS\Extension; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -23,6 +23,6 @@ * * @since __DEPLOY_VERSION__ */ -interface LazySubscriberInterface extends SubscriberInterface +interface PluginWithSubscriberInterface extends SubscriberInterface { } diff --git a/libraries/src/Plugin/PluginHelper.php b/libraries/src/Plugin/PluginHelper.php index a5d64d8465b67..fef3f8085be13 100644 --- a/libraries/src/Plugin/PluginHelper.php +++ b/libraries/src/Plugin/PluginHelper.php @@ -10,7 +10,7 @@ namespace Joomla\CMS\Plugin; use Joomla\CMS\Cache\Exception\CacheExceptionInterface; -use Joomla\CMS\Event\LazySubscriberInterface; +use Joomla\CMS\Extension\PluginWithSubscriberInterface; use Joomla\CMS\Factory; use Joomla\Event\DispatcherInterface; @@ -235,7 +235,7 @@ protected static function import($plugin, $autocreate = true, ?DispatcherInterfa return; } - if ($plugin instanceof LazySubscriberInterface) { + if ($plugin instanceof PluginWithSubscriberInterface) { $dispatcher->addSubscriber($plugin); } else { $plugin->registerListeners(); diff --git a/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php b/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php index 6afdcad94e7e5..87d0f7730d235 100644 --- a/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php +++ b/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php @@ -11,8 +11,8 @@ namespace Joomla\Plugin\System\ScheduleRunner\Extension; use Joomla\CMS\Component\ComponentHelper; -use Joomla\CMS\Event\LazySubscriberInterface; use Joomla\CMS\Event\Model; +use Joomla\CMS\Extension\PluginWithSubscriberInterface; use Joomla\CMS\Factory; use Joomla\CMS\Log\Log; use Joomla\CMS\Plugin\CMSPlugin; @@ -42,7 +42,7 @@ * * @since 4.1.0 */ -final class ScheduleRunner extends CMSPlugin implements LazySubscriberInterface +final class ScheduleRunner extends CMSPlugin implements PluginWithSubscriberInterface { /** * Length of auto-generated webcron key. diff --git a/plugins/system/tasknotification/src/Extension/TaskNotification.php b/plugins/system/tasknotification/src/Extension/TaskNotification.php index 77c30c1594122..3c6b66b339c5d 100644 --- a/plugins/system/tasknotification/src/Extension/TaskNotification.php +++ b/plugins/system/tasknotification/src/Extension/TaskNotification.php @@ -10,8 +10,8 @@ namespace Joomla\Plugin\System\TaskNotification\Extension; -use Joomla\CMS\Event\LazySubscriberInterface; use Joomla\CMS\Event\Model; +use Joomla\CMS\Extension\PluginWithSubscriberInterface; use Joomla\CMS\Factory; use Joomla\CMS\Log\Log; use Joomla\CMS\Mail\MailTemplate; @@ -40,7 +40,7 @@ * * @since 4.1.0 */ -final class TaskNotification extends CMSPlugin implements LazySubscriberInterface +final class TaskNotification extends CMSPlugin implements PluginWithSubscriberInterface { use DatabaseAwareTrait; use UserFactoryAwareTrait; diff --git a/plugins/system/webauthn/src/Extension/Webauthn.php b/plugins/system/webauthn/src/Extension/Webauthn.php index 5e47d12083742..5a8fda79cf2d5 100644 --- a/plugins/system/webauthn/src/Extension/Webauthn.php +++ b/plugins/system/webauthn/src/Extension/Webauthn.php @@ -11,7 +11,7 @@ namespace Joomla\Plugin\System\Webauthn\Extension; use Joomla\CMS\Event\CoreEventAware; -use Joomla\CMS\Event\LazySubscriberInterface; +use Joomla\CMS\Extension\PluginWithSubscriberInterface; use Joomla\CMS\Factory; use Joomla\CMS\Log\Log; use Joomla\CMS\Plugin\CMSPlugin; @@ -42,7 +42,7 @@ * * @since 4.0.0 */ -final class Webauthn extends CMSPlugin implements LazySubscriberInterface +final class Webauthn extends CMSPlugin implements PluginWithSubscriberInterface { // Add WebAuthn buttons use AdditionalLoginButtons; From 8b60479798c917e7a8ea49e7a7483f769334091f Mon Sep 17 00:00:00 2001 From: Fedik Date: Thu, 13 Mar 2025 11:52:44 +0200 Subject: [PATCH 21/29] fix --- plugins/authentication/cookie/src/Extension/Cookie.php | 4 ++-- plugins/authentication/joomla/src/Extension/Joomla.php | 4 ++-- plugins/authentication/ldap/src/Extension/Ldap.php | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/authentication/cookie/src/Extension/Cookie.php b/plugins/authentication/cookie/src/Extension/Cookie.php index 7a1b157ac7654..34449cba41384 100644 --- a/plugins/authentication/cookie/src/Extension/Cookie.php +++ b/plugins/authentication/cookie/src/Extension/Cookie.php @@ -15,6 +15,7 @@ use Joomla\CMS\Event\User\AfterLoginEvent; use Joomla\CMS\Event\User\AfterLogoutEvent; use Joomla\CMS\Event\User\AuthenticationEvent; +use Joomla\CMS\Extension\PluginWithSubscriberInterface; use Joomla\CMS\Filter\InputFilter; use Joomla\CMS\Language\Text; use Joomla\CMS\Log\Log; @@ -22,7 +23,6 @@ use Joomla\CMS\User\UserFactoryAwareTrait; use Joomla\CMS\User\UserHelper; use Joomla\Database\DatabaseAwareTrait; -use Joomla\Event\SubscriberInterface; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -35,7 +35,7 @@ * @note Code based on http://jaspan.com/improved_persistent_login_cookie_best_practice * and http://fishbowl.pastiche.org/2004/01/19/persistent_login_cookie_best_practice/ */ -final class Cookie extends CMSPlugin implements SubscriberInterface +final class Cookie extends CMSPlugin implements PluginWithSubscriberInterface { use DatabaseAwareTrait; use UserFactoryAwareTrait; diff --git a/plugins/authentication/joomla/src/Extension/Joomla.php b/plugins/authentication/joomla/src/Extension/Joomla.php index 71975d2a40900..1c6a7fcf211dc 100644 --- a/plugins/authentication/joomla/src/Extension/Joomla.php +++ b/plugins/authentication/joomla/src/Extension/Joomla.php @@ -12,11 +12,11 @@ use Joomla\CMS\Authentication\Authentication; use Joomla\CMS\Event\User\AuthenticationEvent; +use Joomla\CMS\Extension\PluginWithSubscriberInterface; use Joomla\CMS\Plugin\CMSPlugin; use Joomla\CMS\User\UserFactoryAwareTrait; use Joomla\CMS\User\UserHelper; use Joomla\Database\DatabaseAwareTrait; -use Joomla\Event\SubscriberInterface; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -27,7 +27,7 @@ * * @since 1.5 */ -final class Joomla extends CMSPlugin implements SubscriberInterface +final class Joomla extends CMSPlugin implements PluginWithSubscriberInterface { use DatabaseAwareTrait; use UserFactoryAwareTrait; diff --git a/plugins/authentication/ldap/src/Extension/Ldap.php b/plugins/authentication/ldap/src/Extension/Ldap.php index 5d11a818df7a4..7db4aa8b1ace8 100644 --- a/plugins/authentication/ldap/src/Extension/Ldap.php +++ b/plugins/authentication/ldap/src/Extension/Ldap.php @@ -12,10 +12,10 @@ use Joomla\CMS\Authentication\Authentication; use Joomla\CMS\Event\User\AuthenticationEvent; +use Joomla\CMS\Extension\PluginWithSubscriberInterface; use Joomla\CMS\Log\Log; use Joomla\CMS\Plugin\CMSPlugin; use Joomla\Event\DispatcherInterface; -use Joomla\Event\SubscriberInterface; use Joomla\Plugin\Authentication\Ldap\Factory\LdapFactoryInterface; use Symfony\Component\Ldap\Entry; use Symfony\Component\Ldap\Exception\ConnectionException; @@ -31,7 +31,7 @@ * * @since 1.5 */ -final class Ldap extends CMSPlugin implements SubscriberInterface +final class Ldap extends CMSPlugin implements PluginWithSubscriberInterface { /** * The ldap factory From 3bcafcc1430bf936d052d9fc00ea95902cd96071 Mon Sep 17 00:00:00 2001 From: Fedik Date: Thu, 13 Mar 2025 11:54:53 +0200 Subject: [PATCH 22/29] fix --- libraries/src/Plugin/PluginHelper.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libraries/src/Plugin/PluginHelper.php b/libraries/src/Plugin/PluginHelper.php index fef3f8085be13..9feef695922dd 100644 --- a/libraries/src/Plugin/PluginHelper.php +++ b/libraries/src/Plugin/PluginHelper.php @@ -12,6 +12,7 @@ use Joomla\CMS\Cache\Exception\CacheExceptionInterface; use Joomla\CMS\Extension\PluginWithSubscriberInterface; use Joomla\CMS\Factory; +use Joomla\Event\DispatcherAwareInterface; use Joomla\Event\DispatcherInterface; // phpcs:disable PSR1.Files.SideEffects @@ -231,10 +232,16 @@ protected static function import($plugin, $autocreate = true, ?DispatcherInterfa $plugin = Factory::getApplication()->bootPlugin($plugin->name, $plugin->type); + // TODO: Remove in 7.0 + if ($dispatcher && $plugin instanceof DispatcherAwareInterface && !$plugin instanceof PluginWithSubscriberInterface) { + $plugin->setDispatcher($dispatcher); + } + if (!$autocreate) { return; } + // TODO: In 7.0 remove registerListeners and check only for SubscriberInterface if ($plugin instanceof PluginWithSubscriberInterface) { $dispatcher->addSubscriber($plugin); } else { From 4aa834f9b3c71d5180892f5a48d03d341a478ab0 Mon Sep 17 00:00:00 2001 From: Fedik Date: Thu, 13 Mar 2025 13:15:21 +0200 Subject: [PATCH 23/29] re arrange --- libraries/src/Plugin/PluginHelper.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/libraries/src/Plugin/PluginHelper.php b/libraries/src/Plugin/PluginHelper.php index 9feef695922dd..2b0cc26de6718 100644 --- a/libraries/src/Plugin/PluginHelper.php +++ b/libraries/src/Plugin/PluginHelper.php @@ -232,11 +232,6 @@ protected static function import($plugin, $autocreate = true, ?DispatcherInterfa $plugin = Factory::getApplication()->bootPlugin($plugin->name, $plugin->type); - // TODO: Remove in 7.0 - if ($dispatcher && $plugin instanceof DispatcherAwareInterface && !$plugin instanceof PluginWithSubscriberInterface) { - $plugin->setDispatcher($dispatcher); - } - if (!$autocreate) { return; } @@ -245,6 +240,10 @@ protected static function import($plugin, $autocreate = true, ?DispatcherInterfa if ($plugin instanceof PluginWithSubscriberInterface) { $dispatcher->addSubscriber($plugin); } else { + if ($dispatcher && $plugin instanceof DispatcherAwareInterface) { + $plugin->setDispatcher($dispatcher); + } + $plugin->registerListeners(); } } From acf47fcc4e8fb05a58f2654fa743115585a92ea0 Mon Sep 17 00:00:00 2001 From: Fedik Date: Sat, 7 Jun 2025 12:18:12 +0300 Subject: [PATCH 24/29] set Dispatcher in the plugin service provider --- plugins/content/finder/services/provider.php | 2 +- plugins/editors/codemirror/services/provider.php | 2 +- plugins/editors/none/services/provider.php | 2 +- plugins/editors/tinymce/services/provider.php | 2 +- plugins/system/cache/src/Extension/Cache.php | 4 +++- plugins/system/schemaorg/services/provider.php | 2 +- plugins/system/shortcut/services/provider.php | 2 +- 7 files changed, 9 insertions(+), 7 deletions(-) diff --git a/plugins/content/finder/services/provider.php b/plugins/content/finder/services/provider.php index 2625c3054ad40..cbe8d01ba857c 100644 --- a/plugins/content/finder/services/provider.php +++ b/plugins/content/finder/services/provider.php @@ -34,9 +34,9 @@ public function register(Container $container): void PluginInterface::class, function (Container $container) { $plugin = new Finder( - $container->get(DispatcherInterface::class), (array) PluginHelper::getPlugin('content', 'finder') ); + $plugin->setDispatcher($container->get(DispatcherInterface::class)); $plugin->setApplication(Factory::getApplication()); return $plugin; diff --git a/plugins/editors/codemirror/services/provider.php b/plugins/editors/codemirror/services/provider.php index 74ff09c3f2d16..e3d55f98bb181 100644 --- a/plugins/editors/codemirror/services/provider.php +++ b/plugins/editors/codemirror/services/provider.php @@ -34,9 +34,9 @@ public function register(Container $container) PluginInterface::class, function (Container $container) { $plugin = new Codemirror( - $container->get(DispatcherInterface::class), (array) PluginHelper::getPlugin('editors', 'codemirror') ); + $plugin->setDispatcher($container->get(DispatcherInterface::class)); $plugin->setApplication(Factory::getApplication()); return $plugin; diff --git a/plugins/editors/none/services/provider.php b/plugins/editors/none/services/provider.php index d4174182f11d3..6e5663ee93702 100644 --- a/plugins/editors/none/services/provider.php +++ b/plugins/editors/none/services/provider.php @@ -34,9 +34,9 @@ public function register(Container $container) PluginInterface::class, function (Container $container) { $plugin = new None( - $container->get(DispatcherInterface::class), (array) PluginHelper::getPlugin('editors', 'none') ); + $plugin->setDispatcher($container->get(DispatcherInterface::class)); $plugin->setApplication(Factory::getApplication()); return $plugin; diff --git a/plugins/editors/tinymce/services/provider.php b/plugins/editors/tinymce/services/provider.php index b210f970f356f..564028247624b 100644 --- a/plugins/editors/tinymce/services/provider.php +++ b/plugins/editors/tinymce/services/provider.php @@ -35,9 +35,9 @@ public function register(Container $container) PluginInterface::class, function (Container $container) { $plugin = new TinyMCE( - $container->get(DispatcherInterface::class), (array) PluginHelper::getPlugin('editors', 'tinymce') ); + $plugin->setDispatcher($container->get(DispatcherInterface::class)); $plugin->setApplication(Factory::getApplication()); $plugin->setDatabase($container->get(DatabaseInterface::class)); diff --git a/plugins/system/cache/src/Extension/Cache.php b/plugins/system/cache/src/Extension/Cache.php index 6e9d04c7e812e..ff47972fefe10 100644 --- a/plugins/system/cache/src/Extension/Cache.php +++ b/plugins/system/cache/src/Extension/Cache.php @@ -111,7 +111,9 @@ public function __construct( ?Profiler $profiler, ?SiteRouter $router ) { - parent::__construct($dispatcher, $config); + parent::__construct($config); + + $this->setDispatcher($dispatcher); $this->documentFactory = $documentFactory; $this->cacheControllerFactory = $cacheControllerFactory; diff --git a/plugins/system/schemaorg/services/provider.php b/plugins/system/schemaorg/services/provider.php index 76dc49108eb10..321f35d6133a5 100644 --- a/plugins/system/schemaorg/services/provider.php +++ b/plugins/system/schemaorg/services/provider.php @@ -36,10 +36,10 @@ public function register(Container $container) PluginInterface::class, function (Container $container) { $plugin = new Schemaorg( - $container->get(DispatcherInterface::class), (array) PluginHelper::getPlugin('system', 'schemaorg') ); + $plugin->setDispatcher($container->get(DispatcherInterface::class)); $plugin->setApplication(Factory::getApplication()); $plugin->setDatabase($container->get(DatabaseInterface::class)); $plugin->setUserFactory($container->get(UserFactoryInterface::class)); diff --git a/plugins/system/shortcut/services/provider.php b/plugins/system/shortcut/services/provider.php index d81da573e5f7c..2e8e5bc4b7307 100644 --- a/plugins/system/shortcut/services/provider.php +++ b/plugins/system/shortcut/services/provider.php @@ -34,9 +34,9 @@ public function register(Container $container) PluginInterface::class, function (Container $container) { $plugin = new Shortcut( - $container->get(DispatcherInterface::class), (array) PluginHelper::getPlugin('system', 'shortcut') ); + $plugin->setDispatcher($container->get(DispatcherInterface::class)); $plugin->setApplication(Factory::getApplication()); return $plugin; From 69742492ccede3eddcf7e75f33546476a1708e8b Mon Sep 17 00:00:00 2001 From: Fedik Date: Sat, 7 Jun 2025 12:35:20 +0300 Subject: [PATCH 25/29] use reflection --- .../PluginWithSubscriberInterface.php | 28 ------------------- libraries/src/Plugin/PluginHelper.php | 13 ++++++--- 2 files changed, 9 insertions(+), 32 deletions(-) delete mode 100644 libraries/src/Extension/PluginWithSubscriberInterface.php diff --git a/libraries/src/Extension/PluginWithSubscriberInterface.php b/libraries/src/Extension/PluginWithSubscriberInterface.php deleted file mode 100644 index fa30ee4b6d241..0000000000000 --- a/libraries/src/Extension/PluginWithSubscriberInterface.php +++ /dev/null @@ -1,28 +0,0 @@ - - * @license GNU General Public License version 2 or later; see LICENSE.txt - */ - -namespace Joomla\CMS\Extension; - -// phpcs:disable PSR1.Files.SideEffects -\defined('_JEXEC') or die; -// phpcs:enable PSR1.Files.SideEffects - -use Joomla\Event\SubscriberInterface; - -/** - * An interface to help transitioning to SubscriberInterface for plugins that implement Lazy Object. - * For plugins which implement this interface method registerListeners() will not be called. - * - * @TODO Remove in 8.0 - * - * @since __DEPLOY_VERSION__ - */ -interface PluginWithSubscriberInterface extends SubscriberInterface -{ -} diff --git a/libraries/src/Plugin/PluginHelper.php b/libraries/src/Plugin/PluginHelper.php index a97085d3e89f6..fb88db8e086be 100644 --- a/libraries/src/Plugin/PluginHelper.php +++ b/libraries/src/Plugin/PluginHelper.php @@ -10,10 +10,10 @@ namespace Joomla\CMS\Plugin; use Joomla\CMS\Cache\Exception\CacheExceptionInterface; -use Joomla\CMS\Extension\PluginWithSubscriberInterface; use Joomla\CMS\Factory; use Joomla\Event\DispatcherAwareInterface; use Joomla\Event\DispatcherInterface; +use Joomla\Event\SubscriberInterface; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -236,15 +236,20 @@ protected static function import($plugin, $autocreate = true, ?DispatcherInterfa return; } - // TODO: In 7.0 remove registerListeners and check only for SubscriberInterface - if ($plugin instanceof PluginWithSubscriberInterface) { + // Check for overridden registerListeners() + $reflection = new \ReflectionClass($plugin); + $registerOverridden = $reflection->hasMethod('registerListeners') && $reflection->getMethod('registerListeners')->class !== CMSPlugin::class; + + // @TODO: From 7.0 when registerListeners() will be removed from CMSPlugin checking for overridden registerListeners() need to be removed. + if ($plugin instanceof SubscriberInterface && !$registerOverridden) { $dispatcher->addSubscriber($plugin); } else { + // @TODO: From 7.0 when DispatcherAwareInterface will be removed from CMSPlugin this should be checked for all plugins. if ($dispatcher && $plugin instanceof DispatcherAwareInterface) { $plugin->setDispatcher($dispatcher); } - // @TODO: Starting from 7.0 it should use $dispatcher->addSubscriber($plugin); for plugins which implement SubscriberInterface. + // @TODO: From 7.0 it should use $dispatcher->addSubscriber($plugin); for plugins which implement SubscriberInterface. $plugin->registerListeners(); } } From 97c0b795a722b7dec28ebf6e3c2db694f063bf8e Mon Sep 17 00:00:00 2001 From: Fedik Date: Sat, 7 Jun 2025 12:38:23 +0300 Subject: [PATCH 26/29] fixes --- plugins/authentication/cookie/src/Extension/Cookie.php | 4 ++-- plugins/authentication/joomla/src/Extension/Joomla.php | 4 ++-- plugins/authentication/ldap/src/Extension/Ldap.php | 4 ++-- .../system/schedulerunner/src/Extension/ScheduleRunner.php | 4 ++-- .../tasknotification/src/Extension/TaskNotification.php | 4 ++-- plugins/system/webauthn/src/Extension/Webauthn.php | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/plugins/authentication/cookie/src/Extension/Cookie.php b/plugins/authentication/cookie/src/Extension/Cookie.php index 34449cba41384..7a1b157ac7654 100644 --- a/plugins/authentication/cookie/src/Extension/Cookie.php +++ b/plugins/authentication/cookie/src/Extension/Cookie.php @@ -15,7 +15,6 @@ use Joomla\CMS\Event\User\AfterLoginEvent; use Joomla\CMS\Event\User\AfterLogoutEvent; use Joomla\CMS\Event\User\AuthenticationEvent; -use Joomla\CMS\Extension\PluginWithSubscriberInterface; use Joomla\CMS\Filter\InputFilter; use Joomla\CMS\Language\Text; use Joomla\CMS\Log\Log; @@ -23,6 +22,7 @@ use Joomla\CMS\User\UserFactoryAwareTrait; use Joomla\CMS\User\UserHelper; use Joomla\Database\DatabaseAwareTrait; +use Joomla\Event\SubscriberInterface; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -35,7 +35,7 @@ * @note Code based on http://jaspan.com/improved_persistent_login_cookie_best_practice * and http://fishbowl.pastiche.org/2004/01/19/persistent_login_cookie_best_practice/ */ -final class Cookie extends CMSPlugin implements PluginWithSubscriberInterface +final class Cookie extends CMSPlugin implements SubscriberInterface { use DatabaseAwareTrait; use UserFactoryAwareTrait; diff --git a/plugins/authentication/joomla/src/Extension/Joomla.php b/plugins/authentication/joomla/src/Extension/Joomla.php index 1c6a7fcf211dc..71975d2a40900 100644 --- a/plugins/authentication/joomla/src/Extension/Joomla.php +++ b/plugins/authentication/joomla/src/Extension/Joomla.php @@ -12,11 +12,11 @@ use Joomla\CMS\Authentication\Authentication; use Joomla\CMS\Event\User\AuthenticationEvent; -use Joomla\CMS\Extension\PluginWithSubscriberInterface; use Joomla\CMS\Plugin\CMSPlugin; use Joomla\CMS\User\UserFactoryAwareTrait; use Joomla\CMS\User\UserHelper; use Joomla\Database\DatabaseAwareTrait; +use Joomla\Event\SubscriberInterface; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -27,7 +27,7 @@ * * @since 1.5 */ -final class Joomla extends CMSPlugin implements PluginWithSubscriberInterface +final class Joomla extends CMSPlugin implements SubscriberInterface { use DatabaseAwareTrait; use UserFactoryAwareTrait; diff --git a/plugins/authentication/ldap/src/Extension/Ldap.php b/plugins/authentication/ldap/src/Extension/Ldap.php index 7db4aa8b1ace8..5d11a818df7a4 100644 --- a/plugins/authentication/ldap/src/Extension/Ldap.php +++ b/plugins/authentication/ldap/src/Extension/Ldap.php @@ -12,10 +12,10 @@ use Joomla\CMS\Authentication\Authentication; use Joomla\CMS\Event\User\AuthenticationEvent; -use Joomla\CMS\Extension\PluginWithSubscriberInterface; use Joomla\CMS\Log\Log; use Joomla\CMS\Plugin\CMSPlugin; use Joomla\Event\DispatcherInterface; +use Joomla\Event\SubscriberInterface; use Joomla\Plugin\Authentication\Ldap\Factory\LdapFactoryInterface; use Symfony\Component\Ldap\Entry; use Symfony\Component\Ldap\Exception\ConnectionException; @@ -31,7 +31,7 @@ * * @since 1.5 */ -final class Ldap extends CMSPlugin implements PluginWithSubscriberInterface +final class Ldap extends CMSPlugin implements SubscriberInterface { /** * The ldap factory diff --git a/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php b/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php index 87d0f7730d235..b285b7e844795 100644 --- a/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php +++ b/plugins/system/schedulerunner/src/Extension/ScheduleRunner.php @@ -12,7 +12,6 @@ use Joomla\CMS\Component\ComponentHelper; use Joomla\CMS\Event\Model; -use Joomla\CMS\Extension\PluginWithSubscriberInterface; use Joomla\CMS\Factory; use Joomla\CMS\Log\Log; use Joomla\CMS\Plugin\CMSPlugin; @@ -25,6 +24,7 @@ use Joomla\Component\Scheduler\Administrator\Task\Task; use Joomla\Event\Event; use Joomla\Event\EventInterface; +use Joomla\Event\SubscriberInterface; use Joomla\Registry\Registry; // phpcs:disable PSR1.Files.SideEffects @@ -42,7 +42,7 @@ * * @since 4.1.0 */ -final class ScheduleRunner extends CMSPlugin implements PluginWithSubscriberInterface +final class ScheduleRunner extends CMSPlugin implements SubscriberInterface { /** * Length of auto-generated webcron key. diff --git a/plugins/system/tasknotification/src/Extension/TaskNotification.php b/plugins/system/tasknotification/src/Extension/TaskNotification.php index 3c6b66b339c5d..2fd2861e94549 100644 --- a/plugins/system/tasknotification/src/Extension/TaskNotification.php +++ b/plugins/system/tasknotification/src/Extension/TaskNotification.php @@ -11,7 +11,6 @@ namespace Joomla\Plugin\System\TaskNotification\Extension; use Joomla\CMS\Event\Model; -use Joomla\CMS\Extension\PluginWithSubscriberInterface; use Joomla\CMS\Factory; use Joomla\CMS\Log\Log; use Joomla\CMS\Mail\MailTemplate; @@ -22,6 +21,7 @@ use Joomla\Component\Scheduler\Administrator\Task\Task; use Joomla\Database\DatabaseAwareTrait; use Joomla\Event\Event; +use Joomla\Event\SubscriberInterface; use Joomla\Filesystem\Path; use PHPMailer\PHPMailer\Exception as MailerException; @@ -40,7 +40,7 @@ * * @since 4.1.0 */ -final class TaskNotification extends CMSPlugin implements PluginWithSubscriberInterface +final class TaskNotification extends CMSPlugin implements SubscriberInterface { use DatabaseAwareTrait; use UserFactoryAwareTrait; diff --git a/plugins/system/webauthn/src/Extension/Webauthn.php b/plugins/system/webauthn/src/Extension/Webauthn.php index 5a8fda79cf2d5..4f468bdaae40d 100644 --- a/plugins/system/webauthn/src/Extension/Webauthn.php +++ b/plugins/system/webauthn/src/Extension/Webauthn.php @@ -11,11 +11,11 @@ namespace Joomla\Plugin\System\Webauthn\Extension; use Joomla\CMS\Event\CoreEventAware; -use Joomla\CMS\Extension\PluginWithSubscriberInterface; use Joomla\CMS\Factory; use Joomla\CMS\Log\Log; use Joomla\CMS\Plugin\CMSPlugin; use Joomla\Event\DispatcherInterface; +use Joomla\Event\SubscriberInterface; use Joomla\Plugin\System\Webauthn\Authentication; use Joomla\Plugin\System\Webauthn\PluginTraits\AdditionalLoginButtons; use Joomla\Plugin\System\Webauthn\PluginTraits\AjaxHandler; @@ -42,7 +42,7 @@ * * @since 4.0.0 */ -final class Webauthn extends CMSPlugin implements PluginWithSubscriberInterface +final class Webauthn extends CMSPlugin implements SubscriberInterface { // Add WebAuthn buttons use AdditionalLoginButtons; From b1314d1f7d3ac2646ace28ac301968d1c6a2da2b Mon Sep 17 00:00:00 2001 From: Fedik Date: Tue, 12 Aug 2025 11:16:32 +0300 Subject: [PATCH 27/29] use di helper --- .../system/schedulerunner/services/provider.php | 17 +++-------------- .../tasknotification/services/provider.php | 17 +++-------------- plugins/system/webauthn/services/provider.php | 17 +++-------------- 3 files changed, 9 insertions(+), 42 deletions(-) diff --git a/plugins/system/schedulerunner/services/provider.php b/plugins/system/schedulerunner/services/provider.php index 566e366a0e6fe..0e6717c1e1037 100644 --- a/plugins/system/schedulerunner/services/provider.php +++ b/plugins/system/schedulerunner/services/provider.php @@ -31,8 +31,8 @@ public function register(Container $container): void { $container->set( - ScheduleRunner::class, - function (Container $container) { + PluginInterface::class, + $container->lazy(ScheduleRunner::class, function (Container $container) { $plugin = new ScheduleRunner( $container->get(DispatcherInterface::class), (array) PluginHelper::getPlugin('system', 'schedulerunner') @@ -40,18 +40,7 @@ function (Container $container) { $plugin->setApplication(Factory::getApplication()); return $plugin; - } - )->set( - PluginInterface::class, - function (Container $container) { - if (PHP_VERSION_ID >= 80400) { - return (new ReflectionClass(ScheduleRunner::class))->newLazyProxy(function () use ($container) { - return $container->get(ScheduleRunner::class); - }); - } - - return $container->get(ScheduleRunner::class); - } + }) ); } }; diff --git a/plugins/system/tasknotification/services/provider.php b/plugins/system/tasknotification/services/provider.php index 3c66e85e6d56b..566f4716a047a 100644 --- a/plugins/system/tasknotification/services/provider.php +++ b/plugins/system/tasknotification/services/provider.php @@ -33,8 +33,8 @@ public function register(Container $container): void { $container->set( - TaskNotification::class, - function (Container $container) { + PluginInterface::class, + $container->lazy(TaskNotification::class, function (Container $container) { $plugin = new TaskNotification( $container->get(DispatcherInterface::class), (array) PluginHelper::getPlugin('system', 'tasknotification') @@ -44,18 +44,7 @@ function (Container $container) { $plugin->setUserFactory($container->get(UserFactoryInterface::class)); return $plugin; - } - )->set( - PluginInterface::class, - function (Container $container) { - if (PHP_VERSION_ID >= 80400) { - return (new ReflectionClass(TaskNotification::class))->newLazyProxy(function () use ($container) { - return $container->get(TaskNotification::class); - }); - } - - return $container->get(TaskNotification::class); - } + }) ); } }; diff --git a/plugins/system/webauthn/services/provider.php b/plugins/system/webauthn/services/provider.php index b10a730b5ac1a..93620eb09da53 100644 --- a/plugins/system/webauthn/services/provider.php +++ b/plugins/system/webauthn/services/provider.php @@ -40,8 +40,8 @@ public function register(Container $container) { $container->set( - Webauthn::class, - function (Container $container) { + PluginInterface::class, + $container->lazy(Webauthn::class, function (Container $container) { $app = Factory::getApplication(); $session = $container->has('session') ? $container->get('session') : $this->getSession($app); @@ -71,18 +71,7 @@ function (Container $container) { $plugin->setApplication($app); return $plugin; - } - )->set( - PluginInterface::class, - function (Container $container) { - if (PHP_VERSION_ID >= 80400) { - return (new ReflectionClass(Webauthn::class))->newLazyProxy(function () use ($container) { - return $container->get(Webauthn::class); - }); - } - - return $container->get(Webauthn::class); - } + }) ); } From 83f961eae29a37798b5a61f65567d2e75bee8263 Mon Sep 17 00:00:00 2001 From: Fedik Date: Tue, 12 Aug 2025 11:24:18 +0300 Subject: [PATCH 28/29] phpstan --- phpstan-baseline.neon | 143 +++++++++++++++++++++--------------------- 1 file changed, 71 insertions(+), 72 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 943de366b7e39..1cb69d610b6e1 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -944,24 +944,6 @@ parameters: count: 1 path: administrator/components/com_categories/src/View/Category/HtmlView.php - - - message: ''' - #^Call to deprecated method getInstance\(\) of class Joomla\\String\\Inflector\: - 3\.0 Use static methods without a class instance instead\.$# - ''' - identifier: staticMethod.deprecated - count: 1 - path: administrator/components/com_categories/tmpl/categories/default.php - - - - message: ''' - #^Call to deprecated method toPlural\(\) of class Joomla\\String\\Inflector\: - 3\.0 Use Doctrine\\Common\\Inflector\\Inflector\:\:pluralize\(\) instead\.$# - ''' - identifier: method.deprecated - count: 1 - path: administrator/components/com_categories/tmpl/categories/default.php - - message: '#^Access to an undefined property Joomla\\Component\\Categories\\Administrator\\View\\Category\\HtmlView\:\:\$useCoreUI\.$#' identifier: property.notFound @@ -5862,24 +5844,6 @@ parameters: count: 1 path: administrator/components/com_tags/tmpl/tag/edit.php - - - message: ''' - #^Call to deprecated method getInstance\(\) of class Joomla\\String\\Inflector\: - 3\.0 Use static methods without a class instance instead\.$# - ''' - identifier: staticMethod.deprecated - count: 1 - path: administrator/components/com_tags/tmpl/tags/default.php - - - - message: ''' - #^Call to deprecated method toPlural\(\) of class Joomla\\String\\Inflector\: - 3\.0 Use Doctrine\\Common\\Inflector\\Inflector\:\:pluralize\(\) instead\.$# - ''' - identifier: method.deprecated - count: 1 - path: administrator/components/com_tags/tmpl/tags/default.php - - message: ''' #^Call to deprecated method getError\(\) of class Joomla\\CMS\\MVC\\Model\\BaseModel\: @@ -7069,12 +7033,6 @@ parameters: count: 1 path: administrator/components/com_users/tmpl/user/edit_groups.php - - - message: '#^Call to method pluralize\(\) of deprecated class Doctrine\\Common\\Inflector\\Inflector\.$#' - identifier: staticMethod.deprecatedClass - count: 1 - path: administrator/components/com_workflow/src/Controller/DisplayController.php - - message: ''' #^Call to deprecated method getError\(\) of class Joomla\\CMS\\MVC\\Model\\BaseModel\: @@ -13524,24 +13482,7 @@ parameters: Catch thrown Exceptions instead of getError$# ''' identifier: method.deprecated - count: 6 - path: libraries/src/MVC/Controller/ApiController.php - - - - message: ''' - #^Call to deprecated method getErrors\(\) of class Joomla\\CMS\\MVC\\Model\\BaseModel\: - 3\.1\.4 will be removed in 7\.0 - Will be removed without replacement - Catch thrown Exceptions instead of getErrors$# - ''' - identifier: method.deprecated - count: 1 - path: libraries/src/MVC/Controller/ApiController.php - - - - message: '#^Call to method singularize\(\) of deprecated class Doctrine\\Common\\Inflector\\Inflector\.$#' - identifier: staticMethod.deprecatedClass - count: 4 + count: 2 path: libraries/src/MVC/Controller/ApiController.php - @@ -15407,6 +15348,16 @@ parameters: count: 2 path: plugins/content/confirmconsent/src/Field/ConsentBoxField.php + - + message: ''' + #^Call to deprecated method setDispatcher\(\) of class Joomla\\Plugin\\Content\\Finder\\Extension\\Finder\: + 5\.2 will be removed in 7\.0 + Plugin should implement DispatcherAwareInterface on its own, when it is needed\.$# + ''' + identifier: method.deprecated + count: 1 + path: plugins/content/finder/services/provider.php + - message: ''' #^Call to deprecated method getDispatcher\(\) of class Joomla\\Plugin\\Content\\Finder\\Extension\\Finder\: @@ -15509,6 +15460,16 @@ parameters: count: 2 path: plugins/editors/codemirror/layouts/editors/codemirror/codemirror.php + - + message: ''' + #^Call to deprecated method setDispatcher\(\) of class Joomla\\Plugin\\Editors\\CodeMirror\\Extension\\Codemirror\: + 5\.2 will be removed in 7\.0 + Plugin should implement DispatcherAwareInterface on its own, when it is needed\.$# + ''' + identifier: method.deprecated + count: 1 + path: plugins/editors/codemirror/services/provider.php + - message: ''' #^Call to deprecated method getDispatcher\(\) of class Joomla\\Plugin\\Editors\\CodeMirror\\Extension\\Codemirror\: @@ -15519,6 +15480,16 @@ parameters: count: 1 path: plugins/editors/codemirror/src/Extension/Codemirror.php + - + message: ''' + #^Call to deprecated method setDispatcher\(\) of class Joomla\\Plugin\\Editors\\None\\Extension\\None\: + 5\.2 will be removed in 7\.0 + Plugin should implement DispatcherAwareInterface on its own, when it is needed\.$# + ''' + identifier: method.deprecated + count: 1 + path: plugins/editors/none/services/provider.php + - message: ''' #^Call to deprecated method getDispatcher\(\) of class Joomla\\Plugin\\Editors\\None\\Extension\\None\: @@ -15529,6 +15500,16 @@ parameters: count: 1 path: plugins/editors/none/src/Extension/None.php + - + message: ''' + #^Call to deprecated method setDispatcher\(\) of class Joomla\\Plugin\\Editors\\TinyMCE\\Extension\\TinyMCE\: + 5\.2 will be removed in 7\.0 + Plugin should implement DispatcherAwareInterface on its own, when it is needed\.$# + ''' + identifier: method.deprecated + count: 1 + path: plugins/editors/tinymce/services/provider.php + - message: ''' #^Call to deprecated method getDispatcher\(\) of class Joomla\\Plugin\\Editors\\TinyMCE\\Extension\\TinyMCE\: @@ -15723,6 +15704,16 @@ parameters: count: 4 path: plugins/system/cache/src/Extension/Cache.php + - + message: ''' + #^Call to deprecated method setDispatcher\(\) of class Joomla\\Plugin\\System\\Cache\\Extension\\Cache\: + 5\.2 will be removed in 7\.0 + Plugin should implement DispatcherAwareInterface on its own, when it is needed\.$# + ''' + identifier: method.deprecated + count: 1 + path: plugins/system/cache/src/Extension/Cache.php + - message: ''' #^Call to deprecated method getLanguage\(\) of class Joomla\\CMS\\Factory\: @@ -15816,6 +15807,16 @@ parameters: count: 1 path: plugins/system/languagefilter/src/Extension/LanguageFilter.php + - + message: ''' + #^Call to deprecated method setDispatcher\(\) of class Joomla\\Plugin\\System\\Schemaorg\\Extension\\Schemaorg\: + 5\.2 will be removed in 7\.0 + Plugin should implement DispatcherAwareInterface on its own, when it is needed\.$# + ''' + identifier: method.deprecated + count: 1 + path: plugins/system/schemaorg/services/provider.php + - message: ''' #^Call to deprecated method getDispatcher\(\) of class Joomla\\Plugin\\System\\Schemaorg\\Extension\\Schemaorg\: @@ -15826,6 +15827,16 @@ parameters: count: 4 path: plugins/system/schemaorg/src/Extension/Schemaorg.php + - + message: ''' + #^Call to deprecated method setDispatcher\(\) of class Joomla\\Plugin\\System\\Shortcut\\Extension\\Shortcut\: + 5\.2 will be removed in 7\.0 + Plugin should implement DispatcherAwareInterface on its own, when it is needed\.$# + ''' + identifier: method.deprecated + count: 1 + path: plugins/system/shortcut/services/provider.php + - message: ''' #^Call to deprecated method getDispatcher\(\) of class Joomla\\Plugin\\System\\Shortcut\\Extension\\Shortcut\: @@ -16011,12 +16022,6 @@ parameters: count: 2 path: plugins/workflow/featuring/src/Extension/Featuring.php - - - message: '#^Call to method singularize\(\) of deprecated class Doctrine\\Common\\Inflector\\Inflector\.$#' - identifier: staticMethod.deprecatedClass - count: 1 - path: plugins/workflow/featuring/src/Extension/Featuring.php - - message: '#^Access to an undefined property Joomla\\Plugin\\Workflow\\Notification\\Extension\\Notification\:\:\$app\.$#' identifier: property.notFound @@ -16028,9 +16033,3 @@ parameters: identifier: property.notFound count: 2 path: plugins/workflow/publishing/src/Extension/Publishing.php - - - - message: '#^Call to method singularize\(\) of deprecated class Doctrine\\Common\\Inflector\\Inflector\.$#' - identifier: staticMethod.deprecatedClass - count: 1 - path: plugins/workflow/publishing/src/Extension/Publishing.php From d7f1a3175c766910716a15e70815896ee9e5253c Mon Sep 17 00:00:00 2001 From: Fedik Date: Thu, 28 Aug 2025 09:58:03 +0300 Subject: [PATCH 29/29] typo --- plugins/system/schemaorg/services/provider.php | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/system/schemaorg/services/provider.php b/plugins/system/schemaorg/services/provider.php index 321f35d6133a5..06ce84cdbbd66 100644 --- a/plugins/system/schemaorg/services/provider.php +++ b/plugins/system/schemaorg/services/provider.php @@ -38,7 +38,6 @@ function (Container $container) { $plugin = new Schemaorg( (array) PluginHelper::getPlugin('system', 'schemaorg') ); - $plugin->setDispatcher($container->get(DispatcherInterface::class)); $plugin->setApplication(Factory::getApplication()); $plugin->setDatabase($container->get(DatabaseInterface::class));