CreateClassCacheCommand.php 1.6 KB

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