From 4034742582c3c75a0fb0015b5fafa43732a17fbb Mon Sep 17 00:00:00 2001 From: Awilum Date: Tue, 21 Sep 2021 13:12:01 +0300 Subject: [PATCH] feat(console): add CacheSetCommand #543 --- .../Commands/Cache/CacheSetCommand.php | 45 +++++++++++++++++++ .../Console/FlextypeConsoleApplication.php | 2 + 2 files changed, 47 insertions(+) create mode 100644 src/flextype/core/Console/Commands/Cache/CacheSetCommand.php diff --git a/src/flextype/core/Console/Commands/Cache/CacheSetCommand.php b/src/flextype/core/Console/Commands/Cache/CacheSetCommand.php new file mode 100644 index 00000000..04dc6431 --- /dev/null +++ b/src/flextype/core/Console/Commands/Cache/CacheSetCommand.php @@ -0,0 +1,45 @@ +setName('cache:set'); + $this->setDescription('Set value'); + $this->addArgument('key', InputArgument::REQUIRED, 'Key.'); + $this->addArgument('value', InputArgument::REQUIRED, 'Value.'); + $this->addArgument('ttl', InputArgument::OPTIONAL, 'Time To Live.'); + } + + protected function execute(InputInterface $input, OutputInterface $output): int + { + $io = new SymfonyStyle($input, $output); + + $key = $input->getArgument('key'); + $value = $input->getArgument('value'); + $ttl = $input->getArgument('ttl') ?? 300; + + if (cache()->set($key, $value, $ttl)) { + $io->success('Value for key ' . $key . ' stored.'); + return Command::SUCCESS; + } else { + $io->error('Value for key ' . $key . ' wasn\'t created.'); + 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 b63206f4..97beb49a 100644 --- a/src/flextype/core/Console/FlextypeConsoleApplication.php +++ b/src/flextype/core/Console/FlextypeConsoleApplication.php @@ -17,6 +17,7 @@ use Flextype\Console\Commands\Entries\EntriesDeleteCommand; use Flextype\Console\Commands\Entries\EntriesCopyCommand; use Flextype\Console\Commands\Entries\EntriesMoveCommand; use Flextype\Console\Commands\Entries\EntriesHasCommand; +use Flextype\Console\Commands\Cache\CacheSetCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -32,6 +33,7 @@ class FlextypeConsoleApplication extends ConsoleApplication console()->add(new EntriesMoveCommand()); console()->add(new EntriesHasCommand()); console()->add(new EntriesFetchCommand()); + console()->add(new CacheSetCommand()); parent::run(); }