57 lines
1.8 KiB
PHP
57 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace Trinity\Bundle\ContentManagerBundle\Command;
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
use Symfony\Component\Finder\Finder;
|
|
use Symfony\Component\Filesystem\Filesystem;
|
|
|
|
class CacheClearRoutingCommand extends ContainerAwareCommand
|
|
{
|
|
protected function configure()
|
|
{
|
|
$this
|
|
->setName('cache:clear-routing')
|
|
->setDescription('Clears the routing cache')
|
|
->setHelp(<<<EOF
|
|
The <info>%command.name%</info> command clears the routing application cache for a given environment
|
|
and debug mode:
|
|
|
|
<info>php %command.full_name% --env=dev</info>
|
|
<info>php %command.full_name% --env=prod --no-debug</info>
|
|
EOF
|
|
)
|
|
;
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
|
{
|
|
$realCacheDir = $this->getContainer()->getParameter('kernel.cache_dir');
|
|
|
|
if (!is_writable($realCacheDir)) {
|
|
throw new \RuntimeException(sprintf('Unable to write in the "%s" directory', $realCacheDir));
|
|
}
|
|
|
|
$kernel = $this->getContainer()->get('kernel');
|
|
|
|
$output->writeln(sprintf(
|
|
'Clearing the cache for the routing <info>%s</info> environment with debug <info>%s</info>',
|
|
$kernel->getEnvironment(),
|
|
var_export($kernel->isDebug(), true)
|
|
));
|
|
|
|
$finder = new Finder();
|
|
$files = $finder->name('*Url*')->in(sprintf('%s/../', $realCacheDir))->depth('== 1');
|
|
|
|
foreach ($files as $k => $v) {
|
|
$this->getContainer()->get('filesystem')->remove($v);
|
|
$output->writeln(sprintf('<comment>%s</comment> removed', $v));
|
|
}
|
|
}
|
|
}
|