Skip to content

Add support for Symfony 6; drop < 5.1 #1239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,13 @@ jobs:
fail-fast: false
matrix:
php: ['7.3', '7.4', '8.0']
symfony_version: ['4.4.*', '5.2.*']
symfony_version: ['5.2.*', '6.0.*']
dependencies: ['--prefer-lowest', '--prefer-dist']
exclude:
- php: '8.0'
symfony_version: '4.4.*'
- php: '7.3'
symfony_version: '6.0.*'
- php: '7.4'
symfony_version: '6.0.*'

name: PHP ${{ matrix.php }} unit tests on Sf ${{ matrix.symfony_version }}, deps=${{ matrix.dependencies }}

Expand Down Expand Up @@ -122,12 +124,14 @@ jobs:
fail-fast: false
matrix:
php: ['7.4', '8.0'] # same as in the container
symfony_version: ['4.4.*', '5.2.*']
symfony_version: ['5.2.*', '6.0.*']
dependencies: ['--prefer-lowest', '--prefer-dist']
rdkafka_action: ['exclude-group', 'group']
exclude:
- php: '8.0'
symfony_version: '4.4.*'
- php: '7.3'
symfony_version: '6.0.*'
- php: '7.4'
symfony_version: '6.0.*'

name: PHP ${{ matrix.php }} functional tests on Sf ${{ matrix.symfony_version }}, rdkafka_action=${{ matrix.rdkafka_action }}, deps=${{ matrix.dependencies }}

Expand Down
12 changes: 8 additions & 4 deletions .php_cs.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
<?php

return PhpCsFixer\Config::create()
return (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules(array(
'@Symfony' => true,
'@Symfony:risky' => true,
'array_syntax' => array('syntax' => 'short'),
'combine_consecutive_unsets' => true,
// one should use PHPUnit methods to set up expected exception instead of annotations
'general_phpdoc_annotation_remove' => array('expectedException', 'expectedExceptionMessage', 'expectedExceptionMessageRegExp'),
'general_phpdoc_annotation_remove' => ['annotations' =>
['expectedException', 'expectedExceptionMessage', 'expectedExceptionMessageRegExp']
],
'heredoc_to_nowdoc' => true,
'no_extra_consecutive_blank_lines' => array('break', 'continue', 'extra', 'return', 'throw', 'use', 'parenthesis_brace_block', 'square_brace_block', 'curly_brace_block'),
'no_extra_blank_lines' => ['tokens' => [
'break', 'continue', 'extra', 'return', 'throw', 'use', 'parenthesis_brace_block', 'square_brace_block', 'curly_brace_block']
],
'no_unreachable_default_argument_value' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'ordered_class_elements' => true,
'ordered_imports' => true,
'phpdoc_add_missing_param_annotation' => true,
'phpdoc_order' => true,
'psr4' => true,
'psr_autoloading' => true,
'strict_param' => true,
'native_function_invocation' => false,
))
Expand Down
29 changes: 15 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"doctrine/dbal": "^2.12|^3.1",
"ramsey/uuid": "^3.5|^4",
"psr/log": "^1.1 || ^2.0 || ^3.0",
"psr/container": "^1 || ^2.0",
"psr/container": "^1.1 || ^2.0",
"makasim/temp-file": "^0.2",
"google/cloud-pubsub": "^1.4.3",
"doctrine/orm": "^2.7.4",
Expand Down Expand Up @@ -53,23 +53,23 @@
"phpunit/phpunit": "^9.5",
"phpstan/phpstan": "^0.12",
"queue-interop/queue-spec": "^0.6.2",
"symfony/browser-kit": "^4.3|^5",
"symfony/config": "^4.3|^5",
"symfony/process": "^4.3|^5",
"symfony/console": "^4.3|^5",
"symfony/dependency-injection": "^4.3|^5",
"symfony/event-dispatcher": "^4.3|^5",
"symfony/expression-language": "^4.3|^5",
"symfony/http-kernel": "^4.3|^5",
"symfony/filesystem": "^4.3|^5",
"symfony/framework-bundle": "^4.3|^5",
"symfony/yaml": "^4.3|^5",
"symfony/browser-kit": "^5.1|^6.0",
"symfony/config": "^5.1|^6.0",
"symfony/process": "^5.1|^6.0",
"symfony/console": "^5.1|^6.0",
"symfony/dependency-injection": "^5.1|^6.0",
"symfony/event-dispatcher": "^5.1|^6.0",
"symfony/expression-language": "^5.1|^6.0",
"symfony/http-kernel": "^5.1|^6.0",
"symfony/filesystem": "^5.1|^6.0",
"symfony/framework-bundle": "^5.1|^6.0",
"symfony/yaml": "^5.1|^6.0",
"empi89/php-amqp-stubs": "*@dev",
"doctrine/doctrine-bundle": "^2.0",
"doctrine/mongodb-odm-bundle": "^3.5|^4.3",
"alcaeus/mongo-php-adapter": "^1.0",
"kwn/php-rdkafka-stubs": "^2.0.3",
"friendsofphp/php-cs-fixer": "^2",
"friendsofphp/php-cs-fixer": "^3.4",
"dms/phpunit-arraysubset-asserts": "^0.2.1",
"phpspec/prophecy-phpunit": "^2.0"
},
Expand Down Expand Up @@ -127,7 +127,8 @@
"ext-mongodb": "1.5",
"ext-bcmath": "1",
"ext-mbstring": "1",
"ext-mongo": "1.6.14"
"ext-mongo": "1.6.14",
"ext-sockets": "1"
},
"prefer-stable": true
}
Expand Down
8 changes: 4 additions & 4 deletions docs/bundle/async_events.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ enqueue:

