2017 © Pedro Peláez
 

library saga

Events and side effect handling with sagas for PHP.

image

zack/saga

Events and side effect handling with sagas for PHP.

  • Sunday, September 25, 2016
  • by lennerd
  • Repository
  • 1 Watchers
  • 9 Stars
  • 15 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 2 Open issues
  • 4 Versions
  • 15 % Grown

The README.md

Build Status Coverage Status, (*1)

Zack/Saga is a simple and easy to use library for event and side effects handling. Inspired by redux-saga it uses PHP generators and simple effect objects to create maintainable and easy to test processes and workflows., (*2)

Example

<?php

use Symfony\Component\EventDispatcher\EventDispatcher;
use Zack\Saga\Processor;
use Zack\Saga\SagaInterface;

class LoginSaga implements SagaInterface
{
    public function run(): \Generator
    {
        // Wait for the 'acme.user.login' event.
        $event = yield take('acme.user.login');

        // Get user from given ID.
        $user = UserProvider::find($event->getUserId());

        if ($user === null) {
            // Redirect to login page.
            yield dispatch('acme.router.redirect', new RedirectEvent('/login'));
            return;
        }

        // Create session.
        yield dispatch('acme.user.session', new UserSessionEvent($user));
        // Redirect to dashboard page.
        yield dispatch('acme.router.redirect', new RedirectEvent('/login'));

        // Fork saga for taking user logout event.
        yield fork(new LogoutSaga());
    }
}

$eventDispatcher = new EventDispatcher();

// Create a default Processor.
$processor = Processor::create($eventDispatcher);
$processor->run(new LoginSaga());

$eventDispatcher->dispatch('acme.user.login', new LoginEvent(1));

Installation

You can install this library via Composer:, (*3)

$ composer require zack/saga

The Versions

25/09 2016

dev-master

9999999-dev https://github.com/zackphp/saga

Events and side effect handling with sagas for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

saga

25/09 2016

v0.1.0

0.1.0.0 https://github.com/zackphp/saga

Events and side effect handling with sagas for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

saga

24/09 2016

v0.0.2

0.0.2.0 https://github.com/zackphp/saga

Events and side effect handling with sagas for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

saga

23/09 2016

v0.0.1

0.0.1.0 https://github.com/zackphp/saga

Events and side effect handling with sagas for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

saga