setName('cache:clear-routing') ->setDescription('Clears the routing cache') ->setHelp(<<%command.name% command clears the routing application cache for a given environment and debug mode: php %command.full_name% --env=dev php %command.full_name% --env=prod --no-debug 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 %s environment with debug %s', $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('%s removed', $v)); } } }