Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mkgor/commando

Command patten implementation, Makes your application more flexible and expandable.
https://github.com/mkgor/commando

composer-package patterns php7

Last synced: 7 days ago
JSON representation

Command patten implementation, Makes your application more flexible and expandable.

Awesome Lists containing this project

README

        

# Commando
Commando is a simple implementation of \`Command\` pattern. It gives you simple to make your application
more flexible and expandable.

## Contents
- [Requirments](https://github.com/pixaye/commando#requirments)
- [Installation](https://github.com/pixaye/commando#installation)
- [Usage](https://github.com/pixaye/commando#usage)

## Requirments
The only requirement for now is a **PHP 7.1+**

## Installation
The easiest way of installation is an installtion via composer:

````
composer require pixaye/commando
````

## Usage

First of all, you should initialize and store **CommandBus** object

````php
new Handlers\SomeCommandHandler(),
Commands\SomeAnotherCommand::class => new Handlers\SomeAnotherCommandHandler()
]);

````

Then, to dispatch command, you should create command object and call **dispatch** method of bus

````php
new Handlers\RegisterNewUserCommandHandler(),
]);

//For example, we want to register new user
$registeredUser = $bus->dispatch(new Commands\RegisterNewUserCommand('John Doe', '1234567890'));
````

Command is a simple PHP class, which can contain some properties which handler should use to do some action.

````php
fullName;
}

/**
* @param mixed $fullName
*/
public function setFullName($fullName)
{
$this->fullName = $fullName;
}

/**
* @return mixed
*/
public function getPassword()
{
return $this->password;
}

/**
* @param mixed $password
*/
public function setPassword($password)
{
$this->password = $password;
}
}
````

It will call **RegisterNewUserCommandHandler**'s handle method and return it

**Important!** - All handlers should implement Commando\Handler\HandlerInterface and every command should implement Commando\Command\CommandInterface

````php
getFullName() . ' and password = ' . $command->getPassword() . ' has been created';
}
}
````