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

Commit cab787c

Browse files
committed
Add cache/logs command to console
1 parent 961762e commit cab787c

3 files changed

Lines changed: 37 additions & 3 deletions

File tree

config/dev.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88

99
// enable the debug mode
1010
$app['debug'] = true;
11+
$app['logs.path'] = __DIR__.'/../var/logs/';
1112

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

1617
$app->register(new WebProfilerServiceProvider(), array(
17-
'profiler.cache_dir' => __DIR__.'/../var/cache/profiler',
18+
'profiler.cache_dir' => $app['cache.path'].'profiler',
1819
));

config/prod.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22

33
// configure your app for the production environment
44

5+
$app['cache.path'] = __DIR__.'/../var/cache/';
56
$app['twig.path'] = array(__DIR__.'/../templates');
6-
$app['twig.options'] = array('cache' => __DIR__.'/../var/cache/twig');
7+
$app['twig.options'] = array('cache' => $app['cache.path'].'twig');

src/console.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use Symfony\Component\Console\Output\OutputInterface;
66
use Symfony\Component\Console\Input\InputArgument;
77
use Symfony\Component\Console\Input\InputOption;
8+
use Symfony\Component\Filesystem\Filesystem;
9+
use Symfony\Component\Finder\Finder;
810

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

25+
if (isset($app['cache.path'])) {
26+
$console
27+
->register('cache:clear')
28+
->setDescription('Clears the cache')
29+
->setCode(function (InputInterface $input, OutputInterface $output) use ($app) {
30+
$cacheDir = $app['cache.path'];
31+
$finder = Finder::create()->in($cacheDir)->notName('.gitkeep');
32+
$filesystem = new Filesystem();
33+
$filesystem->remove($finder);
34+
35+
$output->writeln(sprintf('%s <info>success</info>', 'cache:clear'));
36+
})
37+
;
38+
}
39+
40+
if (isset($app['logs.path'])) {
41+
$console
42+
->register('logs:clear')
43+
->setDescription('Clears the logs')
44+
->setCode(function (InputInterface $input, OutputInterface $output) use ($app) {
45+
$cacheDir = $app['logs.path'];
46+
$finder = Finder::create()->in($cacheDir)->notName('.gitkeep');
47+
$filesystem = new Filesystem();
48+
$filesystem->remove($finder);
49+
50+
$output->writeln(sprintf('%s <info>success</info>', 'logs:clear'));
51+
})
52+
;
53+
}
54+
2355
return $console;

0 commit comments

Comments
 (0)