From 97dac7518bc302d13fe0e87fb02a3708c6b1c16d Mon Sep 17 00:00:00 2001 From: Andrew <33055211+andrew-nuwber@users.noreply.github.com> Date: Thu, 10 Feb 2022 15:07:02 +0100 Subject: [PATCH] Allow Laravel 9 (#84) * allow laravel 9 * fix codestyle * change phpqa image * PSR 12 codecheck * copy Illuminate\Events\Dispatcher functions from 7 version --- .github/workflows/static-code-analysis.yml | 4 ++-- .github/workflows/testing.yml | 2 +- composer.json | 6 ++--- src/Amqp/Connection.php | 2 +- src/Console/EventsListCommand.php | 2 +- src/Console/InstallCommand.php | 2 +- src/Console/Log/Output.php | 1 - src/Console/Log/Writer.php | 9 ++++---- src/Console/ObserverMakeCommand.php | 4 ++-- src/Dispatcher.php | 27 ++++++++++++++++++++++ src/Queue/Exceptions/FailedException.php | 1 - src/helpers.php | 2 +- 12 files changed, 43 insertions(+), 19 deletions(-) diff --git a/.github/workflows/static-code-analysis.yml b/.github/workflows/static-code-analysis.yml index 591a7a0..1bccc08 100644 --- a/.github/workflows/static-code-analysis.yml +++ b/.github/workflows/static-code-analysis.yml @@ -4,9 +4,9 @@ on: [push] jobs: static-code-analysis: - container: zdenekdrahos/phpqa:v1.23.3 + container: ghcr.io/nuwber/phpqa-docker:php8.1 runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: phpqa - run: phpqa --analyzedDirs src --output cli --tools phpcs:0,phpmd,phpcpd:0,phpmetrics:0,phploc,pdepend + run: phpqa --analyzedDirs src --output cli --tools phpcs.PSR12:0,phpmd,phpcpd:0,phpmetrics:0,phploc,pdepend diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 8036cc7..a5e801c 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-versions: ['7.3', '7.4', '8.0'] + php-versions: ['7.3', '7.4', '8.0', '8.1'] name: Testing on PHP ${{ matrix.php-versions }} steps: - uses: actions/checkout@v2 diff --git a/composer.json b/composer.json index a566bd9..a8b522e 100644 --- a/composer.json +++ b/composer.json @@ -22,9 +22,9 @@ "ext-bcmath": "*", "ext-pcntl": "*", "ext-json": "*", - "illuminate/events": "^7.0 | ^8.0", - "illuminate/queue": "^7.0 | ^8.0", - "illuminate/support": "^7.0 | ^8.0", + "illuminate/events": "^7.0 | ^8.0 | ^9.0", + "illuminate/queue": "^7.0 | ^8.0 | ^9.0", + "illuminate/support": "^7.0 | ^8.0 | ^9.0", "enqueue/amqp-lib": "^0.10" }, "require-dev": { diff --git a/src/Amqp/Connection.php b/src/Amqp/Connection.php index b376bd8..d5f6597 100644 --- a/src/Amqp/Connection.php +++ b/src/Amqp/Connection.php @@ -81,7 +81,7 @@ protected function makeFactory(): AmqpConnectionFactory ]); $factory->setDelayStrategy($this->getDelayStrategy()); - + return $factory; } diff --git a/src/Console/EventsListCommand.php b/src/Console/EventsListCommand.php index 2dfa428..dc49449 100644 --- a/src/Console/EventsListCommand.php +++ b/src/Console/EventsListCommand.php @@ -20,7 +20,7 @@ class EventsListCommand extends Command * @var string */ protected $description = 'List of registered broadcast events'; - + public function handle(): void { $events = RabbitEvents::getEvents(); diff --git a/src/Console/InstallCommand.php b/src/Console/InstallCommand.php index e0a9d7f..b10f3c6 100644 --- a/src/Console/InstallCommand.php +++ b/src/Console/InstallCommand.php @@ -56,7 +56,7 @@ protected function registerServiceProvider() $appConfig ) ); - + file_put_contents($this->laravel->path('Providers/RabbitEventsServiceProvider.php'), str_replace( "namespace App\Providers;", "namespace {$namespace}\Providers;", diff --git a/src/Console/Log/Output.php b/src/Console/Log/Output.php index 739bc3e..4d3bd6b 100644 --- a/src/Console/Log/Output.php +++ b/src/Console/Log/Output.php @@ -9,7 +9,6 @@ class Output extends Writer { - /** * @var Application */ diff --git a/src/Console/Log/Writer.php b/src/Console/Log/Writer.php index dc72e0c..b7bdfd6 100644 --- a/src/Console/Log/Writer.php +++ b/src/Console/Log/Writer.php @@ -9,11 +9,10 @@ abstract class Writer { - - const STATUS_PROCESSING = 'Processing'; - const STATUS_PROCESSED = 'Processed'; - const STATUS_EXCEPTION = 'Exception Occurred'; - const STATUS_FAILED = 'Failed'; + public const STATUS_PROCESSING = 'Processing'; + public const STATUS_PROCESSED = 'Processed'; + public const STATUS_EXCEPTION = 'Exception Occurred'; + public const STATUS_FAILED = 'Failed'; /** * @param JobProcessing | JobProcessed | JobFailed $event diff --git a/src/Console/ObserverMakeCommand.php b/src/Console/ObserverMakeCommand.php index 5654f68..4b63d0f 100644 --- a/src/Console/ObserverMakeCommand.php +++ b/src/Console/ObserverMakeCommand.php @@ -72,7 +72,7 @@ protected function replaceModel($stub, $model): string { $model = str_replace('/', '\\', $model); - $namespaceModel = $this->laravel->getNamespace().$model; + $namespaceModel = $this->laravel->getNamespace() . $model; if (Str::startsWith($model, '\\')) { $stub = str_replace('NamespacedDummyModel', trim($model, '\\'), $stub); @@ -103,7 +103,7 @@ protected function replaceModel($stub, $model): string */ protected function getDefaultNamespace($rootNamespace): string { - return $rootNamespace.'\Observers'; + return $rootNamespace . '\Observers'; } /** diff --git a/src/Dispatcher.php b/src/Dispatcher.php index 3551569..3ba50db 100644 --- a/src/Dispatcher.php +++ b/src/Dispatcher.php @@ -34,6 +34,20 @@ public function listen($events, $listener = null): void } } + public function getListeners($eventName) + { + $listeners = $this->listeners[$eventName] ?? []; + + $listeners = array_merge( + $listeners, + $this->wildcardsCache[$eventName] ?? $this->getWildcardListeners($eventName) + ); + + return class_exists($eventName, false) + ? $this->addInterfaceListeners($eventName, $listeners) + : $listeners; + } + /* * @inheritdoc */ @@ -64,6 +78,19 @@ public function makeListener($listener, $wildcard = false): \Closure }; } + protected function getWildcardListeners($eventName) + { + $wildcards = []; + + foreach ($this->wildcards as $key => $listeners) { + if (Str::is($key, $eventName)) { + $wildcards = array_merge($wildcards, $listeners); + } + } + + return $this->wildcardsCache[$eventName] = $wildcards; + } + /** * Setup a wildcard listener callback. * diff --git a/src/Queue/Exceptions/FailedException.php b/src/Queue/Exceptions/FailedException.php index 493bfad..970ea15 100644 --- a/src/Queue/Exceptions/FailedException.php +++ b/src/Queue/Exceptions/FailedException.php @@ -4,5 +4,4 @@ class FailedException extends \RuntimeException { - } diff --git a/src/helpers.php b/src/helpers.php index 771e848..6972c41 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -10,7 +10,7 @@ function publish($event, array $payload = []) { if (is_string($event)) { - $event = new class($event, $payload) implements ShouldPublish { + $event = new class ($event, $payload) implements ShouldPublish { private $event; private $payload;