contributte/dummy-events

This package is abandoned and no longer maintained. The author suggests using the contributte/event-dispatcher package instead.

Simple events for Nette

2.0.0 2018-06-25 21:59 UTC

This package is auto-updated.

Last update: 2021-06-28 10:57:09 UTC


README

68747470733a2f2f62616467656e2e6e65742f62616467652f737570706f72742f6769747465722f6379616e 68747470733a2f2f62616467656e2e6e65742f62616467652f737570706f72742f666f72756d2f79656c6c6f77 68747470733a2f2f62616467656e2e6e65742f62616467652f73706f6e736f722f646f6e6174696f6e732f463936383534

Website 🚀 contributte.org | Contact 👨🏻‍💻 f3l1x.io | Twitter 🐦 @contributte

Disclaimer

Composer contributte/dummy-events
Version
PHP
License

Documentation

Usage

Register extension

Register in your config file (e.q. config.neon).

extensions:
    events: Contributte\DummyEvents\DI\EventsExtension

Register events

On Container compile - EventsExtension collect all services which implement EventsSubscriber and call their onEvents($em) method.

use Contributte\DummyEvents\EventsSubscriber;
use Contributte\DummyEvents\EventsManager;

class TestService implements EventsSubscriber 
{
    /**
     * @param EventsManager $em
     */
    public function onEvents(EventsManager $em) {
        $em->on('order.update', function($state) {
            // Some logic..
        });
    }
}

Register lazy events

Name tag as event name with prefix event.

services:
    {class: TestService, tags: [event.order.update]}

Or use tag arrays with key name events.

services:
    {class: TestService, tags: [events: [order.update]]}

This prevents usage of other tags.

If EventsSubscriber register more events and also is lazy registered (by tags in neon). Implemented method onEvents(EventsManager $em) is called only once.

use Contributte\DummyEvents\EventsSubscriber;
use Contributte\DummyEvents\EventsManager;

class TestSubscriber implements EventsSubscriber 
{
    
    public function onEvents(EventsManager $em) {
        $em->on('order.create', function($state) {
            // Some logic..
        });
        
        $em->on('order.update', function($state) {
            // Some logic..
        });
        
        $em->on('order.delete', function($state) {
            // Some logic..
        });
    }
}

Fire events

Inject to your class ultra-simple EventsManager.

use Contributte\DummyEvents\EventsManager;

/** @var EventsManager @inject **/
public $em;

public function save() {
    // Some logic..
    
    // Fire order update events
    $this->em->trigger('order.update', $order->state);
}

Development

This package was maintain by these authors.

538058?v=3&s=80

Consider to support contributte development team. Also thank you for being used this package.