2017 © Pedro Peláez
 

library infrastructure

image

geggleto/infrastructure

  • Sunday, January 29, 2017
  • by geggleto
  • Repository
  • 1 Watchers
  • 3 Stars
  • 11 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

Command And Event Structure for Slim

Usage

In order to take advantage of the Command Bus and Event Bus, you will need to base your Controllers/Actions on the AbstractAction object, (*1)


public MyAction extends Infra\AbstractAction implements EventListenerInterface { protected $sent; public function __construct(CommandBus $bus) { parent::__construct($bus); $this->sent = false; //Register Our Action class as a listener for the SentEmailToUser Event $eventBus = $bus->getEventBus(); $eventBus->addListener(SentEmailToUser::NAME, $this); //We are waiting for the domain model to return to us wether the email was sent or not. //We do not care about anything else, except whether or not it was successful. } //In this action we will Queue and Email to be sent. public function __invoke(Request $request, Response $response, array $args = []) { $this->commandBus->handle(new SendEmailToUser()); //Return our response return $this->respond($response); } //We received the event mark it as a yes public function receiveEvent(SentEmailToUser $event) { $this->sent = true; } public function respond(Response $response) { if ($sent) { //Yes we did return $response->withJson(['message' => 'Sent Email to User']); } else { //No We did not. return $response->withJson(['message' => 'Sent Email to User'], 500); } } public function getCommands() { return []; //We are not queueing any other commands } public function getEvents() { return []; //We are not queuing any other events } }

The Versions

29/01 2017
29/01 2017
29/01 2017
29/01 2017
27/01 2017

0.0.1

0.0.1.0

  Sources   Download

MIT

The Requires

 

The Development Requires