diff --git a/src/flextype/core/Console/Commands/Cache/CacheHasCommand.php b/src/flextype/core/Console/Commands/Cache/CacheHasCommand.php new file mode 100644 index 00000000..0e83941b --- /dev/null +++ b/src/flextype/core/Console/Commands/Cache/CacheHasCommand.php @@ -0,0 +1,41 @@ +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; + } + } +} \ No newline at end of file diff --git a/src/flextype/core/Console/FlextypeConsoleApplication.php b/src/flextype/core/Console/FlextypeConsoleApplication.php index ced1724a..99a9f299 100644 --- a/src/flextype/core/Console/FlextypeConsoleApplication.php +++ b/src/flextype/core/Console/FlextypeConsoleApplication.php @@ -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(); }