From 12f4c9b358c48b7153fddffdaceb8ded1b0d880b Mon Sep 17 00:00:00 2001 From: Anton Date: Thu, 29 Feb 2024 00:42:44 +0800 Subject: [PATCH] CommandDescriptionProcessor interface removed. Description processor now can be implementec as callable --- src/TelegramBot/Command/ButtonUpdateCommand.php | 8 +++++--- src/TelegramBot/CommandDescriptionProcessor.php | 10 ---------- src/TelegramBot/DummyDescriptionProcessor.php | 13 ------------- src/config/services.php | 9 ++------- tests/ServicesAutowiringTest.php | 2 -- 5 files changed, 7 insertions(+), 35 deletions(-) delete mode 100644 src/TelegramBot/CommandDescriptionProcessor.php delete mode 100644 src/TelegramBot/DummyDescriptionProcessor.php diff --git a/src/TelegramBot/Command/ButtonUpdateCommand.php b/src/TelegramBot/Command/ButtonUpdateCommand.php index 66886ee..22d3e15 100644 --- a/src/TelegramBot/Command/ButtonUpdateCommand.php +++ b/src/TelegramBot/Command/ButtonUpdateCommand.php @@ -8,7 +8,6 @@ use Luzrain\TelegramBotApi\Exception\TelegramApiException; use Luzrain\TelegramBotApi\Method; use Luzrain\TelegramBotApi\Type; -use Luzrain\TelegramBotBundle\TelegramBot\CommandDescriptionProcessor; use Luzrain\TelegramBotBundle\TelegramBot\CommandMetadataProvider; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; @@ -17,11 +16,14 @@ final class ButtonUpdateCommand extends Command { + private \Closure $descriptionProcessor; + public function __construct( private BotApi $botApi, private CommandMetadataProvider $commandMetadataProvider, - private CommandDescriptionProcessor $descriptionProcessor, + callable|null $descriptionProcessor, ) { + $this->descriptionProcessor = $descriptionProcessor ? $descriptionProcessor(...) : static fn (string $str) => $str; parent::__construct(); } @@ -46,7 +48,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int continue; } - $description = $this->descriptionProcessor->process($attr->description); + $description = ($this->descriptionProcessor)($attr->description); $output->writeln(\sprintf("%s\t\t%s", $attr->command, $description)); $commands[] = new Type\BotCommand(command: $attr->command, description: $description); } diff --git a/src/TelegramBot/CommandDescriptionProcessor.php b/src/TelegramBot/CommandDescriptionProcessor.php deleted file mode 100644 index f073c5a..0000000 --- a/src/TelegramBot/CommandDescriptionProcessor.php +++ /dev/null @@ -1,10 +0,0 @@ -setArguments([ new Reference(BotApi::class), new Reference('telegram_bot.command_metadata_provider'), - new Reference('telegram_bot.description_processor'), + new Reference('telegram_bot.description_processor', ContainerInterface::NULL_ON_INVALID_REFERENCE), ]) - ; $container @@ -105,10 +104,6 @@ ->setArguments([new Reference(BotApi::class)]) ; - $container - ->register('telegram_bot.description_processor', DummyDescriptionProcessor::class) - ; - /** @var \Closure $controllerConfigurate */ $controllerConfigurate = static function (ChildDefinition $definition, object $attribute, \ReflectionMethod $reflector): void { $definition->addTag('telegram_bot.command', [ diff --git a/tests/ServicesAutowiringTest.php b/tests/ServicesAutowiringTest.php index 529d0d1..21be29b 100644 --- a/tests/ServicesAutowiringTest.php +++ b/tests/ServicesAutowiringTest.php @@ -12,7 +12,6 @@ use Luzrain\TelegramBotBundle\TelegramBot\Command\WebhookDeleteCommand; use Luzrain\TelegramBotBundle\TelegramBot\Command\WebhookInfoCommand; use Luzrain\TelegramBotBundle\TelegramBot\Command\WebhookUpdateCommand; -use Luzrain\TelegramBotBundle\TelegramBot\CommandDescriptionProcessor; use Luzrain\TelegramBotBundle\TelegramBot\CommandMetadataProvider; use Luzrain\TelegramBotBundle\TelegramBot\Controller\WebHookController; use Luzrain\TelegramBotBundle\TelegramBot\LongPollingService; @@ -49,6 +48,5 @@ public function testServiceAutowiring(): void $this->assertInstanceOf(ButtonDeleteCommand::class, self::$container->get('telegram_bot.menu_button_delete_command')); $this->assertInstanceOf(UpdateHandler::class, self::$container->get('telegram_bot.update_handler')); $this->assertInstanceOf(CommandMetadataProvider::class, self::$container->get('telegram_bot.command_metadata_provider')); - $this->assertInstanceOf(CommandDescriptionProcessor::class, self::$container->get('telegram_bot.description_processor')); } }