Clear.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: liu21st <liu21st@gmail.com>
  10. // +----------------------------------------------------------------------
  11. namespace think\console\command;
  12. use think\console\Command;
  13. use think\console\Input;
  14. use think\console\input\Option;
  15. use think\console\Output;
  16. class Clear extends Command
  17. {
  18. protected function configure()
  19. {
  20. // 指令配置
  21. $this
  22. ->setName('clear')
  23. ->addOption('path', 'd', Option::VALUE_OPTIONAL, 'path to clear', null)
  24. ->setDescription('Clear runtime file');
  25. }
  26. protected function execute(Input $input, Output $output)
  27. {
  28. $path = $input->getOption('path') ?: RUNTIME_PATH;
  29. $files = scandir($path);
  30. if ($files) {
  31. foreach ($files as $file) {
  32. if ('.' != $file && '..' != $file && is_dir($path . $file)) {
  33. array_map('unlink', glob($path . $file . '/*.*'));
  34. } elseif (is_file($path . $file)) {
  35. unlink($path . $file);
  36. }
  37. }
  38. }
  39. $output->writeln("<info>Clear Successed</info>");
  40. }
  41. }