From 4427f3cb3ebe1ac42fa5f8f40fd23c21cbb6e940 Mon Sep 17 00:00:00 2001 From: Awilum Date: Tue, 21 Sep 2021 14:15:38 +0300 Subject: [PATCH] feat(console): add CacheHasCommand #543 --- .../Commands/Cache/CacheHasCommand.php | 41 +++++++++++++++++++ .../Console/FlextypeConsoleApplication.php | 2 + 2 files changed, 43 insertions(+) create mode 100644 src/flextype/core/Console/Commands/Cache/CacheHasCommand.php 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(); }