Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x][RFC] Plugins loading concept. Creating the plugin instance on demand (when the respective event is triggered) #43463

Open
wants to merge 9 commits into
base: 5.2-dev
Choose a base branch
from

Conversation

Fedik
Copy link
Member

@Fedik Fedik commented May 12, 2024

Summary of Changes

This is concept of loading the plugins on demand.
The idea (not new) is to instantiate the plugin only when the event is triggered, thus reduce App initialisation and execution in general. This can be achieved for plugins that implements SubscriberInterface.

The PR contains an examples based on: LanguageFilter, Debug and GuidedTours plugins.

It works as folowing:
PluginHelper::importPlugin() reading the plugin event with getSubscribedEvents(), and creates a clousore for each.
When the event is triggered the closure is looking for the plugin instance, and executes the event method.

Instead of use $app->bootPlugin() it introduce $app->getPluginContainer(), which allows to retrieve the plugin information without booting it in first place.

New options for plugin service:

  • plugin.information Define the plugin class name, and implemented interfaces. This is important to be able to get the class name without booting whole plugin. (Should be probably some kind of configurable class, that can read this information from XML automaticaly, or set by developer. Need to discuss, please share your ideas)
  • plugin.executeValidation Validate if the plugin should be executed in current runtime. This solves long standing problem, when we have to run $app->isClinet('potato') in many events. (Should probably also be some kind of configurable class. Need to discuss, please share your ideas)

The PR uses a simple arrays for new options, however it is only for purpuse of demonstration. Some of these things need to be updated to to proper Class/Interface.

impact on existing plugins:

Zero, Null, Nulo, no backward compatibility break. All existing plugins will work as before.

Testing Instructions

The PR can be merged without testing.

Link to documentations

Please select:

  • Documentation link for docs.joomla.org:
  • No documentation changes for docs.joomla.org needed
  • Pull Request link for manual.joomla.org: TBD
  • No documentation changes for manual.joomla.org needed

Please share your opinions 馃嵒

@joomla-cms-bot joomla-cms-bot added PR-5.2-dev RFC Request for Comment labels May 12, 2024
@Fedik Fedik added the Feature label May 12, 2024
*
* @since __DEPLOY_VERSION__
*/
public function getPluginContainer($plugin, $type): ContainerInterface
Copy link
Member Author

@Fedik Fedik May 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: This should not be public in final implementation. Made like that to "make it work" purpuse only (and for demonstartion).
Probably need a standalone ExtesionManager class.

// Add a listener, which will instantiate the plugin when the event will dispatch
foreach ($class::getSubscribedEvents() as $eventName => $handler) {
$dispatcher->addListener($eventName, function ($event) use ($container, $handler, &$instance) {
$instance = $instance ?? $container->get(PluginInterface::class);
Copy link
Member Author

@Fedik Fedik May 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: It probably should still use bootPlugin() to get the plugin instance, to keep API consistent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature PR-5.2-dev RFC Request for Comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants