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

Add cache/logs command to console #74

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Silex-Skeleton uses .gitignore in both cache and logs directories.

$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>', 'logs:clear'));
})
;
}

return $console;