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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.3] [RFC] CMSPlugin: Lazy subscriber interface and decorator #43658

Open
wants to merge 16 commits into
base: 5.3-dev
Choose a base branch
from

Conversation

Fedik
Copy link
Member

@Fedik Fedik commented Jun 15, 2024

Summary of Changes

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.

Example usage of the decorator for the plugin with heavy dependencies:

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.

Testing Instructions

Code review by maintainers.

Check that following plugins works as before:

ScheduleRunner
TaskNotification
Webauthn

Actual result BEFORE applying this Pull Request

Works

Expected result AFTER applying this Pull Request

Works

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: Info about Lazy Subscriber Manual#273
  • No documentation changes for manual.joomla.org needed

References:

@joomla-cms-bot joomla-cms-bot added PR-5.2-dev RFC Request for Comment labels Jun 15, 2024
@Fedik Fedik added the Feature label Jun 15, 2024
@Fedik Fedik changed the title [5.2][RFC] CMSPlugin: Lazy subscriber interface and decorator [5.x][RFC] CMSPlugin: Lazy subscriber interface and decorator Jun 15, 2024
@HLeithner HLeithner changed the base branch from 5.2-dev to 5.3-dev September 2, 2024 08:51
@HLeithner
Copy link
Member

This pull request has been automatically rebased to 5.3-dev.

@HLeithner HLeithner changed the title [5.x][RFC] CMSPlugin: Lazy subscriber interface and decorator [5.3] [RFC] CMSPlugin: Lazy subscriber interface and decorator Sep 2, 2024
@Hackwar Hackwar removed the PR-5.2-dev label Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature PR-5.3-dev RFC Request for Comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants