1 | <?php |
||
2 | |||
3 | namespace Matecat\SimpleS3\Console; |
||
4 | |||
5 | use Matecat\SimpleS3\Client; |
||
6 | use Symfony\Component\Console\Command\Command; |
||
7 | use Symfony\Component\Console\Input\InputArgument; |
||
8 | use Symfony\Component\Console\Input\InputInterface; |
||
9 | use Symfony\Component\Console\Output\OutputInterface; |
||
10 | use Symfony\Component\Console\Style\SymfonyStyle; |
||
11 | |||
12 | class ItemDeleteCommand extends Command |
||
13 | { |
||
14 | /** |
||
15 | * @var Client |
||
16 | */ |
||
17 | private $s3Client; |
||
18 | |||
19 | /** |
||
20 | * CacheFlushCommand constructor. |
||
21 | * |
||
22 | * @param Client $s3Client |
||
23 | * @param null $name |
||
0 ignored issues
–
show
Documentation
Bug
introduced
by
![]() |
|||
24 | */ |
||
25 | public function __construct(Client $s3Client, $name = null) |
||
26 | { |
||
27 | parent::__construct($name); |
||
28 | |||
29 | $this->s3Client = $s3Client; |
||
30 | } |
||
31 | |||
32 | protected function configure() |
||
33 | { |
||
34 | $this |
||
35 | ->setName('ss3:item:delete') |
||
36 | ->setDescription('Deletes an object from a bucket.') |
||
37 | ->setHelp('This command allows you to delete an object from a S3 bucket.') |
||
38 | ->addArgument('bucket', InputArgument::REQUIRED, 'The name of the bucket') |
||
39 | ->addArgument('key', InputArgument::REQUIRED, 'The desired keyname') |
||
40 | ; |
||
41 | } |
||
42 | |||
43 | protected function execute(InputInterface $input, OutputInterface $output) |
||
44 | { |
||
45 | $bucket = $input->getArgument('bucket'); |
||
46 | $key = $input->getArgument('key'); |
||
47 | $io = new SymfonyStyle($input, $output); |
||
48 | |||
49 | try { |
||
50 | if (true === $this->s3Client->deleteItem(['bucket' => $bucket, 'key' => $key])) { |
||
51 | $io->success('The item was successfully cleared'); |
||
52 | } else { |
||
53 | $io->error('There was an error in deleting the item'); |
||
54 | } |
||
55 | } catch (\Exception $e) { |
||
56 | $io->error($e->getMessage()); |
||
57 | } |
||
58 | } |
||
59 | } |
||
60 |