DumpRoutesCommand.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. class DumpRoutesCommand extends ContainerAwareCommand
  16. {
  17. /**
  18. * {@inheritDoc}
  19. */
  20. public function configure()
  21. {
  22. $this->setName('sonata:admin:dump-routes');
  23. $this->setDescription('Dump route information to improve performance');
  24. }
  25. /**
  26. * {@inheritDoc}
  27. */
  28. public function execute(InputInterface $input, OutputInterface $output)
  29. {
  30. $output->write("Starting dumping cache file");
  31. $pool = $this->getContainer()->get('sonata.admin.pool');
  32. $cache = $this->getContainer()->get('sonata.admin.route.cache');
  33. foreach ($pool->getAdminServiceIds() as $id) {
  34. $output->writeln(sprintf(' > Generate routes cache for <info>%s</info>', $id));
  35. $routes = $cache->load($pool->getInstance($id));
  36. $output->writeln(sprintf(' Load %d routes', count($routes)));
  37. }
  38. $output->write("done!");
  39. }
  40. }