PHPackages                             dnoegel/lazy-subscriber - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. dnoegel/lazy-subscriber

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

dnoegel/lazy-subscriber
=======================

Will allow you to define anonymous function as event listener callbacks for Shopware (4.2.0+)

065PHP

Since Oct 8Pushed 10y ago1 watchersCompare

[ Source](https://github.com/dnoegel/lazy-subscriber)[ Packagist](https://packagist.org/packages/dnoegel/lazy-subscriber)[ RSS](/packages/dnoegel-lazy-subscriber/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

LazySubscriber
==============

[](#lazysubscriber)

The Shopware `SubscriberInterface` allows you to define subscribers in order to subscribe to Shopware events easily. The `SubscriberInterface`, however, does not support anonymous function as callbacks, basically because Shopware tries to be forward compatible to the [Symfony `EventDispatcher`](https://github.com/symfony/EventDispatcher/blob/master/EventDispatcher.php#L121).

The `LazySubscriber` will provide you a simple way to define your callbacks as anonymous functions, which is especially comfortable, if you want to register a lot of services for Shopware's DIC. Using the `LazySubscriber` you can define your services as you would in e.g. Pimple.

How to use
==========

[](#how-to-use)

Install
-------

[](#install)

If you want to use composer for this dependency, just run `composer require dnoegel/lazy-subscriber`.

The Subscriber
--------------

[](#the-subscriber)

```
namespace YourPlugin\Subscriber;

class ContainerSubscriber extends LazySubscriber
{
    public function define()
    {
        return [
            'my_plugin.cart' => function() {
                return new Cart();
            },
            'my_plugin.persister' => function(DIC $c) {
                return new Persister($c->get('connection'));
            }
        ];
    }
}
```

Bootstrap
---------

[](#bootstrap)

In order to use your subscriber defined above, you need to register it during runtime.

```
class Shopware_Plugins_Frontend_YourPlugin_Bootstrap extends Shopware_Components_Plugin_Bootstrap
{
    // register namespaces for your plugin as well as for the lazy-subscriber library
    public function registerMyComponents()
    {
        $this->Application()->Loader()->registerNamespace(
            'Shopware\YourPlugin',
            $this->Path()
        );

        // you can use this
        require_once __DIR__ . '/vendor/autoload.php';
        // or this line to include the dependency:
        $this->Application()->Loader()->registerNamespace(
            'Dnoegel\LazySubscriber',
            $this->Path() . '/vendor/dnoegel/lazy-subscriber/src'
        );
    }

    // install: register an early event
    public function install()
    {
        $this->subscribeEvent(
            'Enlight_Controller_Front_DispatchLoopStartup',
            'onStartDispatch'
        );

        return true;
    }

    // Dynamically add your own subscriber
    public function onStartDispatch(Enlight_Event_EventArgs $args)
    {
        $this->registerMyComponents();

        $subscribers = array(
            new \Shopware\YourPlugin\Subscriber\ContainerSubscriber(Shopware()->Container())

        );

        foreach ($subscribers as $subscriber) {
            $this->Application()->Events()->addSubscriber($subscriber);
        }
    }
}
```

Should I use it?
================

[](#should-i-use-it)

It might be ok for populating the DI in your plugin as this is a bit cumbersome, especially during development. You should **not** use it for default events, and you should not use it as a way to define all your event subscribers in one big lazy subscriber. In addition to that be aware, that event subscribers works nicely - if you know what is going on behind the scenes and what to take care of. If this is not the case, you might want to stick to the "default event registration" way for the time being.

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/3e33c241de9be12145b80356591da2a7b875f1111d77a8f0a5474f55f02c91c1?d=identicon)[dnoegel](/maintainers/dnoegel)

---

Top Contributors

[![dnoegel](https://avatars.githubusercontent.com/u/1114384?v=4)](https://github.com/dnoegel "dnoegel (11 commits)")

### Embed Badge

![Health badge](/badges/dnoegel-lazy-subscriber/health.svg)

```
[![Health](https://phpackages.com/badges/dnoegel-lazy-subscriber/health.svg)](https://phpackages.com/packages/dnoegel-lazy-subscriber)
```

###  Alternatives

[zschuessler/laravel-route-to-class

A Laravel view composer that will convert the current route to a body class. 'admin/product/5/edit' becomes 'admin-product-edit'

26428.8k1](/packages/zschuessler-laravel-route-to-class)[mrm-commerce/magento-coding-standard-phpcs

MRM Commerce PHP Code Sniffer Coding Standard designed for Magento 2 applications

4751.2k](/packages/mrm-commerce-magento-coding-standard-phpcs)[helis/settings-manager-bundle

Provides a nice way to define variables and inject them into application parts

3069.1k](/packages/helis-settings-manager-bundle)[stepanenko3/nova-settings

This Laravel Nova settings tool based on env, using nativ nova fields and resources

3219.8k](/packages/stepanenko3-nova-settings)[vaimo/module-admin-auto-login

Provides automatic admin login on Magento projects; Useful addition when working with a project locally (should be used only as require-dev)

2140.1k](/packages/vaimo-module-admin-auto-login)[koala-framework/sourcemaps

Sourcemaps Utities

1563.5k2](/packages/koala-framework-sourcemaps)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
