Skip to content

Commit

Permalink
Merge pull request swarrot#232 from metfan/upgrade-symfony-support
Browse files Browse the repository at this point in the history
Add support to Symfony 7.0
  • Loading branch information
metfan authored Jan 4, 2024
2 parents f279dc3 + 4b1d176 commit bf97176
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 38 deletions.
18 changes: 13 additions & 5 deletions .github/workflows/unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [7.4, 8.0, 8.1]
symfony: [4.4.*, 5.4.*, 6.0.*]
php: [7.4, 8.0, 8.1, 8.2, 8.3]
symfony: [5.4.*, 6.4.*, 7.0.*]
exclude:
- php: 7.4
symfony: 6.0.*
symfony: 6.4.*
- php: 7.4
symfony: 7.0.*
- php: 8.0
symfony: 6.4.*
- php: 8.0
symfony: 7.0.*
- php: 8.1
symfony: 7.0.*

services:
rabbitmq:
Expand All @@ -28,10 +36,10 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@2.16.0
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: amqp
Expand Down
21 changes: 6 additions & 15 deletions Broker/Publisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
use Psr\Log\NullLogger;
use Swarrot\Broker\Message;
use Swarrot\SwarrotBundle\Event\MessagePublishedEvent;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface as ContractsEventDispatcherInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;

class Publisher
{
/** @var FactoryInterface */
protected $factory;
/** @var ContractsEventDispatcherInterface|EventDispatcherInterface */
/** @var EventDispatcherInterface */
protected $eventDispatcher;
/** @var array */
protected $messageTypes;
Expand Down Expand Up @@ -50,18 +49,10 @@ public function publish(string $messageType, Message $message, array $overridenC

$messagePublisher->publish($message, $routingKey);

if ($this->eventDispatcher instanceof ContractsEventDispatcherInterface) {
$this->eventDispatcher->dispatch(
new MessagePublishedEvent($messageType, $message, $connection, $exchange, $routingKey),
MessagePublishedEvent::NAME
);
} else {
// Dispatch the old way as we are using Event Dispatcher < 4.3
$this->eventDispatcher->dispatch(
MessagePublishedEvent::NAME,
new MessagePublishedEvent($messageType, $message, $connection, $exchange, $routingKey)
);
}
$this->eventDispatcher->dispatch(
new MessagePublishedEvent($messageType, $message, $connection, $exchange, $routingKey),
MessagePublishedEvent::NAME
);
}

public function isKnownMessageType(string $messageType): bool
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

- Add support to Symfony 7.0
- Remove Symfony <5.4 support

## 2.4.1 - 2022-03-07

- Make command lazy loadable
Expand Down
7 changes: 2 additions & 5 deletions Command/SwarrotCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ class SwarrotCommand extends Command
/** @var array */
protected $aliases;

/** @var string */
protected static $defaultDescription = 'Consume messages from a given queue';

public function __construct(
FactoryInterface $swarrotFactory,
string $name,
Expand Down Expand Up @@ -65,7 +62,7 @@ protected function configure(): void
$this
->setName('swarrot:consume:'.$this->name)
->setAliases($this->aliases)
->setDescription(self::$defaultDescription)
->setDescription('Consume messages from a given queue')
->addArgument('queue', InputArgument::OPTIONAL, 'Queue to consume', $this->queue)
->addArgument('connection', InputArgument::OPTIONAL, 'Connection to use', $this->connectionName)
->addOption(
Expand Down Expand Up @@ -117,7 +114,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$consumer->consume($options);

return 0;
return Command::SUCCESS;
}

protected function getOptions(InputInterface $input): array
Expand Down
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
"php": "^7.4|^8.0",
"psr/log": "^1.0|^2.0|^3.0",
"swarrot/swarrot": "^4.0",
"symfony/config": "^4.4|^5.4|^6.0",
"symfony/console": "^4.4|^5.4|^6.0",
"symfony/dependency-injection": "^4.4|^5.4|^6.0",
"symfony/http-kernel": "^4.4|^5.4|^6.0",
"symfony/yaml": "^4.4|^5.4|^6.0"
"symfony/config": "^5.4|^6.0|^7.0",
"symfony/console": "^5.4|^6.0|^7.0",
"symfony/dependency-injection": "^5.4|^6.0|^7.0",
"symfony/http-kernel": "^5.4|^6.0|^7.0",
"symfony/yaml": "^5.4|^6.0|^7.0"
},
"require-dev": {
"doctrine/common": "^2.9|^3.0",
Expand All @@ -30,8 +30,8 @@
"phpspec/prophecy-phpunit": "^2.0",
"phpstan/phpstan": "^1.2",
"phpunit/phpunit": "^9.5",
"symfony/event-dispatcher": "^4.4|^5.4|^6.0",
"symfony/phpunit-bridge": "^4.4|^5.4|^6.0"
"symfony/event-dispatcher": "^5.4|^6.0|^7.0",
"symfony/phpunit-bridge": "^5.4|^6.0|^7.0"
},
"suggest": {
"php-amqplib/php-amqplib": "Required if using amqp_lib"
Expand All @@ -47,7 +47,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "2.4-dev"
"dev-master": "2.5-dev"
}
}
}
5 changes: 0 additions & 5 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ parameters:
- Event/SymfonyEvent.php

ignoreErrors:
-
message: "#^Else branch is unreachable because previous condition is always true\\.$#"
count: 1
path: Broker/Publisher.php

-
message: '#^Cannot cast mixed to.*#'
paths:
Expand Down

0 comments on commit bf97176

Please sign in to comment.