mirror of
https://github.com/flextype/flextype.git
synced 2025-08-07 05:36:54 +02:00
feat(console): add CacheHasCommand #543
This commit is contained in:
41
src/flextype/core/Console/Commands/Cache/CacheHasCommand.php
Normal file
41
src/flextype/core/Console/Commands/Cache/CacheHasCommand.php
Normal 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\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
class CacheHasCommand extends Command
|
||||
{
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->setName('cache:has');
|
||||
$this->setDescription('Check whether cache item exists.');
|
||||
$this->addArgument('key', InputArgument::REQUIRED, 'Key.');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
|
||||
$key = $input->getArgument('key');
|
||||
|
||||
if (cache()->has($key)) {
|
||||
$io->success('Cache item with key ' . $key . ' exists.');
|
||||
return Command::SUCCESS;
|
||||
} else {
|
||||
$io->error('Cache item with key ' . $key . ' doesn\'t exists.');
|
||||
return Command::FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
@@ -21,6 +21,7 @@ use Flextype\Console\Commands\Cache\CacheDeleteCommand;
|
||||
use Flextype\Console\Commands\Cache\CacheSetCommand;
|
||||
use Flextype\Console\Commands\Cache\CacheGetCommand;
|
||||
use Flextype\Console\Commands\Cache\CacheClearCommand;
|
||||
use Flextype\Console\Commands\Cache\CacheHasCommand;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
@@ -40,6 +41,7 @@ class FlextypeConsoleApplication extends ConsoleApplication
|
||||
console()->add(new CacheGetCommand());
|
||||
console()->add(new CacheDeleteCommand());
|
||||
console()->add(new CacheClearCommand());
|
||||
console()->add(new CacheHasCommand());
|
||||
|
||||
parent::run();
|
||||
}
|
||||
|
Reference in New Issue
Block a user