From 5b6a23f8036b10a3f7106cedc0d251bf774a43e9 Mon Sep 17 00:00:00 2001 From: bota Date: Thu, 31 Jul 2025 15:15:39 +0300 Subject: [PATCH 1/2] Issue #46: Changed ExampleMessage and ExampleMessageHandler to Message and MessageHandler Signed-off-by: bota --- config/autoload/templates.global.php | 43 ------------------- src/App/ConfigProvider.php | 20 +++------ .../{ExampleMessage.php => Message.php} | 2 +- ...eMessageHandler.php => MessageHandler.php} | 10 ++--- src/Swoole/Delegators/TCPServerDelegator.php | 6 +-- 5 files changed, 14 insertions(+), 67 deletions(-) delete mode 100644 config/autoload/templates.global.php rename src/App/Message/{ExampleMessage.php => Message.php} (91%) rename src/App/Message/{ExampleMessageHandler.php => MessageHandler.php} (83%) diff --git a/config/autoload/templates.global.php b/config/autoload/templates.global.php deleted file mode 100644 index 6b1f459..0000000 --- a/config/autoload/templates.global.php +++ /dev/null @@ -1,43 +0,0 @@ - [ - 'factories' => [ - DateExtension::class => InvokableFactory::class, - Environment::class => TwigEnvironmentFactory::class, - TemplateRendererInterface::class => TwigRendererFactory::class, - TranslationExtension::class => InvokableFactory::class, - ], - ], - 'debug' => false, - 'templates' => [ - 'extension' => 'html.twig', - ], - 'twig' => [ - 'assets_url' => '/', - 'assets_version' => null, - 'auto_reload' => true, - 'autoescape' => 'html', - 'cache_dir' => 'data/cache/twig', - 'extensions' => [ - DateExtension::class, - TranslationExtension::class, - ], - 'globals' => [ - 'appName' => $app['name'] ?? '', - ], - 'optimizations' => -1, - 'runtime_loaders' => [], -// 'timezone' => '', - ], -]; diff --git a/src/App/ConfigProvider.php b/src/App/ConfigProvider.php index 9d6963d..32641e6 100644 --- a/src/App/ConfigProvider.php +++ b/src/App/ConfigProvider.php @@ -10,8 +10,8 @@ use Netglue\PsrContainer\Messenger\Container\Middleware\MessageHandlerMiddlewareStaticFactory; use Netglue\PsrContainer\Messenger\Container\Middleware\MessageSenderMiddlewareStaticFactory; use Netglue\PsrContainer\Messenger\HandlerLocator\OneToManyFqcnContainerHandlerLocator; -use Queue\App\Message\ExampleMessage; -use Queue\App\Message\ExampleMessageHandler; +use Queue\App\Message\Message; +use Queue\App\Message\MessageHandler; use Symfony\Component\Messenger\MessageBusInterface; class ConfigProvider @@ -25,7 +25,6 @@ public function __invoke(): array 'buses' => $this->busConfig(), ], ], - 'templates' => $this->getTemplates(), ]; } @@ -37,7 +36,7 @@ private function getDependencies(): array "message_bus_stamp_middleware" => [BusNameStampMiddlewareStaticFactory::class, "message_bus"], "message_bus_sender_middleware" => [MessageSenderMiddlewareStaticFactory::class, "message_bus"], "message_bus_handler_middleware" => [MessageHandlerMiddlewareStaticFactory::class, "message_bus"], - ExampleMessageHandler::class => AttributedServiceFactory::class, + MessageHandler::class => AttributedServiceFactory::class, ], "aliases" => [ MessageBusInterface::class => "message_bus", @@ -45,15 +44,6 @@ private function getDependencies(): array ]; } - public function getTemplates(): array - { - return [ - 'paths' => [ - 'notification-email' => [__DIR__ . '/templates'], - ], - ]; - } - private function busConfig(): array { return [ @@ -81,7 +71,7 @@ private function busConfig(): array */ 'handler_locator' => OneToManyFqcnContainerHandlerLocator::class, 'handlers' => [ - ExampleMessage::class => [ExampleMessageHandler::class], + Message::class => [MessageHandler::class], ], /** @@ -97,7 +87,7 @@ private function busConfig(): array * Route specific messages to specific transports by using the message name as the key. */ 'routes' => [ - ExampleMessage::class => ["redis_transport"], + Message::class => ["redis_transport"], ], ], ]; diff --git a/src/App/Message/ExampleMessage.php b/src/App/Message/Message.php similarity index 91% rename from src/App/Message/ExampleMessage.php rename to src/App/Message/Message.php index d094f4d..aeee893 100644 --- a/src/App/Message/ExampleMessage.php +++ b/src/App/Message/Message.php @@ -4,7 +4,7 @@ namespace Queue\App\Message; -class ExampleMessage +class Message { public function __construct( private array $payload, diff --git a/src/App/Message/ExampleMessageHandler.php b/src/App/Message/MessageHandler.php similarity index 83% rename from src/App/Message/ExampleMessageHandler.php rename to src/App/Message/MessageHandler.php index 63bf30a..74d008b 100644 --- a/src/App/Message/ExampleMessageHandler.php +++ b/src/App/Message/MessageHandler.php @@ -10,7 +10,7 @@ use Symfony\Component\Messenger\MessageBusInterface; use Symfony\Component\Messenger\Stamp\DelayStamp; -class ExampleMessageHandler +class MessageHandler { #[Inject( MessageBusInterface::class, @@ -24,7 +24,7 @@ public function __construct( ) { } - public function __invoke(ExampleMessage $message): void + public function __invoke(Message $message): void { $payload = $message->getPayload(); @@ -50,7 +50,7 @@ public function __invoke(ExampleMessage $message): void public function retry(array $payload): void { if (! isset($payload['retry'])) { - $this->bus->dispatch(new ExampleMessage(["foo" => $payload['foo'], 'retry' => 1]), [ + $this->bus->dispatch(new Message(["foo" => $payload['foo'], 'retry' => 1]), [ new DelayStamp($this->config['fail-safe']['first_retry']), ]); } else { @@ -58,13 +58,13 @@ public function retry(array $payload): void switch ($retry) { case 1: $delay = $this->config['fail-safe']['second_retry']; - $this->bus->dispatch(new ExampleMessage(["foo" => $payload['foo'], 'retry' => ++$retry]), [ + $this->bus->dispatch(new Message(["foo" => $payload['foo'], 'retry' => ++$retry]), [ new DelayStamp($delay), ]); break; case 2: $delay = $this->config['fail-safe']['third_retry']; - $this->bus->dispatch(new ExampleMessage(["foo" => $payload['foo'], 'retry' => ++$retry]), [ + $this->bus->dispatch(new Message(["foo" => $payload['foo'], 'retry' => ++$retry]), [ new DelayStamp($delay), ]); break; diff --git a/src/Swoole/Delegators/TCPServerDelegator.php b/src/Swoole/Delegators/TCPServerDelegator.php index e7353ec..3b9b67a 100644 --- a/src/Swoole/Delegators/TCPServerDelegator.php +++ b/src/Swoole/Delegators/TCPServerDelegator.php @@ -5,7 +5,7 @@ namespace Queue\Swoole\Delegators; use Psr\Container\ContainerInterface; -use Queue\App\Message\ExampleMessage; +use Queue\App\Message\Message; use Queue\Swoole\Command\GetFailedMessagesCommand; use Queue\Swoole\Command\GetProcessedMessagesCommand; use Queue\Swoole\Command\GetQueuedMessagesCommand; @@ -79,8 +79,8 @@ public function __invoke(ContainerInterface $container, string $serviceName, cal $logger->error("Error running command: " . $e->getMessage()); } } else { - $bus->dispatch(new ExampleMessage(["foo" => $message])); - $bus->dispatch(new ExampleMessage(["foo" => "with 5 seconds delay"]), [ + $bus->dispatch(new Message(["foo" => $message])); + $bus->dispatch(new Message(["foo" => "with 5 seconds delay"]), [ new DelayStamp(5000), ]); From bb864c67f19086c55c2a29fe177d507003fa924e Mon Sep 17 00:00:00 2001 From: bota Date: Thu, 31 Jul 2025 15:16:01 +0300 Subject: [PATCH 2/2] fixed line Signed-off-by: bota --- phpunit.xml.dist | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 324aa42..7a397a0 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -10,8 +10,7 @@ displayDetailsOnTestsThatTriggerErrors="true" displayDetailsOnTestsThatTriggerNotices="true" displayDetailsOnTestsThatTriggerWarnings="true" - colors="true" -> + colors="true"> ./test