2017 © Pedro Peláez
 

library event-snoozer

Snooze your events for later dispatch.

image

zhem4ag/event-snoozer

Snooze your events for later dispatch.

  • Thursday, July 27, 2017
  • by zhem4ag
  • Repository
  • 2 Watchers
  • 2 Stars
  • 1,467 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 9 Versions
  • 14 % Grown

The README.md

Build Status SensioLabsInsight MIT Licence Code Climate, (*1)

EventSnoozer

Current library allows You to store events and dispatch them later., (*2)

Usage

  • Implement EventStorageInterface or use MemoryEventStorage. I suggest to use database or cache for storing events. For example, I'll use MemoryEventStorage.
    It will store snoozed events until script stop running., (*3)

  • Create event class that you want to save. You could extend EventDispatcher Event class, but if you want to specify additional data and/or priority, extend RealEvent class., (*4)

<?php

namespace MyApp;

use EventSnoozer\RealEvent;  

class MyEvent extends RealEvent
{
    const NAME = 'my.event';
}
  • Instantiate EventSnoozer class and use it for saving events.
<?php

namespace MyApp;

use EventSnoozer\EventStorage\MemoryEventStorage;
use EventSnoozer\EventSnoozer;
use MyApp\MyEvent;
use Symfony\Component\EventDispatcher\EventDispatcher;

$eventStorage = new MemoryEventStorage();
$eventDispatcher = new EventDispatcher();
// Add listeners/subscribers for your events

$eventSnoozer = new EventSnoozer($eventDispatcher, $eventStorage);

$event = new MyEvent();
$event->setPriority(10)
    ->setAdditionalData(array('data' => 'value'));

$eventSnoozer->snoozeEvent(MyEvent::NAME, $event, '+10 min');

  • Use EventSnoozer for dispatching saved events.
    MemoryEventStorage would select events ordered by priority and runtime.
<?php
namespace MyApp;

use EventSnoozer\EventStorage\MemoryEventStorage;
use EventSnoozer\EventSnoozer;
use Symfony\Component\EventDispatcher\EventDispatcher;

$eventStorage = new MemoryEventStorage();
$eventDispatcher = new EventDispatcher();
// Add listeners/subscribers for your events

$eventSnoozer = new EventSnoozer($eventDispatcher, $eventStorage);

$eventSnoozer->dispatchSnoozedEvent(); // For single event
$eventSnoozer->dispatchMultipleSnoozedEvents(5); // For multiple events

I suggest to use symfony/console for creating console commands and run it in background by cronjob., (*5)

The Versions

27/07 2017

dev-master

9999999-dev

Snooze your events for later dispatch.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Evgeny Vyatkin

27/07 2017

v2.x-dev

2.9999999.9999999.9999999-dev

Snooze your events for later dispatch.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Evgeny Vyatkin

27/07 2017

v2.0.0

2.0.0.0

Snooze your events for later dispatch.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Evgeny Vyatkin

04/04 2017

v1.x-dev

1.9999999.9999999.9999999-dev

Snooze your events for later dispatch.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Evgeny Vyatkin

29/03 2017

v1.2.0

1.2.0.0

Snooze your events for later dispatch.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Evgeny Vyatkin

29/03 2017

v1.1.2

1.1.2.0

Snooze your events for later dispatch.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Evgeny Vyatkin

29/03 2017

v1.1.1

1.1.1.0

Snooze your events for later dispatch.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Evgeny Vyatkin

29/03 2017

v1.1.0

1.1.0.0

Snooze your events for later dispatch.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Evgeny Vyatkin

29/03 2017

v1.0.0

1.0.0.0

Snooze your events for later dispatch.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Evgeny Vyatkin