CreateClassCacheCommand.php 1.5 KB

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