Skip to content

Commit 4b3b554

Browse files
committed
Async event dispatcher pkg.
1 parent 4acb30b commit 4b3b554

33 files changed

+296
-47
lines changed

composer.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"enqueue/job-queue": "*@dev",
2020
"enqueue/simple-client": "*@dev",
2121
"enqueue/test": "*@dev",
22+
"enqueue/async-event-dispatcher": "*@dev",
2223

2324
"phpunit/phpunit": "^5",
2425
"doctrine/doctrine-bundle": "~1.2",
@@ -98,6 +99,10 @@
9899
{
99100
"type": "path",
100101
"url": "pkg/simple-client"
102+
},
103+
{
104+
"type": "path",
105+
"url": "pkg/async-event-dispatcher"
101106
}
102107
]
103108
}

docs/bundle/async_events.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ You can also add an async listener directly and register a custom message proces
6666
6767
services:
6868
acme.async_foo_listener:
69-
class: 'Enqueue\Bundle\Events\AsyncListener'
69+
class: 'Enqueue\AsyncEventDispatcher\AsyncListener'
7070
public: false
7171
arguments: ['@enqueue.client.producer', '@enqueue.events.registry']
7272
tags:
@@ -78,7 +78,7 @@ The message processor must subscribe to `event.foo` topic. The message queue top
7878
```php
7979
<?php
8080
81-
use Enqueue\Bundle\Events\Registry;
81+
use Enqueue\AsyncEventDispatcher\Registry;
8282
use Enqueue\Client\TopicSubscriberInterface;
8383
use Enqueue\Psr\PsrContext;
8484
use Enqueue\Psr\PsrMessage;
@@ -126,7 +126,7 @@ class FooEventProcessor implements PsrProcessor, TopicSubscriberInterface
126126
## Event transformer
127127

128128
The bundle uses [php serializer](https://github.com/php-enqueue/enqueue-dev/blob/master/pkg/enqueue-bundle/Events/PhpSerializerEventTransformer.php) transformer by default to pass events through MQ.
129-
You could create a transformer for the given event type. The transformer must implement `Enqueue\Bundle\Events\EventTransformer` interface.
129+
You could create a transformer for the given event type. The transformer must implement `Enqueue\AsyncEventDispatcher\EventTransformer` interface.
130130
Consider the next example. It shows how to send an event that contains Doctrine entity as a subject
131131

132132
```php
@@ -140,7 +140,7 @@ use Enqueue\Consumption\Result;
140140
use Enqueue\Psr\PsrMessage;
141141
use Enqueue\Util\JSON;
142142
use Symfony\Component\EventDispatcher\Event;
143-
use Enqueue\Bundle\Events\EventTransformer;
143+
use Enqueue\AsyncEventDispatcher\EventTransformer;
144144
use Doctrine\Bundle\DoctrineBundle\Registry;
145145
use Symfony\Component\EventDispatcher\GenericEvent;
146146

phpunit.xml.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@
6868
<testsuite name="simple-client">
6969
<directory>pkg/simple-client/Tests</directory>
7070
</testsuite>
71+
72+
<testsuite name="async-event-dispatcher">
73+
<directory>pkg/async-event-dispatcher/Tests</directory>
74+
</testsuite>
7175
</testsuites>
7276

7377
<filter>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*~
2+
/composer.lock
3+
/composer.phar
4+
/phpunit.xml
5+
/vendor/
6+
/.idea/
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
sudo: false
2+
3+
git:
4+
depth: 1
5+
6+
language: php
7+
8+
php:
9+
- '5.6'
10+
- '7.0'
11+
12+
cache:
13+
directories:
14+
- $HOME/.composer/cache
15+
16+
install:
17+
- composer self-update
18+
- composer install --prefer-source --ignore-platform-reqs
19+
20+
script:
21+
- vendor/bin/phpunit --exclude-group=functional

pkg/enqueue-bundle/Events/AsyncListener.php renamed to pkg/async-event-dispatcher/AsyncListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Enqueue\Bundle\Events;
3+
namespace Enqueue\AsyncEventDispatcher;
44

55
use Enqueue\Client\Message;
66
use Enqueue\Client\ProducerInterface;

pkg/enqueue-bundle/Events/AsyncProcessor.php renamed to pkg/async-event-dispatcher/AsyncProcessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Enqueue\Bundle\Events;
3+
namespace Enqueue\AsyncEventDispatcher;
44

55
use Enqueue\Consumption\Result;
66
use Enqueue\Psr\PsrContext;

pkg/enqueue-bundle/Events/ContainerAwareRegistry.php renamed to pkg/async-event-dispatcher/ContainerAwareRegistry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Enqueue\Bundle\Events;
3+
namespace Enqueue\AsyncEventDispatcher;
44

55
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
66
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Enqueue\AsyncEventDispatcher\DependencyInjection;
4+
5+
use Enqueue\AsyncEventDispatcher\OldProxyEventDispatcher;
6+
use Symfony\Component\Config\FileLocator;
7+
use Symfony\Component\DependencyInjection\ContainerBuilder;
8+
use Symfony\Component\DependencyInjection\Definition;
9+
use Symfony\Component\DependencyInjection\Extension\Extension;
10+
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
11+
use Symfony\Component\DependencyInjection\Reference;
12+
use Symfony\Component\HttpKernel\Kernel;
13+
14+
class AsyncEventDispatcherExtension extends Extension
15+
{
16+
/**
17+
* {@inheritdoc}
18+
*/
19+
public function load(array $configs, ContainerBuilder $container)
20+
{
21+
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
22+
$loader->load('services.yml');
23+
24+
if (version_compare(Kernel::VERSION, '3.3', '<')) {
25+
$container->setDefinition('enqueue.events.async_processor', new Definition(OldProxyEventDispatcher::class, [
26+
new Reference('service_container'),
27+
new Reference('enqueue.events.registry'),
28+
new Reference('enqueue.events.event_dispatcher'),
29+
]));
30+
}
31+
}
32+
}

pkg/enqueue-bundle/Events/DependencyInjection/AsyncEventsPass.php renamed to pkg/async-event-dispatcher/DependencyInjection/AsyncEventsPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Enqueue\Bundle\Events\DependencyInjection;
3+
namespace Enqueue\AsyncEventDispatcher\DependencyInjection;
44

55
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
66
use Symfony\Component\DependencyInjection\ContainerBuilder;

0 commit comments

Comments
 (0)