Skip to content

Commit

Permalink
Move to packages/ dir
Browse files Browse the repository at this point in the history
  • Loading branch information
cmodijk committed Dec 13, 2020
0 parents commit f8e85d0
Show file tree
Hide file tree
Showing 63 changed files with 2,524 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/.gitattributes export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
/phpunit.xml export-ignore
/phpunit.xml.dist export-ignore
/composer.lock export-ignore
/tests export-ignore
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
vendor/
phpunit.xml
.couscous/
composer.lock
/build/
31 changes: 31 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
sudo: false

language: php

cache:
directories:
- $HOME/.composer/cache/files

matrix:
fast_finish: true
include:
- php: 7.3
- php: 7.3
env: COMPOSER_FLAGS="--prefer-lowest"
- php: 7.4
- php: 7.4
env: COMPOSER_FLAGS="--prefer-lowest"

env:
global:
- COMPOSER_FLAGS=""
- EXTRA_PHPUNIT_PARAMS=""

before_install:
- composer self-update

install:
- composer update --prefer-dist $COMPOSER_FLAGS

script:
- ./vendor/bin/phpunit $EXTRA_PHPUNIT_PARAMS
34 changes: 34 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Change log

## [Unreleased]

_None yet._

## [1.1.0] - 27-02-2015

### Added

- Added a message bus middleware for logging messages.
- Added a change log.

## [1.0.2] - 20-01-2015

- When an exception occurs in a message handler/subscriber, recorded messages (e.g. events) will now be erased.

## [1.0.1] - 20-01-2015

### Changed

- When an exception occurs in a message handler/subscriber, the command bus will no longer be locked.

## 1.0.0 - 19-01-2015

### Added

- Import of classes and interfaces from SimpleBus/CommandBus and SimpleBus/EventBus 1.0
- This library applies generically to all kinds of messages.

[Unreleased]: https://github.com/SimpleBus/MessageBus/compare/v1.1.0...HEAD
[1.1.0]: https://github.com/SimpleBus/MessageBus/compare/v1.0.2...v1.1.0
[1.0.2]: https://github.com/SimpleBus/MessageBus/compare/v1.0.1...v1.0.2
[1.0.1]: https://github.com/SimpleBus/MessageBus/compare/v1.0.0...v1.0.1
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2015-2018 Matthias Noback, Cliff Odijk, Ruud Kamphuis

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# SimpleBus/MessageBus

