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 |
|
This pull request has been automatically rebased to 5.3-dev.