1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-09 06:36:52 +02:00

feat(console): add CacheDeleteMultipleCommand #543

This commit is contained in:
Awilum
2021-09-21 16:09:50 +03:00
parent 1e4bdc2318
commit 462a7ea2de
2 changed files with 43 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
/**
* Flextype (https://flextype.org)
* Founded by Sergey Romanenko and maintained by Flextype Community.
*/
namespace Flextype\Console\Commands\Cache;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Style\SymfonyStyle;
class CacheDeleteMultipleCommand extends Command
{
protected function configure(): void
{
$this->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;
}
}
}

View File

@@ -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());