Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/mkgor/commando
- Owner: mkgor
- License: mit
- Created: 2020-01-10T08:15:45.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-01-10T13:07:17.000Z (almost 5 years ago)
- Last Synced: 2024-04-19T20:22:55.166Z (7 months ago)
- Topics: composer-package, patterns, php7
- Language: PHP
- Homepage:
- Size: 10.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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';
}
}
````