RFC Feature PR-5.2-dev Pending

User tests: Successful: Unsuccessful:

avatar Fedik
Fedik
15 Jun 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: joomla/Manual#273
  • No documentation changes for manual.joomla.org needed

References:

avatar Fedik Fedik - open - 15 Jun 2024
avatar Fedik Fedik - change - 15 Jun 2024
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 15 Jun 2024
Category Libraries Front End Plugins
avatar Fedik Fedik - change - 15 Jun 2024
Labels Added: RFC Feature PR-5.2-dev
avatar Fedik Fedik - change - 15 Jun 2024
The description was changed
avatar Fedik Fedik - edited - 15 Jun 2024
avatar Fedik Fedik - change - 15 Jun 2024
The description was changed
avatar Fedik Fedik - edited - 15 Jun 2024
avatar Fedik Fedik - change - 15 Jun 2024
The description was changed
avatar Fedik Fedik - edited - 15 Jun 2024
avatar Fedik Fedik - change - 15 Jun 2024
Title
[5.2][RFC] CMSPlugin: Lazy subscriber interface and decorator
[5.x][RFC] CMSPlugin: Lazy subscriber interface and decorator
avatar Fedik Fedik - edited - 15 Jun 2024
avatar HLeithner
HLeithner - comment - 2 Sep 2024

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

avatar HLeithner HLeithner - change - 2 Sep 2024
Title
[5.x][RFC] CMSPlugin: Lazy subscriber interface and decorator
[5.3] [RFC] CMSPlugin: Lazy subscriber interface and decorator
avatar HLeithner HLeithner - edited - 2 Sep 2024

Add a Comment

Login with GitHub to post a comment