CreateClassCacheCommand.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /*
  3. * This file is part of the Sonata Project package.
  4. *
  5. * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Sonata\AdminBundle\Command;
  11. use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
  12. use Symfony\Component\ClassLoader\ClassCollectionLoader;
  13. use Symfony\Component\Console\Input\InputInterface;
  14. use Symfony\Component\Console\Output\OutputInterface;
  15. /**
  16. * @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
  17. */
  18. class CreateClassCacheCommand extends ContainerAwareCommand
  19. {
  20. /**
  21. * {@inheritdoc}
  22. */
  23. public function configure()
  24. {
  25. $this->setName('cache:create-cache-class');
  26. $this->setDescription('Generate the classes.php files');
  27. }
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public function execute(InputInterface $input, OutputInterface $output)
  32. {
  33. $kernel = $this->getContainer()->get('kernel');
  34. $classmap = $kernel->getCacheDir().'/classes.map';
  35. if (!is_file($classmap)) {
  36. throw new \RuntimeException(sprintf('The file %s does not exist', $classmap));
  37. }
  38. $name = 'classes';
  39. $extension = '.php';
  40. $output->write('<info>Writing cache file ...</info>');
  41. ClassCollectionLoader::load(
  42. include($classmap),
  43. $kernel->getCacheDir(),
  44. $name,
  45. $kernel->isDebug(),
  46. false,
  47. $extension
  48. );
  49. $output->writeln(' done!');
  50. }
  51. }