Просмотр файла app/Commands/ImageClear.php

Размер файла: 1Kb
  1. <?php
  2.  
  3. declare(strict_types=1);
  4.  
  5. namespace App\Commands;
  6.  
  7. use Phinx\Console\Command\AbstractCommand;
  8. use Symfony\Component\Console\Input\InputInterface;
  9. use Symfony\Component\Console\Output\OutputInterface;
  10.  
  11. class ImageClear extends AbstractCommand
  12. {
  13. /**
  14. * {@inheritdoc}
  15. */
  16. protected function configure(): void
  17. {
  18. parent::configure();
  19.  
  20. $this->setName('image:clear')
  21. ->setDescription('Flush the application image thumbnails');
  22. }
  23.  
  24. /**
  25. * Cache cleared
  26. *
  27. * @param InputInterface $input
  28. * @param OutputInterface $output
  29. *
  30. * @return int
  31. */
  32. protected function execute(InputInterface $input, OutputInterface $output): int
  33. {
  34. $images = glob(UPLOADS . '/thumbnails/*.{gif,png,jpg,jpeg}', GLOB_BRACE);
  35.  
  36. if ($images) {
  37. foreach ($images as $image) {
  38. unlink($image);
  39. }
  40. }
  41.  
  42. $output->writeln('<info>Image cleared successfully.</info>');
  43.  
  44. return 0;
  45. }
  46. }