Skip to content

Commit

Permalink
SubscriberRegistrationCheckerInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
Fedik committed Jun 14, 2024
1 parent 1bc3f54 commit 08e5c6d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
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;
}

0 comments on commit 08e5c6d

Please sign in to comment.