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.x][RFC] CMSPlugin: Lazy subscriber interface and decorator #43658

Open
wants to merge 16 commits into
base: 5.2-dev
Choose a base branch
from
Prev Previous commit
Next Next commit
SubscriberRegistrationCheckerInterface
  • Loading branch information
Fedik committed Jun 14, 2024
commit 08e5c6d09386bfe10c7891108e1688b47e16a943
18 changes: 17 additions & 1 deletion libraries/src/Event/LazyServiceEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*
* @since __DEPLOY_VERSION__
*/
final class LazyServiceEventSubscriber implements LazyEventSubscriberInterface, PluginInterface
final class LazyServiceEventSubscriber implements LazyEventSubscriberInterface, SubscriberRegistrationCheckerInterface, PluginInterface
{
/**
* The service container
Expand Down Expand Up @@ -105,6 +105,22 @@ public function getEventsAndListeners(): array
return $this->eventsAndListeners;
}

/**
* Check whether the Subscriber (or event listener) should be registered.
*
* @return bool
*
* @since __DEPLOY_VERSION__
*/
public function shouldRegisterListeners(): bool
{
if ($this->container->has(SubscriberRegistrationCheckerInterface::class)) {
return $this->container->get(SubscriberRegistrationCheckerInterface::class)->shouldRegisterListeners();
}

return true;
}

/**
* Method to call the event listeners.
*
Expand Down
31 changes: 31 additions & 0 deletions libraries/src/Event/SubscriberRegistrationCheckerInterface.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 SubscriberRegistrationCheckerInterface
{
/**
* Check whether the Subscriber (or event listener) should be registered.
*
* @return bool
*
* @since __DEPLOY_VERSION__
*/
public function shouldRegisterListeners(): bool;
}