## Usage

To make your listener async you have add `async: true` attribute to the tag `kernel.event_listener`, like this:
To make your listener async you have add `async: true` and `dispatcher: 'enqueue.events.event_dispatcher'` attributes to the tag `kernel.event_listener`, like this:

```yaml
# app/config/config.yml
Expand All @@ -48,7 +48,7 @@ services:
acme.foo_listener:
class: 'AcmeBundle\Listener\FooListener'
tags:
- { name: 'kernel.event_listener', async: true, event: 'foo', method: 'onEvent' }
- { name: 'kernel.event_listener', async: true, event: 'foo', method: 'onEvent', dispatcher: 'enqueue.events.event_dispatcher' }
```

or to `kernel.event_subscriber`:
Expand All @@ -60,7 +60,7 @@ services:
test_async_subscriber:
class: 'AcmeBundle\Listener\TestAsyncSubscriber'
tags:
- { name: 'kernel.event_subscriber', async: true }
- { name: 'kernel.event_subscriber', async: true, dispatcher: 'enqueue.events.event_dispatcher' }
```

That's basically it. The rest of the doc describes advanced features.
Expand All @@ -78,7 +78,7 @@ services:
public: false
arguments: ['@enqueue.transport.default.context', '@enqueue.events.registry', 'a_queue_name']
tags:
- { name: 'kernel.event_listener', event: 'foo', method: 'onEvent' }
- { name: 'kernel.event_listener', event: 'foo', method: 'onEvent', dispatcher: 'enqueue.events.event_dispatcher' }
```


