diff --git a/config/dev.php b/config/dev.php
index a8a9f76..d7da37a 100644
--- a/config/dev.php
+++ b/config/dev.php
@@ -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',
));
diff --git a/config/prod.php b/config/prod.php
index 26a5a51..e84db60 100644
--- a/config/prod.php
+++ b/config/prod.php
@@ -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');
diff --git a/src/console.php b/src/console.php
index 465e14f..5d2c0c0 100644
--- a/src/console.php
+++ b/src/console.php
@@ -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'));
@@ -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 success', '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 success', 'logs:clear'));
+ })
+ ;
+}
+
return $console;