2017 © Pedro Peláez
 

library action-chain

Action chain helper classes for implementing commands

image

kampernet/action-chain

Action chain helper classes for implementing commands

  • Friday, April 22, 2016
  • by kampernet
  • Repository
  • 1 Watchers
  • 0 Stars
  • 84 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Kampernet Actions

This is a simple, dependency free implementation of the Command Pattern in PHP. Useful for creating an orchestration layer, (*1)

Usage

This will create a group of Commands with a certain name., (*2)

    class RegisterAction extends ActionChain {

        public function __construct() {
            $this->add(new RegisterUserAction());
            $this->add(new SendWelcomeEmailAction());
        }

    }

These are the individual command examples, (*3)

    class RegisterUserAction extends Command {

        private $request;
        private $response;

        public function execute($request, $response = null) {

            $this->request = $request;
            $this->response = $response;

            // eg: code to take the request data and persist the user
            // probably more likely to call a service or domain model method here.
        }

        public function undo() {

            // eg: code to "undo" anything this command would have done
        }
    }

Once your commands are built, you can just call them from the routes: ( example using Symfony's Request ), (*4)

    Route::get('/register', function() {

        $response = new Response();
        $reg = new RegisterAction();
        if (!$reg->execute(Request::createFromGlobals(), $response)) {
            $reg->undo();
        }

        return $response;
    });

The Versions

22/04 2016

dev-master

9999999-dev

Action chain helper classes for implementing commands

  Sources   Download

by Cookie Delicious

22/04 2016

1.0.1

1.0.1.0

Action chain helper classes for implementing commands

  Sources   Download

by Cookie Delicious

11/06 2014

v1.0

1.0.0.0

Action chain helper classes for implementing commands

  Sources   Download

by Cookie Delicious