GearmanCacheClearCommand.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * Gearman Bundle for Symfony2
  4. *
  5. * For the full copyright and license information, please view the LICENSE
  6. * file that was distributed with this source code.
  7. *
  8. * Feel free to edit as you please, and have fun.
  9. *
  10. * @author Marc Morera <yuhu@mmoreram.com>
  11. */
  12. namespace Mmoreram\GearmanBundle\Command;
  13. use Symfony\Component\Console\Input\InputInterface;
  14. use Symfony\Component\Console\Output\OutputInterface;
  15. use Mmoreram\GearmanBundle\Command\Abstracts\AbstractGearmanCommand;
  16. use Mmoreram\GearmanBundle\Service\GearmanCacheWrapper;
  17. /**
  18. * Clears all cache data
  19. *
  20. * @since 2.3.1
  21. */
  22. class GearmanCacheClearCommand extends AbstractGearmanCommand
  23. {
  24. /**
  25. * @var GearmanCacheWrapper
  26. *
  27. * GearmanCacheWrapper
  28. */
  29. protected $gearmanCacheWrapper;
  30. /**
  31. * Set the GearmanCacheWrapper instance
  32. *
  33. * @param GearmanCacheWrapper $gearmanCacheWrapper GearmanCacheWrapper
  34. *
  35. * @return GearmanCacheWarmupCommand self Object
  36. */
  37. public function setGearmanCacheWrapper(GearmanCacheWrapper $gearmanCacheWrapper)
  38. {
  39. $this->gearmanCacheWrapper = $gearmanCacheWrapper;
  40. return $this;
  41. }
  42. /**
  43. * Console Command configuration
  44. */
  45. protected function configure()
  46. {
  47. $this
  48. ->setName('gearman:cache:clear')
  49. ->setAliases(array(
  50. 'cache:gearman:clear'
  51. ))
  52. ->setDescription('Clears gearman cache data on current environment');
  53. }
  54. /**
  55. * Executes the current command.
  56. *
  57. * @param InputInterface $input An InputInterface instance
  58. * @param OutputInterface $output An OutputInterface instance
  59. *
  60. * @return integer 0 if everything went fine, or an error code
  61. *
  62. * @throws \LogicException When this abstract class is not implemented
  63. */
  64. protected function execute(InputInterface $input, OutputInterface $output)
  65. {
  66. if (
  67. !$input->getOption('quiet')
  68. ) {
  69. $kernelEnvironment = $this
  70. ->kernel
  71. ->getEnvironment();
  72. $output->writeln('Clearing the cache for the ' . $kernelEnvironment . ' environment');
  73. }
  74. $this
  75. ->gearmanCacheWrapper
  76. ->clear('');
  77. }
  78. }