Skip to content

Commit

Permalink
Allow Laravel 9 (#84)
Browse files Browse the repository at this point in the history
* allow laravel 9

* fix codestyle

* change phpqa image

* PSR 12 codecheck

* copy Illuminate\Events\Dispatcher functions from 7 version
  • Loading branch information
andrew-nuwber authored Feb 10, 2022
1 parent e34aa7e commit 97dac75
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 19 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/static-code-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion src/Amqp/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected function makeFactory(): AmqpConnectionFactory
]);

$factory->setDelayStrategy($this->getDelayStrategy());

return $factory;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Console/EventsListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class EventsListCommand extends Command
* @var string
*/
protected $description = 'List of registered broadcast events';

public function handle(): void
{
$events = RabbitEvents::getEvents();
Expand Down
2 changes: 1 addition & 1 deletion src/Console/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;",
Expand Down
1 change: 0 additions & 1 deletion src/Console/Log/Output.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

class Output extends Writer
{

/**
* @var Application
*/
Expand Down
9 changes: 4 additions & 5 deletions src/Console/Log/Writer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Console/ObserverMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -103,7 +103,7 @@ protected function replaceModel($stub, $model): string
*/
protected function getDefaultNamespace($rootNamespace): string
{
return $rootNamespace.'\Observers';
return $rootNamespace . '\Observers';
}

/**
Expand Down
27 changes: 27 additions & 0 deletions src/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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.
*
Expand Down
1 change: 0 additions & 1 deletion src/Queue/Exceptions/FailedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@

class FailedException extends \RuntimeException
{

}
2 changes: 1 addition & 1 deletion src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 97dac75

Please sign in to comment.