Skip to content

Plugins lazy loading#585

Open
Fedik wants to merge 3 commits intojoomla:mainfrom
Fedik:lazy-plugin
Open

Plugins lazy loading#585
Fedik wants to merge 3 commits intojoomla:mainfrom
Fedik:lazy-plugin

Conversation

@Fedik
Copy link
Member

@Fedik Fedik commented Feb 10, 2026

@Fedik Fedik requested a review from robbiejackson February 10, 2026 12:04
@qodo-code-review
Copy link
Contributor

Review Summary by Qodo

Document plugin lazy loading support for PHP 8.4

📝 Documentation ✨ Enhancement

Grey Divider

Walkthroughs

Description
• Added documentation for PHP 8.4 lazy objects support in plugins
• Explains how to use $container->lazy() in service providers
• Includes code example for lazy plugin instantiation
• Documents performance improvement benefits for Joomla 6.1+
Diagram
flowchart LR
  A["Plugin Documentation"] -->|"Add lazy loading guide"| B["Service Provider Example"]
  B -->|"Use container.lazy()"| C["Deferred Plugin Instantiation"]
  C -->|"Improves Performance"| D["Joomla 6.1+"]
Loading

Grey Divider

File Changes

1. docs/building-extensions/plugins/basic-content-plugin.md 📝 Documentation +23/-1

Add PHP 8.4 lazy loading documentation with examples

• Added tip section documenting PHP 8.4 lazy objects support
• Provided code example showing how to use $container->lazy() in service providers
• Explained performance benefits of lazy loading plugins
• Fixed trailing newline formatting

docs/building-extensions/plugins/basic-content-plugin.md


2. migrations/60-61/new-features.md 📝 Documentation +8/-0

Document lazy loading feature in release notes

• Added new feature entry for plugin lazy loading support
• Documented availability for PHP >= 8.4
• Referenced related pull requests for implementation details
• Highlighted performance improvement benefits

migrations/60-61/new-features.md


Grey Divider

Qodo Logo

@qodo-code-review
Copy link
Contributor

qodo-code-review bot commented Feb 10, 2026

Code Review by Qodo

🐞 Bugs (2) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider


Action required

✅ 1. Invalid lazy snippet 🐞 Bug ✓ Correctness
Description
The new lazy-loading service provider example is not valid PHP as written (missing ; after the
anonymous class) and the lazy factory closure doesn’t show returning a plugin instance. Users
copy/pasting will hit syntax errors and/or register a null/invalid plugin service.
Code

docs/building-extensions/plugins/basic-content-plugin.md[R190-201]

+return new class() implements ServiceProviderInterface
+{
+    public function register(Container $container)
+    {
+        $container->set(
+            PluginInterface::class,
+            $container->lazy(Shortcode::class, function (Container $container) {
+                // ... existing code
+            })
+        );
+    }
+}
Evidence
The newly added snippet ends the anonymous class with } but not };, which is required when
returning an anonymous class expression, and its closure body contains no return. Earlier in the
same document, the non-lazy example shows the correct }; terminator and returns $plugin,
demonstrating the expected pattern this new snippet should follow.

docs/building-extensions/plugins/basic-content-plugin.md[189-202]
docs/building-extensions/plugins/basic-content-plugin.md[142-161]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The lazy-loading service provider example in `basic-content-plugin.md` is invalid PHP because it returns an anonymous class without terminating the statement (`};`). In addition, the lazy factory closure doesn’t show returning a plugin instance, which can lead to copy/paste implementations that register an invalid service.
## Issue Context
This is a docs snippet that developers are likely to copy directly.
## Fix Focus Areas
- docs/building-extensions/plugins/basic-content-plugin.md[189-202]
- docs/building-extensions/plugins/basic-content-plugin.md[131-162]
## Suggested change (illustrative)
Update the snippet to end with `};` and include an explicit `return $plugin;` inside the lazy closure (mirroring the earlier non-lazy example’s body).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

2. Migration note grammar 🐞 Bug ✓ Correctness
Description
The new migration note has a grammatical error (“when the event dispatched”) and fragmented phrasing
that reduces clarity. This can confuse readers about when lazy loading occurs.
Code

migrations/60-61/new-features.md[R33-36]

+## Support Plugin lazy loading for PHP >= 8.4
+
+Added a possibility to load plugin class on demand (lazy loading) when the event dispatched. 
+For servers with PHP version >= 8.4. This helps to improve overall CMS performance.
Evidence
The migration note text contains an ungrammatical clause and sentence fragments, which is the only
description of the feature in that section.

migrations/60-61/new-features.md[33-36]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The migration note contains grammatical errors and fragmented sentences, reducing clarity.
## Issue Context
This is user-facing migration documentation for 6.0→6.1.
## Fix Focus Areas
- migrations/60-61/new-features.md[33-36]
## Suggested rewording (example)
“Adds support for lazily loading plugin classes on demand when an event is dispatched (PHP >= 8.4), improving overall CMS performance.”

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

@HLeithner
Copy link
Member

thanks, I would prefer to rewrite all example usages, at the moment it looks like a "hey good to know" not like, "do it or you are the bad one" ;-)

Shortcode::class I think this needs explanation.

Also I think it would be good to mentation that the code is compatible with joomla 6.0 (container lazy support) but really useful with 6.1.

Also it's a complete description missing what, why, who it works. And what you need to consider (don't use the constructor for global effects), plugin object might not be create if event function is self contain and such things (subscriberinterface).

@Fedik
Copy link
Member Author

Fedik commented Feb 12, 2026

I would prefer to rewrite all example usages

I think for this it is need to review whole Manual then.

@HLeithner
Copy link
Member

maybe @robbiejackson can help and I think we don't have to many examples and a good plugin section.

@robbiejackson
Copy link
Contributor

I was planning to have a lazy loading section in the Plugin Advanced Features page. I'm away on holiday for a bit over 3 weeks but could have a look at that when I get back, if no-one else does it. So I'm OK with this PR as it stands, and can address other stuff as part of a separate PR.

I see it's using PHP 8.4. Is it agreed when 8.4 will be required as a prerequisite of Joomla? In 6.1?

I wouldn't want to have examples which didn't work because of <8.4 version, if that version was not mandated by Joomla.

@HLeithner
Copy link
Member

The code is already in Joomla 6.0, if php is < 8.4 we fallback to the "old" behaviour (directly creating the object) so you can use the same code already for joomla 6.0 and/or php 8.3 but it doesn't have the same effect.

And it's not "advanced" it's the new default.

thanks for offering doing this, have a nice vacation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants