Files
interview-demo-code/backend/src/console/Commands/CacheClearCommand.php
Nikita Kiselev 3abcb18f0c
Some checks failed
Telegram Mini App Shop Builder / Compute version metadata (push) Has been cancelled
Telegram Mini App Shop Builder / Run Frontend tests (push) Has been cancelled
Telegram Mini App Shop Builder / Run Backend tests (push) Has been cancelled
Telegram Mini App Shop Builder / Run PHP_CodeSniffer (push) Has been cancelled
Telegram Mini App Shop Builder / Build module. (push) Has been cancelled
Telegram Mini App Shop Builder / release (push) Has been cancelled
Squashed commit message
2026-03-11 22:55:28 +03:00

44 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace Console\Commands;
use Acme\ECommerceFramework\Cache\CacheInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
class CacheClearCommand extends AcmeShopCommand
{
protected static $defaultName = 'cache:clear';
protected static $defaultDescription = 'Очистка кеша модуля AcmeShop';
private CacheInterface $cache;
public function __construct(CacheInterface $cache)
{
parent::__construct();
$this->cache = $cache;
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$io->title('Очистка кеша модуля AcmeShop');
try {
$this->cache->clear();
$io->success('Кеш успешно очищен!');
return Command::SUCCESS;
} catch (\Exception $e) {
$io->error('Ошибка при очистке кеша: ' . $e->getMessage());
return Command::FAILURE;
}
}
}