diff --git a/libraries/src/Extension/PluginInterface.php b/libraries/src/Extension/PluginInterface.php index 55baeb78188ed..9ac414a7d869c 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 { diff --git a/libraries/src/Plugin/CMSPlugin.php b/libraries/src/Plugin/CMSPlugin.php index 8b373a758c319..8abd0c02cf9c9 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,83 @@ 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 use the language from Application, and only after the app is initialised + */ + 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 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.', + \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(); + } } diff --git a/plugins/content/finder/src/Extension/Finder.php b/plugins/content/finder/src/Extension/Finder.php index cc1f2a4746cd6..d75781ef4dcbc 100644 --- a/plugins/content/finder/src/Extension/Finder.php +++ b/plugins/content/finder/src/Extension/Finder.php @@ -14,6 +14,8 @@ use Joomla\CMS\Event\Model; use Joomla\CMS\Plugin\CMSPlugin; use Joomla\CMS\Plugin\PluginHelper; +use Joomla\Event\DispatcherAwareInterface; +use Joomla\Event\DispatcherAwareTrait; use Joomla\Event\SubscriberInterface; // phpcs:disable PSR1.Files.SideEffects @@ -25,8 +27,10 @@ * * @since 2.5 */ -final class Finder extends CMSPlugin implements SubscriberInterface +final class Finder extends CMSPlugin implements SubscriberInterface, 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 605fefb4dbb85..cb52c30f1de92 100644 --- a/plugins/editors/none/src/Extension/None.php +++ b/plugins/editors/none/src/Extension/None.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\None\Provider\EditorNoneProvider; @@ -24,8 +26,10 @@ * * @since 1.5 */ -final class None extends CMSPlugin implements SubscriberInterface +final class None extends CMSPlugin implements SubscriberInterface, DispatcherAwareInterface { + use DispatcherAwareTrait; + /** * Returns an array of events this subscriber will listen to. * diff --git a/plugins/editors/tinymce/src/Extension/TinyMCE.php b/plugins/editors/tinymce/src/Extension/TinyMCE.php index 6116faf3c00df..a6c92585b70bc 100644 --- a/plugins/editors/tinymce/src/Extension/TinyMCE.php +++ b/plugins/editors/tinymce/src/Extension/TinyMCE.php @@ -17,6 +17,8 @@ use Joomla\CMS\Session\Session; use Joomla\CMS\String\StringableInterface; 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; @@ -32,9 +34,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 1f0f936fb5806..9432c925fede7 100644 --- a/plugins/system/cache/src/Extension/Cache.php +++ b/plugins/system/cache/src/Extension/Cache.php @@ -24,6 +24,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; @@ -38,8 +40,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 19344f276958a..a3c1dc7f10f4f 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 8439405c24f24..2293a996384fa 100644 --- a/plugins/system/shortcut/src/Extension/Shortcut.php +++ b/plugins/system/shortcut/src/Extension/Shortcut.php @@ -16,6 +16,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; @@ -28,8 +30,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. *