[6.1] CMSPlugin: use Lazy Object feature#45062
Conversation
Co-authored-by: Brian Teeman <[email protected]>
|
As said already, this should be done in the DI container and not every plugin itself should implement this. Or do you see problems when the DI container does that? |
|
How to? |
|
Similar cod you have in the service provider, I would do here https://github.com/joomla-framework/di/blob/3.x-dev/src/ContainerResource.php#L160. |
|
hm, yeah, that also could work, need to check. We need it to be flexible. But I thought that you have some ready to use solution :) |
|
This pull request has been automatically rebased to 6.0-dev. |
|
I would suggest to add a simple shortcut for creating lazy proxies: // Container
public function lazy(string $class, callable $factory): callable
{
if (PHP_VERSION_ID < 80400) {
return $factory;
}
return function () use ($class, $factory) {
return (new \ReflectionClass($class))->newLazyProxy(fn() => $factory($this));
};
}Then defining lazy service would look like this: $container->share(
'foo',
$container->lazy(Foo::class, function($container) {
return new Foo($container->get('bar'));
}),
);Full implementation you can see here: |
|
I've created a PR with more advanced implementation: joomla-framework/di#58 |
|
@laoneo That is require changes in Container code with b/c breaks (need new flags and changed method signature). I will keep it without DI, there more important issue that need to resolve to make it work. |
|
It still fine, with introducing of "Reflection checker" it does not change existing behavior. |
|
✅ Tested my random quotation module zitat-service.de with JBT: it installs from JED Web, is is configurable and working on frontend site |
Conflicts: plugins/system/cache/src/Extension/Cache.php plugins/system/schedulerunner/services/provider.php plugins/system/schemaorg/services/provider.php plugins/system/tasknotification/services/provider.php
|
This pull request has been automatically rebased to 6.1-dev. |
|
@Fedik - is this finalized and therefore testable? Will gladly test it for you if it is. |
|
Yes it is, as for now. |
|
I tested it today with my own component and at the first look it worked but after playing with the subscribed events I found out that the plugin is not loaded if |
|
I have tested this item ✅ successfully on 97c0b79 This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/45062. |
|
I have tested this item ✅ successfully on 97c0b79
|
|
RTC This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/45062. |
|
Thanks |
Summary of Changes
Alternative to #43658
Use of PHP Lazy Object feature for plugins.
This allows to instantiate the plugin only when event is triggered, and saving some resources (time and memory).
This does not applied automatically for every plugins, the plugin service provider need to be updated to support Lazy Object.
Few thing that need to figure out:
Following code will trigger lazy object initialization, we need to get rid of it, somehow.joomla-cms/libraries/src/Plugin/PluginHelper.php
Lines 234 to 236 in 2c859aa
Current use of
registerListeners()need to be deprecated. There is PR for it:As next step we have to:
OR change the return type to boolean for
registerListeners(),OR replace it with new method, see the PR:
Testing Instructions
Apply patch, and test on PHP 8.x and 8.4
The following plugins should work as before:
Link to documentations
Please select: