Skip to content

Commit

Permalink
Updated the style for the "cache:clear" command
Browse files Browse the repository at this point in the history
  • Loading branch information
javiereguiluz committed Sep 28, 2015
1 parent 3c19ae0 commit 08b2959
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php
Expand Up @@ -14,6 +14,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Finder\Finder;

Expand Down Expand Up @@ -53,6 +54,9 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$outputIsVerbose = $output->isVerbose();
$output = new SymfonyStyle($input, $output);

$realCacheDir = $this->getContainer()->getParameter('kernel.cache_dir');
$oldCacheDir = $realCacheDir.'_old';
$filesystem = $this->getContainer()->get('filesystem');
Expand All @@ -66,7 +70,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

$kernel = $this->getContainer()->get('kernel');
$output->writeln(sprintf('Clearing the cache for the <info>%s</info> environment with debug <info>%s</info>', $kernel->getEnvironment(), var_export($kernel->isDebug(), true)));
$output->comment(sprintf('Clearing the cache for the <info>%s</info> environment with debug <info>%s</info>', $kernel->getEnvironment(), var_export($kernel->isDebug(), true)));
$this->getContainer()->get('cache_clearer')->clear($realCacheDir);

if ($input->getOption('no-warmup')) {
Expand All @@ -78,14 +82,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
$warmupDir = substr($realCacheDir, 0, -1).'_';

if ($filesystem->exists($warmupDir)) {
if ($output->isVerbose()) {
$output->writeln(' Clearing outdated warmup directory');
if ($outputIsVerbose) {
$output->comment('Clearing outdated warmup directory...');
}
$filesystem->remove($warmupDir);
}

if ($output->isVerbose()) {
$output->writeln(' Warming up cache');
if ($outputIsVerbose) {
$output->comment('Warming up cache...');
}
$this->warmup($warmupDir, $realCacheDir, !$input->getOption('no-optional-warmers'));

Expand All @@ -96,15 +100,17 @@ protected function execute(InputInterface $input, OutputInterface $output)
$filesystem->rename($warmupDir, $realCacheDir);
}

if ($output->isVerbose()) {
$output->writeln(' Removing old cache directory');
if ($outputIsVerbose) {
$output->comment('Removing old cache directory...');
}

$filesystem->remove($oldCacheDir);

if ($output->isVerbose()) {
$output->writeln(' Done');
if ($outputIsVerbose) {
$output->comment('Finished');
}

$output->success(sprintf('Cache for the "%s" environment (debug=%s) was succesfully cleared.', $kernel->getEnvironment(), var_export($kernel->isDebug(), true)));
}

/**
Expand Down

0 comments on commit 08b2959

Please sign in to comment.