User tests: Successful: Unsuccessful:
Adding LazySybscriber interface and decorator.
The decorator LazyServiceSubscriber
allows to instantiate the plugin with heavy dependencies only when the event is actualy dispatched.
The interface LazySubscriberInterface
also allows to use LazyServiceEventListener
, hovewer the plugin should implement it on its own.
Code for plugins/system/example/services/provider.php
.
Before:
return new class () implements ServiceProviderInterface {
public function register(Container $container)
{
$container->set(
PluginInterface::class,
function (Container $container) {
$heavyDependency1 = $container->get(Foo::class);
$heavyDependency2 = $container->get(Bar::class);
return new ExamplePlugin(
$container->get(DispatcherInterface::class),
(array) PluginHelper::getPlugin('system', 'example'),
$heavyDependency1,
$heavyDependency2
);
}
);
}
}
After:
return new class () implements ServiceProviderInterface {
public function register(Container $container)
{
$container->set(
ExamplePlugin::class,
function (Container $container) {
$heavyDependency1 = $container->get(Foo::class);
$heavyDependency2 = $container->get(Bar::class);
return new ExamplePlugin(
$container->get(DispatcherInterface::class),
(array) PluginHelper::getPlugin('system', 'example'),
$heavyDependency1,
$heavyDependency2
);
}
)->set(
PluginInterface::class,
function (Container $container) {
return new LazyServiceSubscriber($container, ExamplePlugin::class);
}
);
}
}
The decorator can work very nicely with (in future):
But I will update it depend what first will be merged this PR or that PR.
Code review by maintainers.
Check that following plugins works as before:
ScheduleRunner
TaskNotification
Webauthn
Works
Works
Please select:
References:
Status | New | ⇒ | Pending |
Category | ⇒ | Libraries Front End Plugins |
Labels |
Added:
RFC
Feature
PR-5.2-dev
|
Title |
|
Title |
|
I will redo this with Lazy Objects
Current approach is totally obsolete with PHP 8.4
But we still support earlier versions of PHP don't we?
Would it not make more sense to have the whole DI container to support lazy objects? Like that, the plugins are only instantiated when actually used.
But we still support earlier versions of PHP don't we?
I doubt this PR will be merged in 1-2 years, we have plenty of time 😄
Would it not make more sense to have the whole DI container to support lazy objects
I need to see a code or an example to say something about it. In theory maybe "yes".
But currently I hardly imagine how it can be done.
Status | Pending | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2025-03-03 16:52:43 |
Closed_By | ⇒ | Fedik | |
Labels |
Added:
PR-5.3-dev
Removed: PR-5.2-dev |
This pull request has been automatically rebased to 5.3-dev.