Skip to content
This repository has been archived by the owner on Sep 14, 2018. It is now read-only.

Commit

Permalink
Add cache/logs command to console
Browse files Browse the repository at this point in the history
  • Loading branch information
jnadaud committed Nov 25, 2016
1 parent 961762e commit d1d6498
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
5 changes: 3 additions & 2 deletions config/dev.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@

// enable the debug mode
$app['debug'] = true;
$app['logs.path'] = __DIR__.'/../var/logs/';

$app->register(new MonologServiceProvider(), array(
'monolog.logfile' => __DIR__.'/../var/logs/silex_dev.log',
'monolog.logfile' => $app['logs.path'].'silex_dev.log',
));

$app->register(new WebProfilerServiceProvider(), array(
'profiler.cache_dir' => __DIR__.'/../var/cache/profiler',
'profiler.cache_dir' => $app['cache.path'].'profiler',
));
3 changes: 2 additions & 1 deletion config/prod.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

// configure your app for the production environment

$app['cache.path'] = __DIR__.'/../var/cache/';
$app['twig.path'] = array(__DIR__.'/../templates');
$app['twig.options'] = array('cache' => __DIR__.'/../var/cache/twig');
$app['twig.options'] = array('cache' => $app['cache.path'].'twig');
32 changes: 32 additions & 0 deletions src/console.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;

$console = new Application('My Silex Application', 'n/a');
$console->getDefinition()->addOption(new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', 'dev'));
Expand All @@ -20,4 +22,34 @@
})
;

if (isset($app['cache.path'])) {
$console
->register('cache:clear')
->setDescription('Clears the cache')
->setCode(function (InputInterface $input, OutputInterface $output) use ($app) {
$cacheDir = $app['cache.path'];
$finder = Finder::create()->in($cacheDir)->notName('.gitkeep');
$filesystem = new Filesystem();
$filesystem->remove($finder);

$output->writeln(sprintf("%s <info>success</info>", 'cache:clear'));
})
;
}

if (isset($app['logs.path'])) {
$console
->register('logs:clear')
->setDescription('Clears the logs')
->setCode(function (InputInterface $input, OutputInterface $output) use ($app) {
$cacheDir = $app['logs.path'];
$finder = Finder::create()->in($cacheDir)->notName('.gitkeep');
$filesystem = new Filesystem();
$filesystem->remove($finder);

$output->writeln(sprintf("%s <info>success</info>", 'cache:clear'));
})
;
}

return $console;

0 comments on commit d1d6498

Please sign in to comment.