ClearResultCacheDoctrineCommand.php 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  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 Symfony\Bundle\DoctrineBundle\Command\Proxy;
  11. use Symfony\Component\Console\Input\InputOption;
  12. use Symfony\Component\Console\Input\InputInterface;
  13. use Symfony\Component\Console\Output\OutputInterface;
  14. use Doctrine\ORM\Tools\Console\Command\ClearCache\ResultCommand;
  15. /**
  16. * Command to clear the result cache of the various cache drivers.
  17. *
  18. * @author Fabien Potencier <fabien@symfony.com>
  19. * @author Jonathan H. Wage <jonwage@gmail.com>
  20. */
  21. class ClearResultCacheDoctrineCommand extends ResultCommand
  22. {
  23. protected function configure()
  24. {
  25. parent::configure();
  26. $this
  27. ->setName('doctrine:cache:clear-result')
  28. ->setDescription('Clears result cache for a entity manager')
  29. ->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command')
  30. ->setHelp(<<<EOT
  31. The <info>doctrine:cache:clear-result</info> command clears all result cache
  32. for the default entity manager:
  33. <info>php app/console doctrine:cache:clear-result</info>
  34. You can also optionally specify the <comment>--em</comment> option to specify
  35. which entity manager to clear the cache for:
  36. <info>php app/console doctrine:cache:clear-result --em=default</info>
  37. If you don't want to clear all result cache you can specify some additional
  38. options to control what cache is deleted:
  39. <info>php app/console doctrine:cache:clear-result --id=cache_key</info>
  40. Or you can specify a <comment>--regex</comment> to delete cache entries that
  41. match it:
  42. <info>php app/console doctrine:cache:clear-result --regex="user_(.*)"</info>
  43. You can also specify a <comment>--prefix</comment> or
  44. <comment>--suffix</comment> to delete cache entries for:
  45. <info>php app/console doctrine:cache:clear-result --prefix="user_" --suffix="_frontend"</info>
  46. EOT
  47. );
  48. }
  49. protected function execute(InputInterface $input, OutputInterface $output)
  50. {
  51. DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));
  52. return parent::execute($input, $output);
  53. }
  54. }