Skip to content

Commit

Permalink
[5.3] CMSPlugin: Deprecate use of DispatcherAware and LanguageAware (#…
Browse files Browse the repository at this point in the history
Fedik authored Feb 28, 2025
1 parent eb65310 commit 76918b0
Showing 9 changed files with 147 additions and 18 deletions.
2 changes: 2 additions & 0 deletions libraries/src/Extension/PluginInterface.php
Original file line number Diff line number Diff line change
@@ -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
{
121 changes: 111 additions & 10 deletions libraries/src/Plugin/CMSPlugin.php
Original file line number Diff line number Diff line change
@@ -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();
}
}
6 changes: 5 additions & 1 deletion plugins/content/finder/src/Extension/Finder.php
Original file line number Diff line number Diff line change
@@ -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.
*
6 changes: 5 additions & 1 deletion plugins/editors/codemirror/src/Extension/Codemirror.php
Original file line number Diff line number Diff line change
@@ -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.
*
6 changes: 5 additions & 1 deletion plugins/editors/none/src/Extension/None.php
Original file line number Diff line number Diff line change
@@ -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.
*
5 changes: 4 additions & 1 deletion plugins/editors/tinymce/src/Extension/TinyMCE.php
Original file line number Diff line number Diff line change
@@ -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;
6 changes: 5 additions & 1 deletion plugins/system/cache/src/Extension/Cache.php
Original file line number Diff line number Diff line change
@@ -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.
*
7 changes: 5 additions & 2 deletions plugins/system/schemaorg/src/Extension/Schemaorg.php
Original file line number Diff line number Diff line change
@@ -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;

/**
6 changes: 5 additions & 1 deletion plugins/system/shortcut/src/Extension/Shortcut.php
Original file line number Diff line number Diff line change
@@ -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.
*

0 comments on commit 76918b0

Please sign in to comment.