From 462a7ea2de53688369b4d394b7465e07126a4434 Mon Sep 17 00:00:00 2001 From: Awilum Date: Tue, 21 Sep 2021 16:09:50 +0300 Subject: [PATCH] feat(console): add CacheDeleteMultipleCommand #543 --- .../Cache/CacheDeleteMultipleCommand.php | 41 +++++++++++++++++++ .../Console/FlextypeConsoleApplication.php | 2 + 2 files changed, 43 insertions(+) create mode 100644 src/flextype/core/Console/Commands/Cache/CacheDeleteMultipleCommand.php diff --git a/src/flextype/core/Console/Commands/Cache/CacheDeleteMultipleCommand.php b/src/flextype/core/Console/Commands/Cache/CacheDeleteMultipleCommand.php new file mode 100644 index 00000000..af485343 --- /dev/null +++ b/src/flextype/core/Console/Commands/Cache/CacheDeleteMultipleCommand.php @@ -0,0 +1,41 @@ +setName('cache:delete-multiple'); + $this->setDescription('Delete mutiple items.'); + $this->addArgument('keys', InputArgument::REQUIRED, 'Keys.'); + } + + protected function execute(InputInterface $input, OutputInterface $output): int + { + $io = new SymfonyStyle($input, $output); + + $keys = $input->getArgument('keys') ? serializers()->json()->decode($input->getArgument('keys')) : []; + + if (cache()->deleteMultiple($keys)) { + $io->success('Cache items with keys ' . implode(', ', $keys) . ' deleted.'); + return Command::SUCCESS; + } else { + $io->error('Cache items with keys ' . implode(', ', $keys) . ' wasn\'t deleted.'); + return Command::FAILURE; + } + } +} \ No newline at end of file diff --git a/src/flextype/core/Console/FlextypeConsoleApplication.php b/src/flextype/core/Console/FlextypeConsoleApplication.php index 0391ab06..b28ab6cd 100644 --- a/src/flextype/core/Console/FlextypeConsoleApplication.php +++ b/src/flextype/core/Console/FlextypeConsoleApplication.php @@ -22,6 +22,7 @@ use Flextype\Console\Commands\Cache\CacheSetCommand; use Flextype\Console\Commands\Cache\CacheGetCommand; use Flextype\Console\Commands\Cache\CacheGetMultipleCommand; use Flextype\Console\Commands\Cache\CacheSetMultipleCommand; +use Flextype\Console\Commands\Cache\CacheDeleteMultipleCommand; use Flextype\Console\Commands\Cache\CacheClearCommand; use Flextype\Console\Commands\Cache\CacheHasCommand; use Symfony\Component\Console\Input\InputInterface; @@ -43,6 +44,7 @@ class FlextypeConsoleApplication extends ConsoleApplication console()->add(new CacheGetCommand()); console()->add(new CacheGetMultipleCommand()); console()->add(new CacheSetMultipleCommand()); + console()->add(new CacheDeleteMultipleCommand()); console()->add(new CacheDeleteCommand()); console()->add(new CacheClearCommand()); console()->add(new CacheHasCommand());