diff --git a/composer.json b/composer.json index af56172..e3bd648 100644 --- a/composer.json +++ b/composer.json @@ -6,26 +6,30 @@ { "name": "Leo Sjöberg", "email": "leo@decahedron.io" + }, + { + "name": "Hakan Aktas", + "email": "hakan.aktas@jobilla.com" } ], "require": { - "php": ">= 7.3", + "php": ">=8.2", "google/cloud": "0.*", - "illuminate/config": "^6.0|^7.0|^8.0|^9.0|^10.0", - "illuminate/console": "^6.0|^7.0|^8.0|^9.0|^10.0", + "illuminate/config": "^9.0|^10.0", + "illuminate/console": "^9.0|^10.0", "kainxspirits/laravel-pubsub-queue": "~0.4.0|~0.5.0|~0.6.0|~0.7.0|~0.8.0", "google/protobuf": "^3.6.0", - "illuminate/bus": "^6.0|^7.0|^8.0|^9.0|^10.0", + "illuminate/bus": "^9.0|^10.0", "ext-json": "*" }, "autoload": { "psr-4": { - "Decahedron\\AppEvents\\": "src/" + "Jobilla\\AppEvents\\": "src/" } }, "autoload-dev": { "psr-4": { - "Decahedron\\AppEvents\\Tests\\Proto\\": "tests/fixtures/Decahedron/AppEvents/Tests/Proto" + "Jobilla\\AppEvents\\Tests\\Proto\\": "tests/fixtures/Jobilla/AppEvents/Tests/Proto" } }, "extra": { @@ -34,7 +38,7 @@ "Kainxspirits\\PubSubQueue\\PubSubQueueServiceProvider" ], "providers": [ - "Decahedron\\AppEvents\\AppEventsProvider" + "Jobilla\\AppEvents\\AppEventsProvider" ] } }, diff --git a/src/AppEvent.php b/src/AppEvent.php index 3b3317c..1477247 100644 --- a/src/AppEvent.php +++ b/src/AppEvent.php @@ -1,6 +1,6 @@ payload = $payload; $this->event = $event; } - - public function handle() - { - foreach (Config::get('app-events.handlers') as $event => $handler) { - if ($this->event !== $event) { - continue; - } - - Container::getInstance()->make($handler)->handle($this->payload, $event); - } - } } diff --git a/src/AppEventFactory.php b/src/AppEventFactory.php index c97b208..30aa990 100644 --- a/src/AppEventFactory.php +++ b/src/AppEventFactory.php @@ -1,6 +1,6 @@ attribute('event_type'), static::resolveProtobufInstance($message)); + $handler = static::resolveHandler($message->attribute('event_type')); + + return new $handler(static::resolveProtobufInstance($message)); + } + + /** + * @throws UnsupportedEventException + */ + protected static function resolveHandler(string $eventName): string + { + $configKey = 'app-events.handlers.' . $eventName; + + if (! Config::has($configKey)) { + throw new UnsupportedEventException($eventName); + } + + return Config::get($configKey); } /** diff --git a/src/AppEventsProvider.php b/src/AppEventsProvider.php index d7b522b..40c8f6c 100644 --- a/src/AppEventsProvider.php +++ b/src/AppEventsProvider.php @@ -1,8 +1,8 @@ option('silent')) { - $this->info('No implementation registered for message type: ' . $e->protoMessageType); - } $handledMessages[] = $message; continue; } catch (UnsupportedEventException $e) { @@ -112,9 +109,9 @@ private function runIteration(Subscription $subscription) 'message' => $message->info(), 'published_at' => $message->publishTime(), ]); - $handledMessages[] = $message; continue; } + if (! $this->option('silent')) { $this->info('Handling message: '.$job->event); } diff --git a/src/PubSubConnector.php b/src/PubSubConnector.php index 6e7c9e7..a91ef63 100644 --- a/src/PubSubConnector.php +++ b/src/PubSubConnector.php @@ -1,6 +1,6 @@