From ba9a00900247953e983a34674b8ce264f6ec9e76 Mon Sep 17 00:00:00 2001 From: Fedik Date: Mon, 6 May 2024 13:55:02 +0300 Subject: [PATCH 1/5] CMSPlugin: Deprecate use of DispatcherAware and LanguageAware --- libraries/src/Extension/PluginInterface.php | 6 + libraries/src/Plugin/CMSPlugin.php | 122 ++++++++++++++++++-- 2 files changed, 118 insertions(+), 10 deletions(-) diff --git a/libraries/src/Extension/PluginInterface.php b/libraries/src/Extension/PluginInterface.php index 55baeb78188ed..fd6952febca0f 100644 --- a/libraries/src/Extension/PluginInterface.php +++ b/libraries/src/Extension/PluginInterface.php @@ -19,6 +19,8 @@ * Access to plugin specific services. * * @since 4.0.0 + * + * @TODO Starting from 7.0 the class will no longer extend DispatcherAwareInterface */ interface PluginInterface extends DispatcherAwareInterface { @@ -28,6 +30,10 @@ interface PluginInterface extends DispatcherAwareInterface * @return void * * @since 4.0.0 + * + * @deprecated 5.2 will be removed in 7.0 + * Plugin should implement SubscriberInterface. + * These plugins will be added to dispatcher in PluginHelper::import(). */ public function registerListeners(); } diff --git a/libraries/src/Plugin/CMSPlugin.php b/libraries/src/Plugin/CMSPlugin.php index 0666323886331..c988676f3dcc8 100644 --- a/libraries/src/Plugin/CMSPlugin.php +++ b/libraries/src/Plugin/CMSPlugin.php @@ -14,6 +14,7 @@ use Joomla\CMS\Event\Result\ResultAwareInterface; use Joomla\CMS\Extension\PluginInterface; use Joomla\CMS\Factory; +use Joomla\CMS\Language\Language; use Joomla\CMS\Language\LanguageAwareInterface; use Joomla\CMS\Language\LanguageAwareTrait; use Joomla\Event\AbstractEvent; @@ -32,11 +33,19 @@ * Plugin Class * * @since 1.5 + * + * @TODO Starting from 7.0 the class will no longer implement DispatcherAwareInterface and LanguageAwareInterface */ abstract class CMSPlugin implements DispatcherAwareInterface, PluginInterface, LanguageAwareInterface { - use DispatcherAwareTrait; - use LanguageAwareTrait; + use DispatcherAwareTrait { + setDispatcher as traitSetDispatcher; + getDispatcher as traitGetDispatcher; + } + use LanguageAwareTrait { + setLanguage as traitSetLanguage; + getLanguage as traitGetLanguage; + } /** * A Registry object holding the parameters for the plugin @@ -101,15 +110,31 @@ abstract class CMSPlugin implements DispatcherAwareInterface, PluginInterface, L /** * Constructor * - * @param DispatcherInterface $dispatcher The event dispatcher - * @param array $config An optional associative array of configuration settings. - * Recognized key values include 'name', 'group', 'params', 'language' - * (this list is not meant to be comprehensive). + * @param array $config An optional associative array of configuration settings. + * Recognized key values include 'name', 'group', 'params', 'language' + * (this list is not meant to be comprehensive). * * @since 1.5 */ - public function __construct(DispatcherInterface $dispatcher, array $config = []) + public function __construct($config = []) { + if ($config instanceof DispatcherInterface) { + @trigger_error( + sprintf( + 'Passing an instance of %1$s to %2$s() will not be supported in 7.0. ' + . 'Starting from 7.0 CMSPlugin class will no longer implement DispatcherAwareInterface.', + DispatcherInterface::class, + __METHOD__ + ), + \E_USER_DEPRECATED + ); + + // Set the dispatcher we are to register our listeners with + $this->setDispatcher($config); + + $config = \func_num_args() > 1 ? func_get_arg(1) : []; + } + // Get the parameters. if (isset($config['params'])) { if ($config['params'] instanceof Registry) { @@ -153,9 +178,6 @@ public function __construct(DispatcherInterface $dispatcher, array $config = []) $this->db = Factory::getDbo(); } } - - // Set the dispatcher we are to register our listeners with - $this->setDispatcher($dispatcher); } /** @@ -390,4 +412,84 @@ public function setApplication(CMSApplicationInterface $application): void $this->setLanguage($application->getLanguage()); } } + + /** + * Set the language to use. + * + * @param Language $language The language to use + * + * @return void + * + * @since __DEPLOY_VERSION__ + * + * @deprecated 5.2 will be removed in 7.0 + * Plugin should implement LanguageAwareInterface on its own, when it is needed. + */ + public function setLanguage(Language $language): void + { + $this->traitSetLanguage($language); + } + + /** + * Get the Language. + * + * @return Language + * + * @throws \UnexpectedValueException May be thrown if the language has not been set. + * + * @since __DEPLOY_VERSION__ + * + * @deprecated 5.2 will be removed in 7.0 + * Plugin should implement LanguageAwareInterface on its own, when it is needed. + */ + protected function getLanguage(): Language + { + @trigger_error( + __CLASS__ . ': Use of LanguageAwareInterface over CMSPlugin will be removed in 7.0.' + . ' Plugin should implement LanguageAwareInterface on its own, when it is needed.', + \E_USER_DEPRECATED + ); + + return $this->traitGetLanguage(); + } + + /** + * Set the dispatcher to use. + * + * @param DispatcherInterface $dispatcher The dispatcher to use. + * + * @return $this + * + * @since __DEPLOY_VERSION__ + * + * @deprecated 5.2 will be removed in 7.0 + * Plugin should implement DispatcherAwareInterface on its own, when it is needed. + */ + public function setDispatcher(DispatcherInterface $dispatcher) + { + @trigger_error( + __CLASS__ . ': Use of DispatcherAwareInterface over CMSPlugin will be removed in 7.0.' + . ' Plugin should implement DispatcherAwareInterface on its own, when it is needed.', + \E_USER_DEPRECATED + ); + + return $this->traitSetDispatcher($dispatcher); + } + + /** + * Get the event dispatcher. + * + * @return DispatcherInterface + * + * @throws \UnexpectedValueException May be thrown if the dispatcher has not been set. + * + * @since __DEPLOY_VERSION__ + * + * @deprecated 5.2 will be removed in 7.0 + * Plugin should implement DispatcherAwareInterface on its own, when it is needed. + */ + public function getDispatcher() + { + return $this->traitGetDispatcher(); + } } From 6fb06b85111cece073c1efed3287435db128d53a Mon Sep 17 00:00:00 2001 From: Fedik Date: Mon, 6 May 2024 14:04:16 +0300 Subject: [PATCH 2/5] CMSPlugin: Deprecate use of DispatcherAware and LanguageAware --- plugins/content/finder/src/Extension/Finder.php | 6 +++++- plugins/editors/codemirror/src/Extension/Codemirror.php | 6 +++++- plugins/editors/none/src/Extension/None.php | 6 +++++- plugins/editors/tinymce/src/Extension/TinyMCE.php | 5 ++++- plugins/system/cache/src/Extension/Cache.php | 6 +++++- plugins/system/schemaorg/src/Extension/Schemaorg.php | 7 +++++-- plugins/system/shortcut/src/Extension/Shortcut.php | 6 +++++- 7 files changed, 34 insertions(+), 8 deletions(-) diff --git a/plugins/content/finder/src/Extension/Finder.php b/plugins/content/finder/src/Extension/Finder.php index 83f44d9dbe2b3..6e88a03d36edf 100644 --- a/plugins/content/finder/src/Extension/Finder.php +++ b/plugins/content/finder/src/Extension/Finder.php @@ -13,6 +13,8 @@ use Joomla\CMS\Event\Finder as FinderEvent; use Joomla\CMS\Plugin\CMSPlugin; use Joomla\CMS\Plugin\PluginHelper; +use Joomla\Event\DispatcherAwareInterface; +use Joomla\Event\DispatcherAwareTrait; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -23,8 +25,10 @@ * * @since 2.5 */ -final class Finder extends CMSPlugin +final class Finder extends CMSPlugin implements DispatcherAwareInterface { + use DispatcherAwareTrait; + /** * Flag to check whether finder plugins already imported. * diff --git a/plugins/editors/codemirror/src/Extension/Codemirror.php b/plugins/editors/codemirror/src/Extension/Codemirror.php index 16d68593d5e7f..51e90b70b2027 100644 --- a/plugins/editors/codemirror/src/Extension/Codemirror.php +++ b/plugins/editors/codemirror/src/Extension/Codemirror.php @@ -12,6 +12,8 @@ use Joomla\CMS\Event\Editor\EditorSetupEvent; use Joomla\CMS\Plugin\CMSPlugin; +use Joomla\Event\DispatcherAwareInterface; +use Joomla\Event\DispatcherAwareTrait; use Joomla\Event\SubscriberInterface; use Joomla\Plugin\Editors\CodeMirror\Provider\CodeMirrorProvider; @@ -24,8 +26,10 @@ * * @since 1.6 */ -final class Codemirror extends CMSPlugin implements SubscriberInterface +final class Codemirror extends CMSPlugin implements SubscriberInterface, DispatcherAwareInterface { + use DispatcherAwareTrait; + /** * Returns an array of events this subscriber will listen to. * diff --git a/plugins/editors/none/src/Extension/None.php b/plugins/editors/none/src/Extension/None.php index 9c5f3afa263bc..eca1816f52c7e 100644 --- a/plugins/editors/none/src/Extension/None.php +++ b/plugins/editors/none/src/Extension/None.php @@ -12,6 +12,8 @@ use Joomla\CMS\Layout\LayoutHelper; use Joomla\CMS\Plugin\CMSPlugin; +use Joomla\Event\DispatcherAwareInterface; +use Joomla\Event\DispatcherAwareTrait; use Joomla\Event\Event; // phpcs:disable PSR1.Files.SideEffects @@ -23,8 +25,10 @@ * * @since 1.5 */ -final class None extends CMSPlugin +final class None extends CMSPlugin implements DispatcherAwareInterface { + use DispatcherAwareTrait; + /** * Display the editor area. * diff --git a/plugins/editors/tinymce/src/Extension/TinyMCE.php b/plugins/editors/tinymce/src/Extension/TinyMCE.php index 0dc33731ad865..05061ff4b0e46 100644 --- a/plugins/editors/tinymce/src/Extension/TinyMCE.php +++ b/plugins/editors/tinymce/src/Extension/TinyMCE.php @@ -15,6 +15,8 @@ use Joomla\CMS\Plugin\CMSPlugin; use Joomla\CMS\Session\Session; use Joomla\Database\DatabaseAwareTrait; +use Joomla\Event\DispatcherAwareInterface; +use Joomla\Event\DispatcherAwareTrait; use Joomla\Event\SubscriberInterface; use Joomla\Filesystem\Folder; use Joomla\Plugin\Editors\TinyMCE\PluginTraits\KnownButtons; @@ -30,9 +32,10 @@ * * @since 1.5 */ -final class TinyMCE extends CMSPlugin implements SubscriberInterface +final class TinyMCE extends CMSPlugin implements SubscriberInterface, DispatcherAwareInterface { use DatabaseAwareTrait; + use DispatcherAwareTrait; // @todo: KnownButtons, ToolbarPresets for backward compatibility. Remove in Joomla 6 use KnownButtons; diff --git a/plugins/system/cache/src/Extension/Cache.php b/plugins/system/cache/src/Extension/Cache.php index f94a0cb49dc4b..d1c5b61f64757 100644 --- a/plugins/system/cache/src/Extension/Cache.php +++ b/plugins/system/cache/src/Extension/Cache.php @@ -22,6 +22,8 @@ use Joomla\CMS\Profiler\Profiler; use Joomla\CMS\Router\SiteRouter; use Joomla\CMS\Uri\Uri; +use Joomla\Event\DispatcherAwareInterface; +use Joomla\Event\DispatcherAwareTrait; use Joomla\Event\DispatcherInterface; use Joomla\Event\Event; use Joomla\Event\Priority; @@ -36,8 +38,10 @@ * * @since 1.5 */ -final class Cache extends CMSPlugin implements SubscriberInterface +final class Cache extends CMSPlugin implements SubscriberInterface, DispatcherAwareInterface { + use DispatcherAwareTrait; + /** * Cache instance. * diff --git a/plugins/system/schemaorg/src/Extension/Schemaorg.php b/plugins/system/schemaorg/src/Extension/Schemaorg.php index c76b395afab8b..c284195db3052 100644 --- a/plugins/system/schemaorg/src/Extension/Schemaorg.php +++ b/plugins/system/schemaorg/src/Extension/Schemaorg.php @@ -28,6 +28,8 @@ use Joomla\CMS\User\UserFactoryAwareTrait; use Joomla\Database\DatabaseAwareTrait; use Joomla\Database\ParameterType; +use Joomla\Event\DispatcherAwareInterface; +use Joomla\Event\DispatcherAwareTrait; use Joomla\Event\SubscriberInterface; use Joomla\Registry\Registry; @@ -40,11 +42,12 @@ * * @since 5.0.0 */ -final class Schemaorg extends CMSPlugin implements SubscriberInterface +final class Schemaorg extends CMSPlugin implements SubscriberInterface, DispatcherAwareInterface { use DatabaseAwareTrait; - use SchemaorgPrepareImageTrait; + use DispatcherAwareTrait; use SchemaorgPrepareDateTrait; + use SchemaorgPrepareImageTrait; use UserFactoryAwareTrait; /** diff --git a/plugins/system/shortcut/src/Extension/Shortcut.php b/plugins/system/shortcut/src/Extension/Shortcut.php index d1cbcc80eade1..43085786ed99a 100644 --- a/plugins/system/shortcut/src/Extension/Shortcut.php +++ b/plugins/system/shortcut/src/Extension/Shortcut.php @@ -15,6 +15,8 @@ use Joomla\CMS\Plugin\CMSPlugin; use Joomla\CMS\Router\Route; use Joomla\CMS\Uri\Uri; +use Joomla\Event\DispatcherAwareInterface; +use Joomla\Event\DispatcherAwareTrait; use Joomla\Event\Event; use Joomla\Event\SubscriberInterface; @@ -27,8 +29,10 @@ * * @since 4.2.0 */ -final class Shortcut extends CMSPlugin implements SubscriberInterface +final class Shortcut extends CMSPlugin implements SubscriberInterface, DispatcherAwareInterface { + use DispatcherAwareTrait; + /** * Returns an array of events this subscriber will listen to. * From 380480da1c20feb59505186d894cda6817604708 Mon Sep 17 00:00:00 2001 From: Fedik Date: Mon, 6 May 2024 14:11:12 +0300 Subject: [PATCH 3/5] CMSPlugin: Deprecate use of DispatcherAware and LanguageAware --- libraries/src/Extension/PluginInterface.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/libraries/src/Extension/PluginInterface.php b/libraries/src/Extension/PluginInterface.php index fd6952febca0f..9ac414a7d869c 100644 --- a/libraries/src/Extension/PluginInterface.php +++ b/libraries/src/Extension/PluginInterface.php @@ -30,10 +30,6 @@ interface PluginInterface extends DispatcherAwareInterface * @return void * * @since 4.0.0 - * - * @deprecated 5.2 will be removed in 7.0 - * Plugin should implement SubscriberInterface. - * These plugins will be added to dispatcher in PluginHelper::import(). */ public function registerListeners(); } From 708a89147167e10f6a5b96fa80f8e49bc8ed9f68 Mon Sep 17 00:00:00 2001 From: Fedik Date: Tue, 7 May 2024 13:52:55 +0300 Subject: [PATCH 4/5] Message about deprecation --- libraries/src/Plugin/CMSPlugin.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/libraries/src/Plugin/CMSPlugin.php b/libraries/src/Plugin/CMSPlugin.php index c988676f3dcc8..45a592d4f2c34 100644 --- a/libraries/src/Plugin/CMSPlugin.php +++ b/libraries/src/Plugin/CMSPlugin.php @@ -423,7 +423,7 @@ public function setApplication(CMSApplicationInterface $application): void * @since __DEPLOY_VERSION__ * * @deprecated 5.2 will be removed in 7.0 - * Plugin should implement LanguageAwareInterface on its own, when it is needed. + * Plugin should use the language from Application, and only after the app is initialised */ public function setLanguage(Language $language): void { @@ -440,13 +440,12 @@ public function setLanguage(Language $language): void * @since __DEPLOY_VERSION__ * * @deprecated 5.2 will be removed in 7.0 - * Plugin should implement LanguageAwareInterface on its own, when it is needed. + * Plugin should use the language from Application, and only after the app is initialised. */ protected function getLanguage(): Language { @trigger_error( - __CLASS__ . ': Use of LanguageAwareInterface over CMSPlugin will be removed in 7.0.' - . ' Plugin should implement LanguageAwareInterface on its own, when it is needed.', + __CLASS__ . ': Use of LanguageAwareInterface over CMSPlugin will be removed in 7.0.', \E_USER_DEPRECATED ); From f38e2e8b166c581846a4122466538634aeeb7000 Mon Sep 17 00:00:00 2001 From: Fedik Date: Fri, 28 Feb 2025 16:39:40 +0200 Subject: [PATCH 5/5] cs --- 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 372057c522403..8abd0c02cf9c9 100644 --- a/libraries/src/Plugin/CMSPlugin.php +++ b/libraries/src/Plugin/CMSPlugin.php @@ -120,7 +120,7 @@ public function __construct($config = []) { if ($config instanceof DispatcherInterface) { @trigger_error( - sprintf( + \sprintf( 'Passing an instance of %1$s to %2$s() will not be supported in 7.0. ' . 'Starting from 7.0 CMSPlugin class will no longer implement DispatcherAwareInterface.', DispatcherInterface::class,