Skip to content

Commit 04f4c74

Browse files
committed
Initial commit
1 parent c92416a commit 04f4c74

27 files changed

+1425
-1
lines changed

.docheader

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* This file is part of event-engine/php-messaging.
3+
* (c) 2018-%year% prooph software GmbH <contact@prooph.de>
4+
*
5+
* For the full copyright and license information, please view the LICENSE
6+
* file that was distributed with this source code.
7+
*/

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tests/ export-ignore

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.idea
2+
composer.lock
3+
vendor

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018-2019 prooph software GmbH
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# php-messaging
2-
Messaging for Event Engine
2+
3+
Event Engine Messaging PHP Package

composer.json

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"name": "event-engine/php-messaging",
3+
"description": "Event Engine Messaging PHP Package",
4+
"homepage": "https://event-engine.io/",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "Alexander Miertsch",
9+
"email": "contact@prooph.de",
10+
"homepage": "http://www.prooph.de"
11+
},
12+
{
13+
"name": "Sandro Keil",
14+
"email": "contact@prooph.de",
15+
"homepage": "http://prooph-software.com/"
16+
}
17+
],
18+
"require": {
19+
"php": "^7.2",
20+
"roave/security-advisories": "dev-master",
21+
"event-engine/php-schema": "dev-master",
22+
"event-engine/php-engine-utils": "dev-master",
23+
"ramsey/uuid" : "^3.6"
24+
},
25+
"require-dev": {
26+
"phpunit/phpunit": "^7.0",
27+
"prooph/php-cs-fixer-config": "^0.3",
28+
"satooshi/php-coveralls": "^1.0",
29+
"malukenho/docheader": "^0.1.4"
30+
},
31+
"autoload": {
32+
"psr-4": {
33+
"EventEngine\\Data\\": "src/"
34+
}
35+
},
36+
"autoload-dev": {
37+
"psr-4": {
38+
"EventEngineTest\\Data\\": "tests/"
39+
}
40+
},
41+
"prefer-stable": true,
42+
"scripts": {
43+
"check": [
44+
"@cs",
45+
"@docheader",
46+
"@test"
47+
],
48+
"docheader": "vendor/bin/docheader check examples/ src/ tests/",
49+
"cs": "php-cs-fixer fix -v --diff --dry-run",
50+
"cs-fix": "php-cs-fixer fix -v --diff",
51+
"test": "vendor/bin/phpunit"
52+
}
53+
}

phpunit.xml.dist

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
colors="true"
5+
convertErrorsToExceptions="true"
6+
convertNoticesToExceptions="true"
7+
convertWarningsToExceptions="true"
8+
processIsolation="false"
9+
stopOnFailure="false"
10+
bootstrap="vendor/autoload.php"
11+
>
12+
<testsuite name="prooph software Event Engine Test Suite">
13+
<directory>./tests/</directory>
14+
</testsuite>
15+
16+
<filter>
17+
<whitelist>
18+
<directory>./src/</directory>
19+
</whitelist>
20+
</filter>
21+
</phpunit>

