mirror of
https://github.com/flextype/flextype.git
synced 2025-08-07 13:46:42 +02:00
feat(console): add CacheGetMultipleCommand #543
This commit is contained in:
@@ -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\Style\SymfonyStyle;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
|
||||
class CacheGetMultipleCommand extends Command
|
||||
{
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->setName('cache:get-multiple');
|
||||
$this->setDescription('Get multiple keys');
|
||||
$this->addArgument('keys', InputArgument::REQUIRED, 'Keys.');
|
||||
$this->addArgument('default', InputArgument::OPTIONAL, 'Default.');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$keys = $input->getArgument('keys') ? serializers()->json()->decode($input->getArgument('keys')) : [];
|
||||
$default = $input->getArgument('default') ?? null;
|
||||
|
||||
$data = cache()->getMultiple($keys, $default);
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
$output->writeln($value);
|
||||
}
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
@@ -20,6 +20,7 @@ use Flextype\Console\Commands\Entries\EntriesHasCommand;
|
||||
use Flextype\Console\Commands\Cache\CacheDeleteCommand;
|
||||
use Flextype\Console\Commands\Cache\CacheSetCommand;
|
||||
use Flextype\Console\Commands\Cache\CacheGetCommand;
|
||||
use Flextype\Console\Commands\Cache\CacheGetMultipleCommand;
|
||||
use Flextype\Console\Commands\Cache\CacheClearCommand;
|
||||
use Flextype\Console\Commands\Cache\CacheHasCommand;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
@@ -39,6 +40,7 @@ class FlextypeConsoleApplication extends ConsoleApplication
|
||||
console()->add(new EntriesFetchCommand());
|
||||
console()->add(new CacheSetCommand());
|
||||
console()->add(new CacheGetCommand());
|
||||
console()->add(new CacheGetMultipleCommand());
|
||||
console()->add(new CacheDeleteCommand());
|
||||
console()->add(new CacheClearCommand());
|
||||
console()->add(new CacheHasCommand());
|
||||
|
Reference in New Issue
Block a user