mirror of
https://github.com/flextype/flextype.git
synced 2025-08-07 21:56:33 +02:00
feat(console): add CacheSetCommand #543
This commit is contained in:
45
src/flextype/core/Console/Commands/Cache/CacheSetCommand.php
Normal file
45
src/flextype/core/Console/Commands/Cache/CacheSetCommand.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?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 CacheSetCommand extends Command
|
||||
{
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
}
|
||||
}
|
@@ -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();
|
||||
}
|
||||
|
Reference in New Issue
Block a user