src/Command.php

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
/**
3+
* This file is part of event-engine/php-messaging.
4+
* (c) 2018-2019 prooph software GmbH <contact@prooph.de>
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
declare(strict_types=1);
11+
12+
namespace EventEngine\Messaging;
13+
14+
interface Command extends Message
15+
{
16+
}

src/CommandDispatchResult.php

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
/**
3+
* This file is part of event-engine/php-messaging.
4+
* (c) 2018-2019 prooph software GmbH <contact@prooph.de>
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
declare(strict_types=1);
11+
12+
namespace EventEngine\Messaging;
13+
14+
final class CommandDispatchResult
15+
{
16+
/**
17+
* @var Message
18+
*/
19+
private $dispatchedCommand;
20+
21+
/**
22+
* @var string
23+
*/
24+
private $effectedAggregateId;
25+
26+
/**
27+
* @var Message[]
28+
*/
29+
private $recordedEvents;
30+
31+
public static function forCommandHandledByAggregate(Message $dispatchedCommand, string $effectedAggregateId, Message ...$recordedEvents): self
32+
{
33+
return new self($dispatchedCommand, $effectedAggregateId, ...$recordedEvents);
34+
}
35+
36+
public static function forCommandHandledByPreProcessor(Message $dispatchedCommand): self
37+
{
38+
return new self($dispatchedCommand);
39+
}
40+
41+
public static function forCommandHandledByController(Message $dispatedCommand): self
42+
{
43+
return new self($dispatedCommand);
44+
}
45+
46+
private function __construct(Message $dispatchedCommand, string $effectedAggregateId = null, Message ...$recordedEvents)
47+
{
48+
$this->dispatchedCommand = $dispatchedCommand;
49+
$this->effectedAggregateId = $effectedAggregateId;
50+
$this->recordedEvents = $recordedEvents;
51+
}
52+
53+
/**
54+
* @return Message
55+
*/
56+
public function dispatchedCommand(): Message
57+
{
58+
return $this->dispatchedCommand;
59+
}
60+
61+
/**
62+
* @return string|null
63+
*/
64+
public function effectedAggregateId(): ?string
65+
{
66+
return $this->effectedAggregateId;
67+
}
68+
69+
/**
70+
* @return Message[]
71+
*/
72+
public function recordedEvents(): array
73+
{
74+
return $this->recordedEvents;
75+
}
76+
}
+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
/**
3+
* This file is part of event-engine/php-messaging.
4+
* (c) 2018-2019 prooph software GmbH <contact@prooph.de>
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
declare(strict_types=1);
11+
12+
namespace EventEngine\Messaging;
13+
14+
use EventEngine\Messaging\Exception\RuntimeException;
15+
use EventEngine\Util\VariableType;
16+
17+
final class CommandDispatchResultCollection
18+
{
19+
/**
20+
* @var CommandDispatchResult[]
21+
*/
22+
private $results;
23+
24+
public function __construct(CommandDispatchResult ...$results)
25+
{
26+
$this->results = $results;
27+
}
28+
29+
public function toArray(): iterable
30+
{
31+
return $this->results;
32+
}
33+
34+
/**
35+
* @param CommandDispatchResult|CommandDispatchResultCollection $result
36+
* @return CommandDispatchResultCollection
37+
*/
38+
public function push($result): CommandDispatchResultCollection
39+
{
40+
$copy = clone $this;
41+
42+
if($result instanceof CommandDispatchResult) {
43+
$copy->results[] = $result;
44+
return $copy;
45+
}
46+
47+
if($result instanceof CommandDispatchResultCollection) {
48+
foreach ($result->toArray() as $item) {
49+
$copy->results[] = $item;
50+
}
51+
52+
return $copy;
53+
}
54+
55+
if(null === $result) {
56+
return $copy;
57+
}
58+
59+
throw new RuntimeException("Cannot push result to " . __CLASS__ . ". Got wrong type: " . VariableType::determine($result));
60+
}
61+
}

src/Event.php

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
/**
3+
* This file is part of event-engine/php-messaging.
4+
* (c) 2018-2019 prooph software GmbH <contact@prooph.de>
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
declare(strict_types=1);
11+
12+
namespace EventEngine\Messaging;
13+
14+
interface Event extends Message
15+
{
16+
}

src/Exception/MessageNotFound.php

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* This file is part of event-engine/php-messaging.
4+
* (c) 2018-2019 prooph software GmbH <contact@prooph.de>
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
declare(strict_types=1);
11+
12+
namespace EventEngine\Messaging\Exception;
13+
14+
use Throwable;
15+
16+
class MessageNotFound extends \RuntimeException implements MessagingException
17+
{
18+
public static function withMessageName(string $messageName): self
19+
{
20+
return new self("Unknown message $messageName");
21+
}
22+
23+
public function __construct(string $message = "", Throwable $previous = null)
24+
{
25+
parent::__construct($message, 404, $previous);
26+
}
27+
}

src/Exception/MessagingException.php

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
/**
3+
* This file is part of event-engine/php-messaging.
4+
* (c) 2018-2019 prooph software GmbH <contact@prooph.de>
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
declare(strict_types=1);
11+
12+
namespace EventEngine\Messaging\Exception;
13+
14+
interface MessagingException
15+
{
16+
}

src/Exception/RuntimeException.php

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/**
3+
* This file is part of event-engine/php-messaging.
4+
* (c) 2018-2019 prooph software GmbH <contact@prooph.de>
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
declare(strict_types=1);
11+
12+
namespace EventEngine\Messaging\Exception;
13+
14+
use Throwable;
15+
16+
class RuntimeException extends \RuntimeException implements MessagingException
17+
{
18+
public function __construct(string $message = "", Throwable $previous = null)
19+
{
20+
parent::__construct($message, 500, $previous);
21+
}
22+
}

0 commit comments

Comments
 (0)