diff --git a/src/flextype/core/Console/Commands/Cache/CacheClearCommand.php b/src/flextype/core/Console/Commands/Cache/CacheClearCommand.php index 5cb7481a..14ddac75 100644 --- a/src/flextype/core/Console/Commands/Cache/CacheClearCommand.php +++ b/src/flextype/core/Console/Commands/Cache/CacheClearCommand.php @@ -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; } } \ No newline at end of file diff --git a/src/flextype/core/Console/Commands/Cache/CacheClearConfigCommand.php b/src/flextype/core/Console/Commands/Cache/CacheClearConfigCommand.php new file mode 100644 index 00000000..daaca86c --- /dev/null +++ b/src/flextype/core/Console/Commands/Cache/CacheClearConfigCommand.php @@ -0,0 +1,71 @@ +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; + } +} \ No newline at end of file diff --git a/src/flextype/core/Console/Commands/Cache/CacheClearDataCommand.php b/src/flextype/core/Console/Commands/Cache/CacheClearDataCommand.php new file mode 100644 index 00000000..480aade7 --- /dev/null +++ b/src/flextype/core/Console/Commands/Cache/CacheClearDataCommand.php @@ -0,0 +1,71 @@ +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; + } +} \ No newline at end of file diff --git a/src/flextype/core/Console/Commands/Cache/CacheClearRoutesCommand.php b/src/flextype/core/Console/Commands/Cache/CacheClearRoutesCommand.php new file mode 100644 index 00000000..b14188b5 --- /dev/null +++ b/src/flextype/core/Console/Commands/Cache/CacheClearRoutesCommand.php @@ -0,0 +1,71 @@ +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; + } +} \ No newline at end of file diff --git a/src/flextype/core/Console/FlextypeConsole.php b/src/flextype/core/Console/FlextypeConsole.php index 5082167d..1e439bcc 100644 --- a/src/flextype/core/Console/FlextypeConsole.php +++ b/src/flextype/core/Console/FlextypeConsole.php @@ -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());