[![Build Status](https://travis-ci.org/SimpleBus/MessageBus.svg?branch=master)](https://travis-ci.org/SimpleBus/MessageBus)

By [Matthias Noback](http://php-and-symfony.matthiasnoback.nl/), Cliff Odijk, Ruud Kamphuis

This package contains generic classes and interfaces which can be used to create message buses, like a [command
bus](https://simplebus.github.io/MessageBus/doc/command_bus.html) or an [event
bus](https://simplebus.github.io/MessageBus/doc/event_bus.html).

Resources
---------

* [Report issues](https://github.com/SimpleBus/SimpleBus/issues) and
[send Pull Requests](https://github.com/SimpleBus/SimpleBus/pulls)
in the [main SimpleBus repository](https://github.com/SimpleBus/SimpleBus)
49 changes: 49 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"name": "simple-bus/message-bus",
"type": "library",
"description": "Generic classes and interfaces for messages and message buses",
"keywords": [
"message",
"message bus",
"event bus",
"command bus"
],
"homepage": "http://github.com/SimpleBus/MessageBus",
"license": "MIT",
"authors": [
{
"name": "Cliff Odijk",
"email": "cliff@jcid.nl"
},
{
"name": "Ruud Kamphuis",
"homepage": "https://github.com/ruudk"
},
{
"name": "Matthias Noback",
"email": "matthiasnoback@gmail.com",
"homepage": "http://php-and-symfony.matthiasnoback.nl"
}
],
"require": {
"php": "^7.3",
"beberlei/assert": "^3.0",
"psr/log": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^8.5"
},
"autoload": {
"psr-4": {
"SimpleBus\\Message\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"SimpleBus\\Message\\Tests\\": "tests"
}
},
"config": {
"sort-packages": true
}
}
35 changes: 35 additions & 0 deletions couscous.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
title: SimpleBus/MessageBus
subTitle: Generic classes and interfaces for command and event buses
baseUrl: //simplebus.github.io/MessageBus
menu:
items:
home:
itemId: home
text: Home
relativeUrl: ""
getting_started:
itemId: getting_started
text: Getting started
relativeUrl: doc/getting_started.html
command_bus:
itemId: command_bus
text: Command bus
relativeUrl: doc/command_bus.html
event_bus:
itemId: event_bus
text: Event bus
relativeUrl: doc/event_bus.html
message_recorder:
itemId: message_recorder
text: Recording events
relativeUrl: doc/message_recorder.html
upgrade_guide:
itemId: upgrade_guide
text: Upgrade guide
relativeUrl: doc/upgrade_guide.html
doctrine_orm_integration:
text: Doctrine ORM integration
absoluteUrl: http://simplebus.github.io/DoctrineORMBridge/
symfony_integration:
text: Symfony integration
absoluteUrl: http://simplebus.github.io/SymfonyBridge/
29 changes: 29 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="tests/bootstrap.php"
failOnRisky="true"
failOnWarning="true"
>
<php>
<ini name="error_reporting" value="-1" />
<ini name="intl.default_locale" value="en" />
<ini name="intl.error_level" value="0" />
<ini name="memory_limit" value="-1" />
</php>

<testsuites>
<testsuite name="Everything">
<directory>./tests/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>./src</directory>
</whitelist>
</filter>
</phpunit>
12 changes: 12 additions & 0 deletions src/Bus/MessageBus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace SimpleBus\Message\Bus;

interface MessageBus
{
/**
* @param object $message
* @return void
*/
public function handle($message);
}
45 changes: 45 additions & 0 deletions src/Bus/Middleware/FinishesHandlingMessageBeforeHandlingNext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace SimpleBus\Message\Bus\Middleware;

use Throwable;

class FinishesHandlingMessageBeforeHandlingNext implements MessageBusMiddleware
{
/**
* @var array
*/
private $queue = [];

/**
* @var bool
*/
private $isHandling = false;

/**
* Completely finishes handling the current message, before allowing other middlewares to start handling new
* messages.
*
* {@inheritdoc}
*/
public function handle($message, callable $next)
{
$this->queue[] = $message;

if (!$this->isHandling) {
$this->isHandling = true;

while ($message = array_shift($this->queue)) {
try {
$next($message);
} catch (Throwable $exception) {
$this->isHandling = false;

throw $exception;
}
}

$this->isHandling = false;
}
}
}
16 changes: 16 additions & 0 deletions src/Bus/Middleware/MessageBusMiddleware.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace SimpleBus\Message\Bus\Middleware;

interface MessageBusMiddleware
{
/**
* The provided $next callable should be called whenever the next middleware should start handling the message.
* Its only argument should be a Message object (usually the same as the originally provided message).
*
* @param object $message
* @param callable $next
* @return void
*/
public function handle($message, callable $next);
}
74 changes: 74 additions & 0 deletions src/Bus/Middleware/MessageBusSupportingMiddleware.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace SimpleBus\Message\Bus\Middleware;

use SimpleBus\Message\Bus\MessageBus;

class MessageBusSupportingMiddleware implements MessageBus
{
/**
* @var MessageBusMiddleware[]
*/
private $middlewares = [];

public function __construct(array $middlewares = [])
{
foreach ($middlewares as $middleware) {
$this->appendMiddleware($middleware);
}
}

/**
* Appends new middleware for this message bus. Should only be used at configuration time.
*
* @private
* @param MessageBusMiddleware $middleware
* @return void
*/
public function appendMiddleware(MessageBusMiddleware $middleware)
{
$this->middlewares[] = $middleware;
}

/**
* Returns a list of middlewares. Should only be used for introspection.
*
* @private
* @return array<MessageBusMiddleware>
*/
public function getMiddlewares()
{
return $this->middlewares;
}

/**
* Prepends new middleware for this message bus. Should only be used at configuration time.
*
* @private
* @param MessageBusMiddleware $middleware
* @return void
*/
public function prependMiddleware(MessageBusMiddleware $middleware)
{
array_unshift($this->middlewares, $middleware);
}

public function handle($message)
{
call_user_func($this->callableForNextMiddleware(0), $message);
}

private function callableForNextMiddleware($index)
{
if (!isset($this->middlewares[$index])) {
return function () {
};
}

$middleware = $this->middlewares[$index];

return function ($message) use ($middleware, $index) {
$middleware->handle($message, $this->callableForNextMiddleware($index + 1));
};
}
}
Loading

0 comments on commit f8e85d0

Please sign in to comment.