Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
12b3977
CMSPlugin: use Lazy Object feature
Fedik Mar 3, 2025
01e632f
CMSPlugin: use Lazy Object feature
Fedik Mar 3, 2025
a6fb246
Update libraries/src/Plugin/CMSPlugin.php
Fedik Mar 3, 2025
4142bc7
CMSPlugin: use Lazy Object feature
Fedik Mar 3, 2025
6546c55
CMSPlugin: use Lazy Object feature
Fedik Mar 3, 2025
23778ea
tst
Fedik Mar 3, 2025
c7fa33a
tst
Fedik Mar 3, 2025
d27ee97
Use lazy proxy
Fedik Mar 3, 2025
48a3950
Merge branch '6.0-dev' into plugin-lazy-objects
HLeithner Mar 6, 2025
36fe142
tst
Fedik Mar 9, 2025
b76f77f
tst
Fedik Mar 9, 2025
bf94b46
Merge branch '6.0-dev' into plugin-lazy-objects
Fedik Mar 12, 2025
50a7386
LazySubscriberInterface
Fedik Mar 12, 2025
def84d0
simplify
Fedik Mar 12, 2025
02486fb
fix
Fedik Mar 12, 2025
c16cc08
fix
Fedik Mar 12, 2025
1ebfa85
fix
Fedik Mar 12, 2025
56ff36f
fix
Fedik Mar 12, 2025
b1edeba
fix
Fedik Mar 12, 2025
eaad966
fix
Fedik Mar 12, 2025
d768e43
implement once
Fedik Mar 13, 2025
fb10ee0
PluginWithSubscriberInterface
Fedik Mar 13, 2025
8b60479
fix
Fedik Mar 13, 2025
3bcafcc
fix
Fedik Mar 13, 2025
4aa834f
re arrange
Fedik Mar 13, 2025
e49a486
Merge branch '6.0-dev' into plugin-lazy-objects
Fedik May 3, 2025
d6049dc
Merge branch '6.0-dev' into plugin-lazy-objects
Fedik Jun 7, 2025
acf47fc
set Dispatcher in the plugin service provider
Fedik Jun 7, 2025
6974249
use reflection
Fedik Jun 7, 2025
97c0b79
fixes
Fedik Jun 7, 2025
f5fe026
Merge branch '6.0-dev' into plugin-lazy-objects
Fedik Aug 12, 2025
b1314d1
use di helper
Fedik Aug 12, 2025
83f961e
phpstan
Fedik Aug 12, 2025
608b6b9
Merge branch '6.0-dev' into plugin-lazy-objects
muhme Aug 21, 2025
230bc18
Merge branch '6.0-dev' into plugin-lazy-objects
Fedik Aug 28, 2025
d7f1a31
typo
Fedik Aug 28, 2025
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
6 changes: 3 additions & 3 deletions libraries/src/Plugin/CMSPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ public function registerListeners()
{
// Plugins which are SubscriberInterface implementations are handled without legacy layer support
if ($this instanceof SubscriberInterface) {
$this->getDispatcher()->addSubscriber($this);

return;
// The subscriber registration handled by PluginHelper::import().
// Return boolean instead of void, to distinguish overridden registerListeners(), need for backward compatibility.
return true;
}

$reflectedObject = new \ReflectionObject($this);
Expand Down
12 changes: 8 additions & 4 deletions libraries/src/Plugin/PluginHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Joomla\CMS\Factory;
use Joomla\Event\DispatcherAwareInterface;
use Joomla\Event\DispatcherInterface;
use Joomla\Event\SubscriberInterface;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand Down Expand Up @@ -231,15 +232,18 @@ protected static function import($plugin, $autocreate = true, ?DispatcherInterfa

$plugin = Factory::getApplication()->bootPlugin($plugin->name, $plugin->type);

if ($dispatcher && $plugin instanceof DispatcherAwareInterface) {
$plugin->setDispatcher($dispatcher);
}
// @TODO: This piece of code breaks everything, and triggering Lazy Object instantiation !!!
// if ($dispatcher && $plugin instanceof DispatcherAwareInterface) {
// $plugin->setDispatcher($dispatcher);
// }

if (!$autocreate) {
return;
}

$plugin->registerListeners();
if ($plugin->registerListeners() && $plugin instanceof SubscriberInterface) {
$dispatcher->addSubscriber($plugin);
}
}

/**
Expand Down
29 changes: 24 additions & 5 deletions plugins/system/schedulerunner/services/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,30 @@ public function register(Container $container): void
$container->set(
PluginInterface::class,
function (Container $container) {
$plugin = new ScheduleRunner(
$container->get(DispatcherInterface::class),
(array) PluginHelper::getPlugin('system', 'schedulerunner')
);
$plugin->setApplication(Factory::getApplication());
$construct = function (?ScheduleRunner $plugin = null) use ($container) {
$eager = !$plugin;
$params = [
$container->get(DispatcherInterface::class),
(array) PluginHelper::getPlugin('system', 'schedulerunner'),
];

if ($eager) {
$plugin = new ScheduleRunner(...$params);
} else {
$plugin->__construct(...$params);
}

$plugin->setApplication(Factory::getApplication());

return $eager ? $plugin : null;
};

if (PHP_VERSION_ID >= 80400) {
$reflector = new ReflectionClass(ScheduleRunner::class);
$plugin = $reflector->newLazyGhost($construct);
} else {
$plugin = $construct();
}

return $plugin;
}
Expand Down
33 changes: 26 additions & 7 deletions plugins/system/tasknotification/services/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,32 @@ public function register(Container $container): void
$container->set(
PluginInterface::class,
function (Container $container) {
$plugin = new TaskNotification(
$container->get(DispatcherInterface::class),
(array) PluginHelper::getPlugin('system', 'tasknotification')
);
$plugin->setApplication(Factory::getApplication());
$plugin->setDatabase($container->get(DatabaseInterface::class));
$plugin->setUserFactory($container->get(UserFactoryInterface::class));
$construct = function (?TaskNotification $plugin = null) use ($container) {
$eager = !$plugin;
$params = [
$container->get(DispatcherInterface::class),
(array) PluginHelper::getPlugin('system', 'tasknotification'),
];

if ($eager) {
$plugin = new TaskNotification(...$params);
} else {
$plugin->__construct(...$params);
}

$plugin->setApplication(Factory::getApplication());
$plugin->setDatabase($container->get(DatabaseInterface::class));
$plugin->setUserFactory($container->get(UserFactoryInterface::class));

return $eager ? $plugin : null;
};

if (PHP_VERSION_ID >= 80400) {
$reflector = new ReflectionClass(TaskNotification::class);
$plugin = $reflector->newLazyGhost($construct);
} else {
$plugin = $construct();
}

return $plugin;
}
Expand Down
63 changes: 41 additions & 22 deletions plugins/system/webauthn/services/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,33 +42,52 @@ public function register(Container $container)
$container->set(
PluginInterface::class,
function (Container $container) {
$app = Factory::getApplication();
$session = $container->has('session') ? $container->get('session') : $this->getSession($app);
$construct = function (?Webauthn $plugin = null) use ($container) {
$eager = !$plugin;
$app = Factory::getApplication();
$session = $container->has('session') ? $container->get('session') : $this->getSession($app);

$db = $container->get(DatabaseInterface::class);
$credentialsRepository = $container->has(PublicKeyCredentialSourceRepository::class)
? $container->get(PublicKeyCredentialSourceRepository::class)
: new CredentialRepository($db);
$db = $container->get(DatabaseInterface::class);
$credentialsRepository = $container->has(PublicKeyCredentialSourceRepository::class)
? $container->get(PublicKeyCredentialSourceRepository::class)
: new CredentialRepository($db);

$metadataRepository = null;
$params = new Registry($config['params'] ?? '{}');
$metadataRepository = null;
$params = new Registry($config['params'] ?? '{}');

if ($params->get('attestationSupport', 0) == 1) {
$metadataRepository = $container->has(MetadataStatementRepository::class)
? $container->get(MetadataStatementRepository::class)
: new MetadataRepository();
}
if ($params->get('attestationSupport', 0) == 1) {
$metadataRepository = $container->has(MetadataStatementRepository::class)
? $container->get(MetadataStatementRepository::class)
: new MetadataRepository();
}

$authenticationHelper = $container->has(Authentication::class)
? $container->get(Authentication::class)
: new Authentication($app, $session, $credentialsRepository, $metadataRepository);

$params = [
$container->get(DispatcherInterface::class),
(array) PluginHelper::getPlugin('system', 'webauthn'),
$authenticationHelper,
];

$authenticationHelper = $container->has(Authentication::class)
? $container->get(Authentication::class)
: new Authentication($app, $session, $credentialsRepository, $metadataRepository);
if ($eager) {
$plugin = new Webauthn(...$params);
} else {
$plugin->__construct(...$params);
}

$plugin = new Webauthn(
$container->get(DispatcherInterface::class),
(array) PluginHelper::getPlugin('system', 'webauthn'),
$authenticationHelper
);
$plugin->setApplication($app);
$plugin->setApplication($app);

return $eager ? $plugin : null;
};

if (PHP_VERSION_ID >= 80400) {
$reflector = new ReflectionClass(Webauthn::class);
$plugin = $reflector->newLazyGhost($construct);
} else {
$plugin = $construct();
}

return $plugin;
}
Expand Down