├── CHANGELOG.md ├── LICENSE ├── README.md ├── composer.json └── src ├── QueueAllMiddleware.php ├── QueueCommand.php ├── QueueCommandNormalizer.php ├── QueueMiddleware.php ├── QueueableCommand.php ├── QueuedCommand.php ├── Receiver.php └── Receiver ├── SameBusReceiver.php └── SeparateBusReceiver.php /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | 4 | ## 0.6.0 - 2016-10-30 5 | 6 | ### Added 7 | 8 | - QueueAllMiddleware to allow queueing any command 9 | - QueueCommandNormalizer to normalize the QueueCommand wrapper 10 | 11 | 12 | ## 0.5.0 - 2015-12-31 13 | 14 | ### Changed 15 | 16 | - Updated dependencies to Tactician 1.0 17 | 18 | 19 | ## 0.4.1 - 2015-06-05 20 | 21 | ### Added 22 | 23 | - `QueueableCommand` interface to ease registering receivers in Bernard routers 24 | - `QueueCommand` to ease passing commands to Bernard which does not implement `Bernard\Message` by wrapping them 25 | 26 | ### Changed 27 | 28 | - `QueuedCommand` is now final 29 | 30 | 31 | ## 0.4.0 - 2015-05-08 32 | 33 | ### Changed 34 | 35 | - Updated dependencies to Tactician 0.6 36 | 37 | 38 | ## 0.3.0 - 2015-03-30 39 | 40 | ### Changed 41 | 42 | - The `Command` interface from Tactician is no longer required 43 | 44 | ### Removed 45 | 46 | - `QueueableCommand` interface is not needed anymore 47 | 48 | 49 | ## 0.2.0 - 2015-03-17 50 | 51 | ### Added 52 | 53 | - `*BusReceivers` to be added to Bernard's core routers 54 | 55 | ### Changed 56 | 57 | - Use a `Producer` instead of a specific `Queue` (queue name can be guessed from the command) 58 | 59 | ### Removed 60 | 61 | - Custom `Router` implementation 62 | 63 | 64 | ## 0.1.0 - 2015-02-19 65 | 66 | ### Added 67 | 68 | - Initial release 69 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015-2016 Márk Sági-Kazár 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is furnished 8 | to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Tactician Bernard 2 | 3 | [![Author](http://img.shields.io/badge/author-@sagikazarmark-blue.svg?style=flat-square)](https://twitter.com/sagikazarmark) 4 | [![Latest Version](https://img.shields.io/github/release/thephpleague/tactician-bernard.svg?style=flat-square)](https://github.com/thephpleague/tactician-bernard/releases) 5 | [![Build Status](https://img.shields.io/travis/thephpleague/tactician-bernard.svg?style=flat-square)](https://travis-ci.org/thephpleague/tactician-bernard) 6 | [![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/thephpleague/tactician-bernard.svg?style=flat-square)](https://scrutinizer-ci.com/g/thephpleague/tactician-bernard) 7 | [![Quality Score](https://img.shields.io/scrutinizer/g/thephpleague/tactician-bernard.svg?style=flat-square)](https://scrutinizer-ci.com/g/thephpleague/tactician-bernard) 8 | [![Total Downloads](https://img.shields.io/packagist/dt/league/tactician-bernard.svg?style=flat-square)](https://packagist.org/packages/league/tactician-bernard) 9 | 10 | **Queueing command bus plugin for [Tactician](http://tactician.thephpleague.com) based on [Bernard](https://bernard.readthedocs.io).** 11 | 12 | 13 | ## Install 14 | 15 | Via Composer 16 | 17 | ``` bash 18 | $ composer require league/tactician-bernard 19 | ``` 20 | 21 | 22 | ## Usage 23 | 24 | Documentation is available on the [official website](http://tactician.thephpleague.com/plugins/bernard/). 25 | 26 | 27 | ## Testing 28 | 29 | ``` bash 30 | $ composer test 31 | ``` 32 | 33 | 34 | ## Contributing 35 | 36 | Contributing information can be found in [the main Tactician repo](https://github.com/thephpleague/tactician#contributing). 37 | 38 | 39 | ## Security 40 | 41 | Disclosure information can be found in [the main Tactician repo](https://github.com/thephpleague/tactician#security). 42 | 43 | 44 | ## Credits 45 | 46 | - [Márk Sági-Kazár](https://github.com/sagikazarmark) 47 | - [Ross Tuck](https://github.com/rosstuck) 48 | - [All Contributors](https://github.com/thephpleague/tactician-bernard/contributors) 49 | 50 | 51 | ## License 52 | 53 | The MIT License (MIT). Please see [License File](LICENSE) for more information. 54 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "league/tactician-bernard", 3 | "description": "Queueing command bus plugin for Tactician based on Bernard", 4 | "license": "MIT", 5 | "keywords": ["bernard", "tactician", "command-bus", "message queue"], 6 | "homepage": "http://tactician.thephpleague.com", 7 | "authors": [ 8 | { 9 | "name": "Márk Sági-Kazár", 10 | "email": "mark.sagikazar@gmail.com" 11 | } 12 | ], 13 | "require": { 14 | "bernard/bernard": "^1.0@dev", 15 | "beberlei/assert": "^2.1", 16 | "league/tactician": "^1.0" 17 | }, 18 | "require-dev": { 19 | "phpspec/phpspec": "^2.5", 20 | "henrikbjorn/phpspec-code-coverage": "^2.0" 21 | }, 22 | "autoload": { 23 | "psr-4": { 24 | "League\\Tactician\\Bernard\\": "src/" 25 | } 26 | }, 27 | "autoload-dev": { 28 | "psr-4": { 29 | "spec\\League\\Tactician\\Bernard\\": "spec/" 30 | } 31 | }, 32 | "scripts": { 33 | "test": "vendor/bin/phpspec run", 34 | "test-ci": "vendor/bin/phpspec run -c phpspec.ci.yml" 35 | }, 36 | "extra": { 37 | "branch-alias": { 38 | "dev-master": "0.7-dev" 39 | } 40 | }, 41 | "prefer-stable": true, 42 | "minimum-stability": "dev" 43 | } 44 | -------------------------------------------------------------------------------- /src/QueueAllMiddleware.php: -------------------------------------------------------------------------------- 1 | command = $command; 27 | 28 | if (is_null($name)) { 29 | $className = get_class($command); 30 | $name = substr($className, strrpos($className, '\\') + 1); 31 | } 32 | 33 | $this->name = $name; 34 | } 35 | 36 | /** 37 | * Returns the wrapped command 38 | * 39 | * @return object 40 | */ 41 | public function getCommand() 42 | { 43 | return $this->command; 44 | } 45 | 46 | /** 47 | * {@inheritdoc} 48 | */ 49 | public function getName() 50 | { 51 | return $this->name; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/QueueCommandNormalizer.php: -------------------------------------------------------------------------------- 1 | get_class($object->getCommand()), 19 | 'name' => $object->getName(), 20 | 'data' => $this->aggregate->normalize($object->getCommand()), 21 | ]; 22 | } 23 | 24 | /** 25 | * {@inheritdoc} 26 | */ 27 | public function supportsNormalization($data, $format = null) 28 | { 29 | return $data instanceof QueueCommand; 30 | } 31 | 32 | /** 33 | * {@inheritdoc} 34 | */ 35 | public function denormalize($data, $class, $format = null, array $context = []) 36 | { 37 | Assertion::choicesNotEmpty($data, ['class', 'name', 'data']); 38 | 39 | Assertion::classExists($data['class']); 40 | 41 | $object = new QueueCommand($this->aggregate->denormalize($data['data'], $data['class']), $data['name']); 42 | 43 | return $object; 44 | } 45 | 46 | /** 47 | * {@inheritdoc} 48 | */ 49 | public function supportsDenormalization($data, $type, $format = null) 50 | { 51 | return $type === QueueCommand::class; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/QueueMiddleware.php: -------------------------------------------------------------------------------- 1 | producer = $producer; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | public function execute($command, callable $next) 32 | { 33 | if ($command instanceof Message) { 34 | $this->producer->produce($command); 35 | 36 | return; 37 | } 38 | 39 | if ($command instanceof QueuedCommand) { 40 | $command = $command->getCommand(); 41 | } 42 | 43 | if ($command instanceof QueueCommand) { 44 | $command = $command->getCommand(); 45 | } 46 | 47 | return $next($command); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/QueueableCommand.php: -------------------------------------------------------------------------------- 1 | command = $command; 23 | } 24 | 25 | /** 26 | * Returns the wrapped command 27 | * 28 | * @return Message 29 | */ 30 | public function getCommand() 31 | { 32 | return $this->command; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Receiver.php: -------------------------------------------------------------------------------- 1 | commandBus = $commandBus; 24 | } 25 | 26 | /** 27 | * Handles the message 28 | * 29 | * @param Message $message 30 | */ 31 | abstract public function handle(Message $message); 32 | 33 | /** 34 | * Makes the receiver callable to be able to register it in a router 35 | * 36 | * @param Message $message 37 | * 38 | * @return mixed 39 | */ 40 | public function __invoke(Message $message) 41 | { 42 | return $this->handle($message); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Receiver/SameBusReceiver.php: -------------------------------------------------------------------------------- 1 | commandBus->handle($queuedCommand); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Receiver/SeparateBusReceiver.php: -------------------------------------------------------------------------------- 1 | commandBus->handle($message); 19 | } 20 | } 21 | --------------------------------------------------------------------------------