PageRenderTime 66ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/doctrine/doctrine-cache-bundle/Doctrine/Bundle/DoctrineCacheBundle/Command/DeleteCommand.php

https://gitlab.com/ineszribi/SmartBookStoreWeb
PHP | 64 lines | 43 code | 10 blank | 11 comment | 6 complexity | 2c54f5fc1b0da99ad64b82137f0f012c MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. namespace Doctrine\Bundle\DoctrineCacheBundle\Command;
  3. use Symfony\Component\Console\Input\InputArgument;
  4. use Symfony\Component\Console\Input\InputInterface;
  5. use Symfony\Component\Console\Input\InputOption;
  6. use Symfony\Component\Console\Output\OutputInterface;
  7. /**
  8. * Delete cache entries.
  9. *
  10. * @author Alan Doucette <dragonwize@gmail.com>
  11. */
  12. class DeleteCommand extends CacheCommand
  13. {
  14. /**
  15. * {@inheritdoc}
  16. */
  17. protected function configure()
  18. {
  19. $this->setName('doctrine:cache:delete')
  20. ->setDescription('Delete a cache entry')
  21. ->addArgument('cache-name', InputArgument::REQUIRED, 'Which cache provider to use?')
  22. ->addArgument('cache-id', InputArgument::OPTIONAL, 'Which cache ID to delete?')
  23. ->addOption('all', 'a', InputOption::VALUE_NONE, 'Delete all cache entries in provider');
  24. }
  25. /**
  26. * {@inheritdoc}
  27. */
  28. protected function execute(InputInterface $input, OutputInterface $output)
  29. {
  30. $cacheName = $input->getArgument('cache-name');
  31. $cacheProvider = $this->getCacheProvider($cacheName);
  32. $cacheId = $input->getArgument('cache-id');
  33. $all = $input->getOption('all');
  34. if ($all && ! method_exists($cacheProvider, 'deleteAll')) {
  35. throw new \RuntimeException('Cache provider does not implement a deleteAll method.');
  36. }
  37. if ( ! $all && ! $cacheId) {
  38. throw new \InvalidArgumentException('Missing cache ID');
  39. }
  40. $success = $all ? $cacheProvider->deleteAll() : $cacheProvider->delete($cacheId);
  41. $color = $success ? 'info' : 'error';
  42. $success = $success ? 'succeeded' : 'failed';
  43. $message = null;
  44. if ( ! $all) {
  45. $message = "Deletion of <$color>%s</$color> in <$color>%s</$color> has <$color>%s</$color>";
  46. $message = sprintf($message, $cacheId, $cacheName, $success, true);
  47. }
  48. if ($all) {
  49. $message = "Deletion of <$color>all</$color> entries in <$color>%s</$color> has <$color>%s</$color>";
  50. $message = sprintf($message, $cacheName, $success, true);
  51. }
  52. $output->writeln($message);
  53. }
  54. }