CreateClassCacheCommand.php 1.6 KB

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