CreateClassCacheCommand.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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\InputArgument;
  13. use Symfony\Component\Console\Input\InputOption;
  14. use Symfony\Component\Console\Input\InputInterface;
  15. use Symfony\Component\Console\Output\OutputInterface;
  16. use Symfony\Component\Console\Output\Output;
  17. use Symfony\Component\ClassLoader\ClassCollectionLoader;
  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. }