|
5 | 5 | use Symfony\Component\Console\Output\OutputInterface; |
6 | 6 | use Symfony\Component\Console\Input\InputArgument; |
7 | 7 | use Symfony\Component\Console\Input\InputOption; |
| 8 | +use Symfony\Component\Filesystem\Filesystem; |
| 9 | +use Symfony\Component\Finder\Finder; |
8 | 10 |
|
9 | 11 | $console = new Application('My Silex Application', 'n/a'); |
10 | 12 | $console->getDefinition()->addOption(new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', 'dev')); |
|
20 | 22 | }) |
21 | 23 | ; |
22 | 24 |
|
| 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 | + |
23 | 55 | return $console; |
0 commit comments