CacheClearAllCommand.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  5. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  6. *
  7. * Licensed under The MIT License
  8. * For full copyright and license information, please see the LICENSE.txt
  9. * Redistributions of files must retain the above copyright notice.
  10. *
  11. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  12. * @link https://cakephp.org CakePHP(tm) Project
  13. * @since 4.0.0
  14. * @license https://opensource.org/licenses/mit-license.php MIT License
  15. */
  16. namespace Cake\Command;
  17. use Cake\Cache\Cache;
  18. use Cake\Console\Arguments;
  19. use Cake\Console\Command;
  20. use Cake\Console\ConsoleIo;
  21. use Cake\Console\ConsoleOptionParser;
  22. /**
  23. * CacheClearAll command.
  24. */
  25. class CacheClearAllCommand extends Command
  26. {
  27. /**
  28. * Hook method for defining this command's option parser.
  29. *
  30. * @see https://book.cakephp.org/3.0/en/console-and-shells/commands.html#defining-arguments-and-options
  31. *
  32. * @param \Cake\Console\ConsoleOptionParser $parser The parser to be defined
  33. * @return \Cake\Console\ConsoleOptionParser The built parser.
  34. */
  35. public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser
  36. {
  37. $parser = parent::buildOptionParser($parser);
  38. $parser->setDescription('Clear all data in all configured cache engines.');
  39. return $parser;
  40. }
  41. /**
  42. * Implement this method with your command's logic.
  43. *
  44. * @param \Cake\Console\Arguments $args The command arguments.
  45. * @param \Cake\Console\ConsoleIo $io The console io
  46. * @return null|int The exit code or null for success
  47. */
  48. public function execute(Arguments $args, ConsoleIo $io): ?int
  49. {
  50. $engines = Cache::configured();
  51. foreach ($engines as $engine) {
  52. $this->executeCommand(CacheClearCommand::class, [$engine], $io);
  53. }
  54. return static::CODE_SUCCESS;
  55. }
  56. }