CreateClassCacheCommand.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. class CreateClassCacheCommand extends ContainerAwareCommand
  16. {
  17. /**
  18. * {@inheritdoc}
  19. */
  20. public function configure()
  21. {
  22. $this->setName('cache:create-cache-class');
  23. $this->setDescription('Generate the classes.php files');
  24. }
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public function execute(InputInterface $input, OutputInterface $output)
  29. {
  30. $kernel = $this->getContainer()->get('kernel');
  31. $classmap = $kernel->getCacheDir().'/classes.map';
  32. if (!is_file($classmap)) {
  33. throw new \RuntimeException(sprintf('The file %s does not exist', $classmap));
  34. }
  35. $name = 'classes';
  36. $extension = '.php';
  37. $output->write('<info>Writing cache file ...</info>');
  38. ClassCollectionLoader::load(
  39. include($classmap),
  40. $kernel->getCacheDir(),
  41. $name,
  42. $kernel->isDebug(),
  43. false,
  44. $extension
  45. );
  46. $output->writeln(' done!');
  47. }
  48. }