Expand Down
16 changes: 8 additions & 8 deletions pkg/async-command/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
"php": "^7.3|^8.0",
"enqueue/enqueue": "^0.10",
"queue-interop/queue-interop": "^0.8",
"symfony/console": "^4.3|^5",
"symfony/process": "^4.3|^5"
"symfony/console": "^5.1|^6.0",
"symfony/process": "^5.1|^6.0"
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"symfony/dependency-injection": "^4.3|^5",
"symfony/config": "^4.3|^5",
"symfony/http-kernel": "^4.3|^5",
"symfony/filesystem": "^4.3|^5",
"symfony/yaml": "^4.3|^5",
"symfony/dependency-injection": "^5.1|^6.0",
"symfony/config": "^5.1|^6.0",
"symfony/http-kernel": "^5.1|^6.0",
"symfony/filesystem": "^5.1|^6.0",
"symfony/yaml": "^5.1|^6.0",
"enqueue/null": "0.10.x-dev",
"enqueue/fs": "0.10.x-dev",
"enqueue/test": "0.10.x-dev"
Expand All @@ -31,7 +31,7 @@
"docs": "https://github.com/php-enqueue/enqueue-dev/blob/master/docs/index.md"
},
"suggest": {
"symfony/dependency-injection": "^4.3|^5 If you'd like to use async event dispatcher container extension."
"symfony/dependency-injection": "^5.1|^6.0 If you'd like to use async event dispatcher container extension."
},
"autoload": {
"psr-4": { "Enqueue\\AsyncCommand\\": "" },
Expand Down
47 changes: 8 additions & 39 deletions pkg/async-event-dispatcher/AsyncEventDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,17 @@

namespace Enqueue\AsyncEventDispatcher;

use Symfony\Component\EventDispatcher\Event;

if (class_exists(Event::class)) {
/**
* Symfony < 5.0.
*/
class AsyncEventDispatcher extends AbstractAsyncEventDispatcher
class AsyncEventDispatcher extends AbstractAsyncEventDispatcher
{
public function dispatch(object $event, string $eventName = null): object
{
/**
* {@inheritdoc}
*/
public function dispatch($event, $eventName = null)
{
$this->parentDispatch($event, $eventName);

return $this->trueEventDispatcher->dispatch($event, $eventName);
}
$this->parentDispatch($event, $eventName);

protected function parentDispatch($event, $eventName)
{
parent::dispatch($event, $eventName);
}
return $this->trueEventDispatcher->dispatch($event, $eventName);
}
} else {
/**
* Symfony >= 5.0.
*/
class AsyncEventDispatcher extends AbstractAsyncEventDispatcher
{
/**
* {@inheritdoc}
*/
public function dispatch(object $event, string $eventName = null): object
{
$this->parentDispatch($event, $eventName);

return $this->trueEventDispatcher->dispatch($event, $eventName);
}

protected function parentDispatch($event, $eventName)
{
return parent::dispatch($event, $eventName);
}
protected function parentDispatch($event, $eventName)
{
return parent::dispatch($event, $eventName);
}
}
66 changes: 14 additions & 52 deletions pkg/async-event-dispatcher/AsyncListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,28 @@

namespace Enqueue\AsyncEventDispatcher;

use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event as ContractEvent;
use Symfony\Contracts\EventDispatcher\Event;

if (class_exists(Event::class)) {
/**
* Symfony < 5.0.
*/
class AsyncListener extends AbstractAsyncListener
class AsyncListener extends AbstractAsyncListener
{
public function __invoke(Event $event, $eventName)
{
/**
* @param Event|ContractEvent $event
* @param string $eventName
*/
public function __invoke($event, $eventName)
{
$this->onEvent($event, $eventName);
}

/**
* @param Event|ContractEvent $event
* @param string $eventName
*/
public function onEvent($event, $eventName)
{
if (false == isset($this->syncMode[$eventName])) {
$transformerName = $this->registry->getTransformerNameForEvent($eventName);

$message = $this->registry->getTransformer($transformerName)->toMessage($eventName, $event);
$message->setProperty('event_name', $eventName);
$message->setProperty('transformer_name', $transformerName);

$this->context->createProducer()->send($this->eventQueue, $message);
}
}
$this->onEvent($event, $eventName);
}
} else {

/**
* Symfony >= 5.0.
* @param string $eventName
*/
class AsyncListener extends AbstractAsyncListener
public function onEvent(Event $event, $eventName)
{
public function __invoke(ContractEvent $event, $eventName)
{
$this->onEvent($event, $eventName);
}

/**
* @param string $eventName
*/
public function onEvent(ContractEvent $event, $eventName)
{
if (false == isset($this->syncMode[$eventName])) {
$transformerName = $this->registry->getTransformerNameForEvent($eventName);
if (false == isset($this->syncMode[$eventName])) {
$transformerName = $this->registry->getTransformerNameForEvent($eventName);

$message = $this->registry->getTransformer($transformerName)->toMessage($eventName, $event);
$message->setProperty('event_name', $eventName);
$message->setProperty('transformer_name', $transformerName);
$message = $this->registry->getTransformer($transformerName)->toMessage($eventName, $event);
$message->setProperty('event_name', $eventName);
$message->setProperty('transformer_name', $transformerName);

$this->context->createProducer()->send($this->eventQueue, $message);
}
$this->context->createProducer()->send($this->eventQueue, $message);
}
}
}
Loading