Skip to content

Commit 76918b0

Browse files
authored
[5.3] CMSPlugin: Deprecate use of DispatcherAware and LanguageAware (#43430)
1 parent eb65310 commit 76918b0

File tree

9 files changed

+147
-18
lines changed

9 files changed

+147
-18
lines changed

libraries/src/Extension/PluginInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
* Access to plugin specific services.
2020
*
2121
* @since 4.0.0
22+
*
23+
* @TODO Starting from 7.0 the class will no longer extend DispatcherAwareInterface
2224
*/
2325
interface PluginInterface extends DispatcherAwareInterface
2426
{

libraries/src/Plugin/CMSPlugin.php

Lines changed: 111 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Joomla\CMS\Event\Result\ResultAwareInterface;
1515
use Joomla\CMS\Extension\PluginInterface;
1616
use Joomla\CMS\Factory;
17+
use Joomla\CMS\Language\Language;
1718
use Joomla\CMS\Language\LanguageAwareInterface;
1819
use Joomla\CMS\Language\LanguageAwareTrait;
1920
use Joomla\Event\AbstractEvent;
@@ -32,11 +33,19 @@
3233
* Plugin Class
3334
*
3435
* @since 1.5
36+
*
37+
* @TODO Starting from 7.0 the class will no longer implement DispatcherAwareInterface and LanguageAwareInterface
3538
*/
3639
abstract class CMSPlugin implements DispatcherAwareInterface, PluginInterface, LanguageAwareInterface
3740
{
38-
use DispatcherAwareTrait;
39-
use LanguageAwareTrait;
41+
use DispatcherAwareTrait {
42+
setDispatcher as traitSetDispatcher;
43+
getDispatcher as traitGetDispatcher;
44+
}
45+
use LanguageAwareTrait {
46+
setLanguage as traitSetLanguage;
47+
getLanguage as traitGetLanguage;
48+
}
4049

4150
/**
4251
* A Registry object holding the parameters for the plugin
@@ -101,15 +110,31 @@ abstract class CMSPlugin implements DispatcherAwareInterface, PluginInterface, L
101110
/**
102111
* Constructor
103112
*
104-
* @param DispatcherInterface $dispatcher The event dispatcher
105-
* @param array $config An optional associative array of configuration settings.
106-
* Recognized key values include 'name', 'group', 'params', 'language'
107-
* (this list is not meant to be comprehensive).
113+
* @param array $config An optional associative array of configuration settings.
114+
* Recognized key values include 'name', 'group', 'params', 'language'
115+
* (this list is not meant to be comprehensive).
108116
*
109117
* @since 1.5
110118
*/
111-
public function __construct(DispatcherInterface $dispatcher, array $config = [])
119+
public function __construct($config = [])
112120
{
121+
if ($config instanceof DispatcherInterface) {
122+
@trigger_error(
123+
\sprintf(
124+
'Passing an instance of %1$s to %2$s() will not be supported in 7.0. '
125+
. 'Starting from 7.0 CMSPlugin class will no longer implement DispatcherAwareInterface.',
126+
DispatcherInterface::class,
127+
__METHOD__
128+
),
129+
\E_USER_DEPRECATED
130+
);
131+
132+
// Set the dispatcher we are to register our listeners with
133+
$this->setDispatcher($config);
134+
135+
$config = \func_num_args() > 1 ? func_get_arg(1) : [];
136+
}
137+
113138
// Get the parameters.
114139
if (isset($config['params'])) {
115140
if ($config['params'] instanceof Registry) {
@@ -153,9 +178,6 @@ public function __construct(DispatcherInterface $dispatcher, array $config = [])
153178
$this->db = Factory::getDbo();
154179
}
155180
}
156-
157-
// Set the dispatcher we are to register our listeners with
158-
$this->setDispatcher($dispatcher);
159181
}
160182

161183
/**
@@ -390,4 +412,83 @@ public function setApplication(CMSApplicationInterface $application): void
390412
$this->setLanguage($application->getLanguage());
391413
}
392414
}
415+
416+
/**
417+
* Set the language to use.
418+
*
419+
* @param Language $language The language to use
420+
*
421+
* @return void
422+
*
423+
* @since __DEPLOY_VERSION__
424+
*
425+
* @deprecated 5.2 will be removed in 7.0
426+
* Plugin should use the language from Application, and only after the app is initialised
427+
*/
428+
public function setLanguage(Language $language): void
429+
{
430+
$this->traitSetLanguage($language);
431+
}
432+
433+
/**
434+
* Get the Language.
435+
*
436+
* @return Language
437+
*
438+
* @throws \UnexpectedValueException May be thrown if the language has not been set.
439+
*
440+
* @since __DEPLOY_VERSION__
441+
*
442+
* @deprecated 5.2 will be removed in 7.0
443+
* Plugin should use the language from Application, and only after the app is initialised.
444+
*/
445+
protected function getLanguage(): Language
446+
{
447+
@trigger_error(
448+
__CLASS__ . ': Use of LanguageAwareInterface over CMSPlugin will be removed in 7.0.',
449+
\E_USER_DEPRECATED
450+
);
451+
452+
return $this->traitGetLanguage();
453+
}
454+
455+
/**
456+
* Set the dispatcher to use.
457+
*
458+
* @param DispatcherInterface $dispatcher The dispatcher to use.
459+
*
460+
* @return $this
461+
*
462+
* @since __DEPLOY_VERSION__
463+
*
464+
* @deprecated 5.2 will be removed in 7.0
465+
* Plugin should implement DispatcherAwareInterface on its own, when it is needed.
466+
*/
467+
public function setDispatcher(DispatcherInterface $dispatcher)
468+
{
469+
@trigger_error(
470+
__CLASS__ . ': Use of DispatcherAwareInterface over CMSPlugin will be removed in 7.0.'
471+
. ' Plugin should implement DispatcherAwareInterface on its own, when it is needed.',
472+
\E_USER_DEPRECATED
473+
);
474+
475+
return $this->traitSetDispatcher($dispatcher);
476+
}
477+
478+
/**
479+
* Get the event dispatcher.
480+
*
481+
* @return DispatcherInterface
482+
*
483+
* @throws \UnexpectedValueException May be thrown if the dispatcher has not been set.
484+
*
485+
* @since __DEPLOY_VERSION__
486+
*
487+
* @deprecated 5.2 will be removed in 7.0
488+
* Plugin should implement DispatcherAwareInterface on its own, when it is needed.
489+
*/
490+
public function getDispatcher()
491+
{
492+
return $this->traitGetDispatcher();
493+
}
393494
}

plugins/content/finder/src/Extension/Finder.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use Joomla\CMS\Event\Model;
1515
use Joomla\CMS\Plugin\CMSPlugin;
1616
use Joomla\CMS\Plugin\PluginHelper;
17+
use Joomla\Event\DispatcherAwareInterface;
18+
use Joomla\Event\DispatcherAwareTrait;
1719
use Joomla\Event\SubscriberInterface;
1820

1921
// phpcs:disable PSR1.Files.SideEffects
@@ -25,8 +27,10 @@
2527
*
2628
* @since 2.5
2729
*/
28-
final class Finder extends CMSPlugin implements SubscriberInterface
30+
final class Finder extends CMSPlugin implements SubscriberInterface, DispatcherAwareInterface
2931
{
32+
use DispatcherAwareTrait;
33+
3034
/**
3135
* Flag to check whether finder plugins already imported.
3236
*

plugins/editors/codemirror/src/Extension/Codemirror.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
use Joomla\CMS\Event\Editor\EditorSetupEvent;
1414
use Joomla\CMS\Plugin\CMSPlugin;
15+
use Joomla\Event\DispatcherAwareInterface;
16+
use Joomla\Event\DispatcherAwareTrait;
1517
use Joomla\Event\SubscriberInterface;
1618
use Joomla\Plugin\Editors\CodeMirror\Provider\CodeMirrorProvider;
1719

@@ -24,8 +26,10 @@
2426
*
2527
* @since 1.6
2628
*/
27-
final class Codemirror extends CMSPlugin implements SubscriberInterface
29+
final class Codemirror extends CMSPlugin implements SubscriberInterface, DispatcherAwareInterface
2830
{
31+
use DispatcherAwareTrait;
32+
2933
/**
3034
* Returns an array of events this subscriber will listen to.
3135
*

plugins/editors/none/src/Extension/None.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
use Joomla\CMS\Event\Editor\EditorSetupEvent;
1414
use Joomla\CMS\Plugin\CMSPlugin;
15+
use Joomla\Event\DispatcherAwareInterface;
16+
use Joomla\Event\DispatcherAwareTrait;
1517
use Joomla\Event\SubscriberInterface;
1618
use Joomla\Plugin\Editors\None\Provider\EditorNoneProvider;
1719

@@ -24,8 +26,10 @@
2426
*
2527
* @since 1.5
2628
*/
27-
final class None extends CMSPlugin implements SubscriberInterface
29+
final class None extends CMSPlugin implements SubscriberInterface, DispatcherAwareInterface
2830
{
31+
use DispatcherAwareTrait;
32+
2933
/**
3034
* Returns an array of events this subscriber will listen to.
3135
*

plugins/editors/tinymce/src/Extension/TinyMCE.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
use Joomla\CMS\Session\Session;
1818
use Joomla\CMS\String\StringableInterface;
1919
use Joomla\Database\DatabaseAwareTrait;
20+
use Joomla\Event\DispatcherAwareInterface;
21+
use Joomla\Event\DispatcherAwareTrait;
2022
use Joomla\Event\SubscriberInterface;
2123
use Joomla\Filesystem\Folder;
2224
use Joomla\Plugin\Editors\TinyMCE\PluginTraits\KnownButtons;
@@ -32,9 +34,10 @@
3234
*
3335
* @since 1.5
3436
*/
35-
final class TinyMCE extends CMSPlugin implements SubscriberInterface
37+
final class TinyMCE extends CMSPlugin implements SubscriberInterface, DispatcherAwareInterface
3638
{
3739
use DatabaseAwareTrait;
40+
use DispatcherAwareTrait;
3841

3942
// @todo: KnownButtons, ToolbarPresets for backward compatibility. Remove in Joomla 6
4043
use KnownButtons;

plugins/system/cache/src/Extension/Cache.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
use Joomla\CMS\Profiler\Profiler;
2525
use Joomla\CMS\Router\SiteRouter;
2626
use Joomla\CMS\Uri\Uri;
27+
use Joomla\Event\DispatcherAwareInterface;
28+
use Joomla\Event\DispatcherAwareTrait;
2729
use Joomla\Event\DispatcherInterface;
2830
use Joomla\Event\Event;
2931
use Joomla\Event\Priority;
@@ -38,8 +40,10 @@
3840
*
3941
* @since 1.5
4042
*/
41-
final class Cache extends CMSPlugin implements SubscriberInterface
43+
final class Cache extends CMSPlugin implements SubscriberInterface, DispatcherAwareInterface
4244
{
45+
use DispatcherAwareTrait;
46+
4347
/**
4448
* Cache instance.
4549
*

plugins/system/schemaorg/src/Extension/Schemaorg.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
use Joomla\CMS\User\UserFactoryAwareTrait;
2929
use Joomla\Database\DatabaseAwareTrait;
3030
use Joomla\Database\ParameterType;
31+
use Joomla\Event\DispatcherAwareInterface;
32+
use Joomla\Event\DispatcherAwareTrait;
3133
use Joomla\Event\SubscriberInterface;
3234
use Joomla\Registry\Registry;
3335

@@ -40,11 +42,12 @@
4042
*
4143
* @since 5.0.0
4244
*/
43-
final class Schemaorg extends CMSPlugin implements SubscriberInterface
45+
final class Schemaorg extends CMSPlugin implements SubscriberInterface, DispatcherAwareInterface
4446
{
4547
use DatabaseAwareTrait;
46-
use SchemaorgPrepareImageTrait;
48+
use DispatcherAwareTrait;
4749
use SchemaorgPrepareDateTrait;
50+
use SchemaorgPrepareImageTrait;
4851
use UserFactoryAwareTrait;
4952

5053
/**

plugins/system/shortcut/src/Extension/Shortcut.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
use Joomla\CMS\Plugin\CMSPlugin;
1717
use Joomla\CMS\Router\Route;
1818
use Joomla\CMS\Uri\Uri;
19+
use Joomla\Event\DispatcherAwareInterface;
20+
use Joomla\Event\DispatcherAwareTrait;
1921
use Joomla\Event\Event;
2022
use Joomla\Event\SubscriberInterface;
2123

@@ -28,8 +30,10 @@
2830
*
2931
* @since 4.2.0
3032
*/
31-
final class Shortcut extends CMSPlugin implements SubscriberInterface
33+
final class Shortcut extends CMSPlugin implements SubscriberInterface, DispatcherAwareInterface
3234
{
35+
use DispatcherAwareTrait;
36+
3337
/**
3438
* Returns an array of events this subscriber will listen to.
3539
*

0 commit comments

Comments
 (0)