Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.3] [RFC] CMSPlugin: Subscriber Registration Checker Interface #43657

Open
wants to merge 6 commits into
base: 5.3-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
RegisterListenersChecker
  • Loading branch information
Fedik committed Jun 14, 2024
commit 27a12184773e7903a15d8d0a2e2f71ff0567af7b
31 changes: 31 additions & 0 deletions libraries/src/Event/RegisterListenersCheckerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

/**
* Joomla! Content Management System
*
* @copyright (C) 2024 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Joomla\CMS\Event;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
* Provides a method to check whether the Subscriber (or event listener) should be registered.
*
* @since __DEPLOY_VERSION__
*/
interface RegisterListenersCheckerInterface
{
/**
* Check whether the Subscriber (or event listener) should be registered.
*
* @return bool
*
* @since __DEPLOY_VERSION__
*/
public function shouldRegisterListeners(): bool;
}
7 changes: 7 additions & 0 deletions libraries/src/Plugin/PluginHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace Joomla\CMS\Plugin;

use Joomla\CMS\Cache\Exception\CacheExceptionInterface;
use Joomla\CMS\Event\RegisterListenersCheckerInterface;
use Joomla\CMS\Factory;
use Joomla\Event\DispatcherAwareInterface;
use Joomla\Event\DispatcherInterface;
Expand Down Expand Up @@ -239,6 +240,12 @@ protected static function import($plugin, $autocreate = true, DispatcherInterfac
return;
}

// Check whether we should register the subscriber in current runtime
if ($plugin instanceof RegisterListenersCheckerInterface && !$plugin->shouldRegisterListeners()) {
dump($plugin);
return;
}

$plugin->registerListeners();
}

Expand Down