68publishers/event-dispatcher-extra

Extension that adds a combination of global and local event dispatchers with bridge into Nette Framework.

Maintainers

👁 Jelen

Package info

github.com/68publishers/event-dispatcher-extra

pkg:composer/68publishers/event-dispatcher-extra

Statistics

Installs: 1 013

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

v1.3.0 2025-05-29 11:38 UTC

Requires

Suggests

  • nette/di: For an integration with Nette Framework.

Provides

None

Replaces

None

MIT 442e062374d2ff533b261c4b435aa01663db5b2f

  • Tomáš Glawaty <tomasglawaty.woop@icloud.com>

eventmanagerevents68publishers

This package is auto-updated.

Last update: 2026-05-29 01:28:48 UTC


README

✨ Extension that adds a combination of global and local event dispatchers with bridge into Nette Framework. The global event dispatcher is the one that is registered as a service in DI Container. The local event dispatcher is a unique instance for each created object.

Installation

The best way to install 68publishers/event-dispatcher-extra is using Composer:

composer require 68publishers/event-dispatcher-extra

Integration into Nette Framework

All you need is register a compiler extension:

extensions:
 68publishers.event_dispatcher_extra: SixtyEightPublishers\EventDispatcherExtra\Bridge\Nette\DI\EventDispatcherExtraExtension

The extension expects a service of type Symfony\Component\EventDispatcher\EventDispatcherInterface in the DI Container so you can use any integration of symfony/event-dispatcher into the Nette Framework or you can simply register the service:

services:
 -
 type: Symfony\Component\EventDispatcher\EventDispatcher
 factory: Symfony\Component\EventDispatcher\EventDispatcher

Example usage

Service and factory:

<?php

use Symfony\Contracts\EventDispatcher\Event;
use SixtyEightPublishers\EventDispatcherExtra\EventDispatcherAwareTrait;
use SixtyEightPublishers\EventDispatcherExtra\EventDispatcherAwareInterface;

final class MyService implements EventDispatcherAwareInterface
{
 use EventDispatcherAwareTrait;

 public function doSomething() : void
 {
 $this->getEventDispatcher()->dispatch(new Event(), 'something');
 }
}

interface MyServiceFactoryInterface
{
 public function create() : MyService;
}
<?php

/** @var MyServiceFactoryInterface $factory */

$service1 = $factory->create();
$service2 = $factory->create();

# attach a local event listener on specific instance:
$service1->getEventDispatcher()->addListener('something', static function () {
 # do some stuff here
});

# the "global" listeners and subscribers will be called as first and then will be called "local" listener defined above:
$service1->doSomething();

# only the "global" listeners and subscribers will be called:
$service2->doSomething();

Contributing

Before committing any changes, don't forget to run

$ vendor/bin/php-cs-fixer fix --config=.php_cs.dist -v --dry-run

and

$ composer run tests