Skip to content

Commit 27a1218

Browse files
committed
RegisterListenersChecker
1 parent a7bba71 commit 27a1218

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
/**
4+
* Joomla! Content Management System
5+
*
6+
* @copyright (C) 2024 Open Source Matters, Inc. <https://www.joomla.org>
7+
* @license GNU General Public License version 2 or later; see LICENSE.txt
8+
*/
9+
10+
namespace Joomla\CMS\Event;
11+
12+
// phpcs:disable PSR1.Files.SideEffects
13+
\defined('_JEXEC') or die;
14+
// phpcs:enable PSR1.Files.SideEffects
15+
16+
/**
17+
* Provides a method to check whether the Subscriber (or event listener) should be registered.
18+
*
19+
* @since __DEPLOY_VERSION__
20+
*/
21+
interface RegisterListenersCheckerInterface
22+
{
23+
/**
24+
* Check whether the Subscriber (or event listener) should be registered.
25+
*
26+
* @return bool
27+
*
28+
* @since __DEPLOY_VERSION__
29+
*/
30+
public function shouldRegisterListeners(): bool;
31+
}

libraries/src/Plugin/PluginHelper.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace Joomla\CMS\Plugin;
1111

1212
use Joomla\CMS\Cache\Exception\CacheExceptionInterface;
13+
use Joomla\CMS\Event\RegisterListenersCheckerInterface;
1314
use Joomla\CMS\Factory;
1415
use Joomla\Event\DispatcherAwareInterface;
1516
use Joomla\Event\DispatcherInterface;
@@ -239,6 +240,12 @@ protected static function import($plugin, $autocreate = true, DispatcherInterfac
239240
return;
240241
}
241242

243+
// Check whether we should register the subscriber in current runtime
244+
if ($plugin instanceof RegisterListenersCheckerInterface && !$plugin->shouldRegisterListeners()) {
245+
dump($plugin);
246+
return;
247+
}
248+
242249
$plugin->registerListeners();
243250
}
244251

0 commit comments

Comments
 (0)