CreateClassCacheCommand.php 1.6 KB

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