-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
108 changed files
with
3,160 additions
and
3,371 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
$header = <<<EOF | ||
GpsLab component. | ||
@author Peter Gribanov <[email protected]> | ||
@copyright Copyright (c) 2016, Peter Gribanov | ||
@license http://opensource.org/licenses/MIT | ||
EOF; | ||
|
||
return PhpCsFixer\Config::create() | ||
->setRules([ | ||
'@Symfony' => true, | ||
'array_syntax' => [ | ||
'syntax' => 'short', | ||
], | ||
'header_comment' => [ | ||
'commentType' => 'PHPDoc', | ||
'header' => $header, | ||
], | ||
'class_definition' => [ | ||
'multiLineExtendsEachSingleLine' => true, | ||
], | ||
]) | ||
->setFinder( | ||
PhpCsFixer\Finder::create() | ||
->in(__DIR__.'/src') | ||
->in(__DIR__.'/tests') | ||
) | ||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
rules: | ||
php.interface_has_no_interface_suffix: | ||
enabled: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,6 @@ language: php | |
|
||
sudo: false | ||
|
||
php: | ||
- 7.1 | ||
- 7.0 | ||
- 5.6 | ||
- 5.5 | ||
|
||
notifications: | ||
email: [email protected] | ||
|
||
|
@@ -18,8 +12,10 @@ branches: | |
matrix: | ||
fast_finish: true | ||
include: | ||
- php: 7.1 | ||
- php: 7.0 | ||
- php: 5.6 | ||
- php: 5.5 | ||
env: COVERAGE=1 | ||
- php: 5.5 | ||
env: SYMFONY_VERSION=2.7.* | ||
- php: 5.5 | ||
|
@@ -30,24 +26,26 @@ matrix: | |
env: PREDIS_VERSION=1.0.* | ||
- php: 5.5 | ||
env: PREDIS_VERSION=1.1.* | ||
allow_failures: | ||
- php: 5.6 | ||
env: PUBSUB_PREDIS_VERSION=2.0.* | ||
- php: hhvm | ||
sudo: required | ||
dist: trusty | ||
group: edge | ||
|
||
before_install: | ||
- if [ "$TRAVIS_PHP_VERSION" != "hhvm" ] && [ "$COVERAGE" != "1" ]; then phpenv config-rm xdebug.ini; fi; | ||
- if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then echo "memory_limit=2G" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini; fi; | ||
- if [ "$TRAVIS_PHP_VERSION" = "hhvm" ]; then echo 'xdebug.enable = on' >> /etc/hhvm/php.ini; fi | ||
- if [ -n "$GH_TOKEN" ]; then composer config github-oauth.github.com ${GH_TOKEN}; fi; | ||
- composer self-update | ||
|
||
before_script: | ||
- if [ "$SYMFONY_VERSION" != "" ]; then composer require "symfony/symfony:${SYMFONY_VERSION}" --dev --no-update; fi; | ||
- if [ "$PREDIS_VERSION" != "" ]; then composer require "predis/predis:${PREDIS_VERSION}" --dev --no-update; fi; | ||
- if [ "$PUBSUB_PREDIS_VERSION" != "" ]; then composer require "superbalist/php-pubsub-redis:${PUBSUB_PREDIS_VERSION}" --dev --no-update; fi; | ||
- composer install --prefer-dist --no-interaction --no-scripts --no-progress | ||
|
||
script: | ||
- if [ "$COVERAGE" != "1" ]; then vendor/bin/phpunit; fi; | ||
- if [ "$COVERAGE" == "1" ]; then vendor/bin/phpunit --coverage-clover build/coverage-clover.xml; fi; | ||
- vendor/bin/phpunit --coverage-clover build/coverage-clover.xml | ||
|
||
after_script: | ||
- if [ "$COVERAGE" == "1" ]; then vendor/bin/ocular code-coverage:upload --format=php-clover build/coverage-clover.xml; fi; | ||
- if [ "$COVERAGE" == "1" ]; then vendor/bin/coveralls -v -c .coveralls.yml; fi; | ||
- vendor/bin/ocular code-coverage:upload --format=php-clover build/coverage-clover.xml | ||
- vendor/bin/coveralls -v -c .coveralls.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
[![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/gpslab/domain-event.svg?maxAge=3600)](https://scrutinizer-ci.com/g/gpslab/domain-event/?branch=master) | ||
[![SensioLabs Insight](https://img.shields.io/sensiolabs/i/9c7460e6-51b0-4cc3-9e4c-47066634017b.svg?maxAge=3600&label=SLInsight)](https://insight.sensiolabs.com/projects/9c7460e6-51b0-4cc3-9e4c-47066634017b) | ||
[![StyleCI](https://styleci.io/repos/69552555/shield?branch=master)](https://styleci.io/repos/69552555) | ||
[![License](https://img.shields.io/github/license/gpslab/domain-event.svg?maxAge=3600)](https://github.com/gpslab/domain-event) | ||
[![License](https://img.shields.io/packagist/l/gpslab/domain-event.svg?maxAge=3600)](https://github.com/gpslab/domain-event) | ||
|
||
Domain event | ||
============ | ||
|
@@ -25,28 +25,28 @@ composer require gpslab/domain-event | |
Create a domain event | ||
|
||
```php | ||
use GpsLab\Domain\Event\EventInterface; | ||
use GpsLab\Domain\Event\Event; | ||
|
||
final class PurchaseOrderCreatedEvent implements EventInterface | ||
final class PurchaseOrderCreatedEvent implements Event | ||
{ | ||
private $customer; | ||
private $customer_id; | ||
|
||
private $create_at; | ||
|
||
public function __construct(Customer $customer, \DateTimeImmutable $create_at) | ||
public function __construct(CustomerId $customer_id, \DateTimeImmutable $create_at) | ||
{ | ||
$this->customer = $customer; | ||
$this->customer_id = $customer_id; | ||
$this->create_at = $create_at; | ||
} | ||
|
||
public function getCustomer() | ||
public function customerId() | ||
{ | ||
return $this->customer; | ||
return $this->customer_id; | ||
} | ||
|
||
public function getCreateAt() | ||
public function createAt() | ||
{ | ||
return clone $this->create_at; | ||
return $this->create_at; | ||
} | ||
} | ||
``` | ||
|
@@ -58,30 +58,34 @@ use GpsLab\Domain\Event\Aggregator\AbstractAggregateEvents; | |
|
||
final class PurchaseOrder extends AbstractAggregateEventsRaiseInSelf | ||
{ | ||
private $customer; | ||
private $customer_id; | ||
|
||
private $create_at; | ||
|
||
public function __construct(Customer $customer) | ||
public function __construct(CustomerId $customer_id) | ||
{ | ||
$this->raise(new PurchaseOrderCreatedEvent($customer, new \DateTimeImmutable())); | ||
$this->raise(new PurchaseOrderCreatedEvent($customer_id, new \DateTimeImmutable())); | ||
} | ||
|
||
/** | ||
* The raise() method will automatically call this method. | ||
* Since it's an event you should never do some tests in this method. | ||
* Try to think that an Event is something that happened in the past. | ||
* You can not modify what happened. The only thing that you can do is create another event to compensate. | ||
* You do not obliged to listen this event and are not required to create this method. | ||
*/ | ||
protected function onPurchaseOrderCreated(PurchaseOrderCreatedEvent $event) | ||
{ | ||
$this->customer = $event->getCustomer(); | ||
$this->create_at = $event->getCreateAt(); | ||
$this->customer_id = $event->customerId(); | ||
$this->create_at = $event->createAt(); | ||
} | ||
} | ||
``` | ||
|
||
Create listener | ||
|
||
```php | ||
use GpsLab\Domain\Event\EventInterface; | ||
use GpsLab\Domain\Event\Listener\AbstractSwitchListener; | ||
|
||
class SendEmailOnPurchaseOrderCreated extends AbstractSwitchListener | ||
class SendEmailOnPurchaseOrderCreated | ||
{ | ||
private $mailer; | ||
|
||
|
@@ -90,12 +94,12 @@ class SendEmailOnPurchaseOrderCreated extends AbstractSwitchListener | |
$this->mailer = $mailer; | ||
} | ||
|
||
protected function handlePurchaseOrderCreated(PurchaseOrderCreatedEvent $event) | ||
public function __invoke(PurchaseOrderCreatedEvent $event) | ||
{ | ||
$this->mailer->send('[email protected]', sprintf( | ||
'Purchase order created at %s for customer #%s', | ||
$event->getCreateAt()->format('Y-m-d'), | ||
$event->getCustomer()->getId() | ||
$event->createAt()->format('Y-m-d'), | ||
$event->customerId() | ||
)); | ||
} | ||
} | ||
|
@@ -104,23 +108,19 @@ class SendEmailOnPurchaseOrderCreated extends AbstractSwitchListener | |
Dispatch events | ||
|
||
```php | ||
use GpsLab\Domain\Event\Listener\Locator\NamedEventLocator; | ||
use GpsLab\Domain\Event\NameResolver\EventClassLastPartResolver; | ||
use GpsLab\Domain\Event\Bus\Bus; | ||
|
||
// use last part of event class as event name | ||
$resolver = new EventClassLastPartResolver(); | ||
use GpsLab\Domain\Event\Bus\ListenerLocatedEventBus; | ||
use GpsLab\Domain\Event\Listener\Locator\DirectBindingEventListenerLocator; | ||
|
||
// first the locator | ||
$locator = new NamedEventLocator($resolver); | ||
$locator = new DirectBindingEventListenerLocator(); | ||
// you can use several listeners for one event and one listener for several events | ||
$locator->register('PurchaseOrderCreated', new SendEmailOnPurchaseOrderCreated(/* $mailer */)); | ||
$locator->register(PurchaseOrderCreatedEvent::class, new SendEmailOnPurchaseOrderCreated(/* $mailer */)); | ||
|
||
// then the event bus | ||
$bus = new EventBus($locator); | ||
$bus = new ListenerLocatedEventBus($locator); | ||
|
||
// do what you need to do on your Domain | ||
$purchase_order = new PurchaseOrder(new Customer(1)); | ||
$purchase_order = new PurchaseOrder(new CustomerId(1)); | ||
|
||
// this will clear the list of event in your AggregateEvents so an Event is trigger only once | ||
$bus->pullAndPublish($purchase_order); | ||
|
@@ -131,16 +131,23 @@ $bus->pullAndPublish($purchase_order); | |
* [Base usage](docs/base.md) | ||
* [Raise events in self](docs/raise_in_self.md) | ||
* Listener | ||
* [Switch listener](docs/listener/switch.md) | ||
* [Create listener](docs/listener.md) | ||
* Locator | ||
* [Voter locator](docs/listener/locator/voter.md) | ||
* [Event class locator](docs/listener/locator/event_class.md) | ||
* [Event class last part locator](docs/listener/locator/event_class_last_part.md) | ||
* [Named event locator](docs/listener/locator/named_event.md) | ||
* [Container aware locator](docs/listener/locator/container_aware.md) | ||
* Queue | ||
* [Direct binding locator](docs/listener/locator/direct_binding.md) | ||
* [PSR-11 Container locator](docs/listener/locator/psr-11_container.md) *([PSR-11](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-11-container.md))* | ||
* [Symfony container locator](docs/listener/locator/symfony_container.md) *(Symfony 3.3 [implements](http://symfony.com/blog/new-in-symfony-3-3-psr-11-containers) a [PSR-11](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-11-container.md))* | ||
* [Queue](docs/queue/queue.md) | ||
* [Queue event bus](docs/queue/bus.md) | ||
* [Queues](docs/queue/queues.md) | ||
* [Pull](docs/queue/pull/pull.md) | ||
* [Memory queue](docs/queue/pull/memory.md) | ||
* [Predis queue](docs/queue/pull/predis.md) | ||
* [Subscribe](docs/queue/subscribe/subscribe.md) | ||
* [Executing queue](docs/queue/subscribe/executing.md) | ||
* [Predis queue](docs/queue/subscribe/predis.md) | ||
* Serialize command | ||
* [Simple payload serializer](docs/queue/serialize/simple.md) | ||
* [Optimized Symfony serializer](docs/queue/serialize/optimized.md) | ||
* [Payload Symfony serializer](docs/queue/serialize/payload.md) | ||
* Frameworks | ||
* [Symfony bundle](https://github.com/gpslab/domain-event-bundle) | ||
* [Middleware](https://github.com/gpslab/middleware) | ||
|
Oops, something went wrong.