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 BucketCreateCommand 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 |
|
|
|
|
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:bucket:create') |
36
|
|
|
->setDescription('Creates a bucket.') |
37
|
|
|
->setHelp('This command creates a bucket on S3.') |
38
|
|
|
->addArgument('bucket', InputArgument::REQUIRED, 'The name of the bucket') |
39
|
|
|
; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
43
|
|
|
{ |
44
|
|
|
$bucket = $input->getArgument('bucket'); |
45
|
|
|
$io = new SymfonyStyle($input, $output); |
46
|
|
|
|
47
|
|
|
try { |
48
|
|
|
if (true === $this->s3Client->createBucketIfItDoesNotExist(['bucket' => $bucket])) { |
49
|
|
|
$io->success('The bucket was successfully created'); |
50
|
|
|
} else { |
51
|
|
|
$io->error('There was an error in creating bucket'); |
52
|
|
|
} |
53
|
|
|
} catch (\Exception $e) { |
54
|
|
|
$io->error($e->getMessage()); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|