Skip to content

Commit

Permalink
CommandDescriptionProcessor interface removed. Description processor …
Browse files Browse the repository at this point in the history
…now can be implementec as callable
  • Loading branch information
luzrain committed Feb 28, 2024
1 parent 2632ce1 commit 12f4c9b
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 35 deletions.
8 changes: 5 additions & 3 deletions src/TelegramBot/Command/ButtonUpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}

Expand All @@ -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);
}
Expand Down
10 changes: 0 additions & 10 deletions src/TelegramBot/CommandDescriptionProcessor.php

This file was deleted.

13 changes: 0 additions & 13 deletions src/TelegramBot/DummyDescriptionProcessor.php

This file was deleted.

9 changes: 2 additions & 7 deletions src/config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
use Luzrain\TelegramBotBundle\TelegramBot\Command\WebhookInfoCommand;
use Luzrain\TelegramBotBundle\TelegramBot\Command\WebhookUpdateCommand;
use Luzrain\TelegramBotBundle\TelegramBot\Controller\WebHookController;
use Luzrain\TelegramBotBundle\TelegramBot\DummyDescriptionProcessor;
use Luzrain\TelegramBotBundle\TelegramBot\LongPollingService;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Reference;

return static function (array $config, ContainerBuilder $container) {
Expand Down Expand Up @@ -94,9 +94,8 @@
->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
Expand All @@ -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', [
Expand Down
2 changes: 0 additions & 2 deletions tests/ServicesAutowiringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'));
}
}

0 comments on commit 12f4c9b

Please sign in to comment.