1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-06 13:16:45 +02:00

feat(console): reorganize cache commands

Commands:

- cache:clear
- cache:clear-data
- cache:clear-twig
- cache:clear-routes
This commit is contained in:
Awilum
2022-04-28 21:34:16 +03:00
parent 4ebd19be89
commit 5dbedbb541
5 changed files with 239 additions and 117 deletions

View File

@@ -30,139 +30,42 @@ class CacheClearCommand extends Command
{
$this->setName('cache:clear');
$this->setDescription('Clear cache.');
$this->addOption('data', null, InputOption::VALUE_NONE, 'Set this flag to clear data from cache.');
$this->addOption('config', null, InputOption::VALUE_NONE, 'Set this flag to clear config from cache.');
$this->addOption('routes', null, InputOption::VALUE_NONE, 'Set this flag to clear routes from cache.');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$result = Command::SUCCESS;
$path = PATH['tmp'];
if ($input->getOption('data')) {
if (filesystem()->directory(PATH['tmp'] . '/data')->exists()) {
if (filesystem()->directory(PATH['tmp'] . '/data')->delete()) {
$output->write(
renderToString(
div('Success: Data were successfully cleared from the cache.',
'bg-success px-2 py-1')
)
);
$result = Command::SUCCESS;
} else {
$output->write(
renderToString(
div('Failure: Data cache wasn\'t cleared.',
'bg-danger px-2 py-1')
)
);
$result = Command::FAILURE;
}
if (filesystem()->directory($path)->exists()) {
if (filesystem()->directory($path)->delete()) {
$output->write(
renderToString(
div('Success: All items were successfully cleared from the cache.',
'bg-success px-2 py-1')
)
);
$result = Command::SUCCESS;
} else {
$output->write(
renderToString(
div('Failure: Data cache directory ' . PATH['tmp'] . '/data' . ' doesn\'t exist.',
div('Failure: Cache wasn\'t cleared.',
'bg-danger px-2 py-1')
)
);
$result = Command::FAILURE;
}
} else {
$output->write(
renderToString(
div('Failure: Cache directory ' . $path . ' doesn\'t exist.',
'bg-danger px-2 py-1')
)
);
$result = Command::FAILURE;
}
if ($input->getOption('config')) {
if (filesystem()->directory(PATH['tmp'] . '/config')->exists()) {
if (filesystem()->directory(PATH['tmp'] . '/config')->delete()) {
$output->write(
renderToString(
div('Success: Config were successfully cleared from the cache.',
'bg-success px-2 py-1')
)
);
$result = Command::SUCCESS;
} else {
$output->write(
renderToString(
div('Failure: Config cache wasn\'t cleared.',
'bg-danger px-2 py-1')
)
);
$result = Command::FAILURE;
}
} else {
$output->write(
renderToString(
div('Failure: Config cache directory ' . PATH['tmp'] . '/config' . ' doesn\'t exist.',
'bg-danger px-2 py-1')
)
);
$result = Command::FAILURE;
}
}
if ($input->getOption('routes')) {
if (filesystem()->directory(PATH['tmp'] . '/routes')->exists()) {
if (filesystem()->directory(PATH['tmp'] . '/routes')->delete()) {
$output->write(
renderToString(
div('Success: Routes were successfully cleared from the cache.',
'bg-success px-2 py-1')
)
);
$result = Command::SUCCESS;
} else {
$output->write(
renderToString(
div('Failure: Routes cache wasn\'t cleared.',
'bg-danger px-2 py-1')
)
);
$result = Command::FAILURE;
}
} else {
$output->write(
renderToString(
div('Failure: Routes cache directory ' . PATH['tmp'] . '/routes' . ' doesn\'t exist.',
'bg-danger px-2 py-1')
)
);
$result = Command::FAILURE;
}
}
if (($input->getOption('data') == false &&
$input->getOption('config') == false &&
$input->getOption('routes') == false)) {
if (filesystem()->directory(PATH['tmp'])->exists()) {
if (filesystem()->directory(PATH['tmp'])->delete()) {
$output->write(
renderToString(
div('Success: All items were successfully cleared from the cache.',
'bg-success px-2 py-1')
)
);
$result = Command::SUCCESS;
} else {
$output->write(
renderToString(
div('Failure: Cache wasn\'t cleared.',
'bg-danger px-2 py-1')
)
);
$result = Command::FAILURE;
}
} else {
$output->write(
renderToString(
div('Failure: Cache directory ' . PATH['tmp'] . ' doesn\'t exist.',
'bg-danger px-2 py-1')
)
);
$result = Command::FAILURE;
}
}
return $result;
}
}

View File

@@ -0,0 +1,71 @@
<?php
declare(strict_types=1);
/**
* Flextype - Hybrid Content Management System with the freedom of a headless CMS
* and with the full functionality of a traditional CMS!
*
* Copyright (c) Sergey Romanenko (https://awilum.github.io)
*
* Licensed under The MIT License.
*
* For full copyright and license information, please see the LICENSE
* Redistributions of files must retain the above copyright notice.
*/
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\InputOption;
use function Thermage\div;
use function Thermage\renderToString;
class CacheClearConfigCommand extends Command
{
protected function configure(): void
{
$this->setName('cache:clear-config');
$this->setDescription('Clear cache config.');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$configPath = PATH['tmp'] . '/config';
if (filesystem()->directory($configPath)->exists()) {
if (filesystem()->directory($configPath)->delete()) {
$output->write(
renderToString(
div('Success: Config were successfully cleared from the cache.',
'bg-success px-2 py-1')
)
);
$result = Command::SUCCESS;
} else {
$output->write(
renderToString(
div('Failure: Config cache wasn\'t cleared.',
'bg-danger px-2 py-1')
)
);
$result = Command::FAILURE;
}
} else {
$output->write(
renderToString(
div('Failure: Config cache directory ' . $configPath . ' doesn\'t exist.',
'bg-danger px-2 py-1')
)
);
$result = Command::FAILURE;
}
return $result;
}
}

View File

@@ -0,0 +1,71 @@
<?php
declare(strict_types=1);
/**
* Flextype - Hybrid Content Management System with the freedom of a headless CMS
* and with the full functionality of a traditional CMS!
*
* Copyright (c) Sergey Romanenko (https://awilum.github.io)
*
* Licensed under The MIT License.
*
* For full copyright and license information, please see the LICENSE
* Redistributions of files must retain the above copyright notice.
*/
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\InputOption;
use function Thermage\div;
use function Thermage\renderToString;
class CacheClearDataCommand extends Command
{
protected function configure(): void
{
$this->setName('cache:clear-data');
$this->setDescription('Clear cache data.');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$routesData = PATH['tmp'] . '/data';
if (filesystem()->directory($routesData)->exists()) {
if (filesystem()->directory($routesData)->delete()) {
$output->write(
renderToString(
div('Success: Data were successfully cleared from the cache.',
'bg-success px-2 py-1')
)
);
$result = Command::SUCCESS;
} else {
$output->write(
renderToString(
div('Failure: Data cache wasn\'t cleared.',
'bg-danger px-2 py-1')
)
);
$result = Command::FAILURE;
}
} else {
$output->write(
renderToString(
div('Failure: Data cache directory ' . $routesData . ' doesn\'t exist.',
'bg-danger px-2 py-1')
)
);
$result = Command::FAILURE;
}
return $result;
}
}

View File

@@ -0,0 +1,71 @@
<?php
declare(strict_types=1);
/**
* Flextype - Hybrid Content Management System with the freedom of a headless CMS
* and with the full functionality of a traditional CMS!
*
* Copyright (c) Sergey Romanenko (https://awilum.github.io)
*
* Licensed under The MIT License.
*
* For full copyright and license information, please see the LICENSE
* Redistributions of files must retain the above copyright notice.
*/
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\InputOption;
use function Thermage\div;
use function Thermage\renderToString;
class CacheClearRoutesCommand extends Command
{
protected function configure(): void
{
$this->setName('cache:clear-routes');
$this->setDescription('Clear cache routes.');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$routesPath = PATH['tmp'] . '/routes';
if (filesystem()->directory($routesPath)->exists()) {
if (filesystem()->directory($routesPath)->delete()) {
$output->write(
renderToString(
div('Success: Routes were successfully cleared from the cache.',
'bg-success px-2 py-1')
)
);
$result = Command::SUCCESS;
} else {
$output->write(
renderToString(
div('Failure: Routes cache wasn\'t cleared.',
'bg-danger px-2 py-1')
)
);
$result = Command::FAILURE;
}
} else {
$output->write(
renderToString(
div('Failure: Routes cache directory ' . $routesPath . ' doesn\'t exist.',
'bg-danger px-2 py-1')
)
);
$result = Command::FAILURE;
}
return $result;
}
}

View File

@@ -31,6 +31,9 @@ use Flextype\Console\Commands\Cache\CacheGetMultipleCommand;
use Flextype\Console\Commands\Cache\CacheSetMultipleCommand;
use Flextype\Console\Commands\Cache\CacheDeleteMultipleCommand;
use Flextype\Console\Commands\Cache\CacheClearCommand;
use Flextype\Console\Commands\Cache\CacheClearRoutesCommand;
use Flextype\Console\Commands\Cache\CacheClearConfigCommand;
use Flextype\Console\Commands\Cache\CacheClearDataCommand;
use Flextype\Console\Commands\Cache\CacheHasCommand;
use Flextype\Console\Commands\Utils\GenerateTokenCommand;
use Flextype\Console\Commands\Utils\GenerateTokenHashCommand;
@@ -58,6 +61,9 @@ class FlextypeConsole extends ConsoleApplication
console()->add(new CacheDeleteMultipleCommand());
console()->add(new CacheDeleteCommand());
console()->add(new CacheClearCommand());
console()->add(new CacheClearRoutesCommand());
console()->add(new CacheClearConfigCommand());
console()->add(new CacheClearDataCommand());
console()->add(new CacheHasCommand());
console()->add(new GenerateTokenCommand());
console()->add(new GenerateTokenHashCommand());