1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace OpenStack\ObjectStore\v1\Models; |
4
|
|
|
|
5
|
|
|
use OpenStack\Common\Resource\OperatorResource; |
6
|
|
|
use OpenStack\Common\Resource\HasMetadata; |
7
|
|
|
use OpenStack\Common\Resource\Retrievable; |
8
|
|
|
use Psr\Http\Message\ResponseInterface; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @property \OpenStack\ObjectStore\v1\Api $api |
12
|
|
|
*/ |
13
|
|
|
class Account extends OperatorResource implements Retrievable, HasMetadata |
14
|
|
|
{ |
15
|
|
|
use MetadataTrait; |
16
|
|
|
|
17
|
|
|
const METADATA_PREFIX = 'X-Account-Meta-'; |
18
|
|
|
|
19
|
|
|
/** @var int */ |
20
|
|
|
public $objectCount; |
21
|
|
|
|
22
|
|
|
/** @var int */ |
23
|
|
|
public $bytesUsed; |
24
|
|
|
|
25
|
|
|
/** @var int */ |
26
|
|
|
public $containerCount; |
27
|
|
|
|
28
|
|
|
/** @var array */ |
29
|
|
|
public $metadata; |
30
|
|
|
|
31
|
|
|
/** @var string */ |
32
|
|
|
public $tempUrl; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* {@inheritdoc} |
36
|
|
|
*/ |
37
|
2 |
View Code Duplication |
public function populateFromResponse(ResponseInterface $response): self |
|
|
|
|
38
|
|
|
{ |
39
|
2 |
|
parent::populateFromResponse($response); |
40
|
|
|
|
41
|
2 |
|
$this->containerCount = $response->getHeaderLine('X-Account-Container-Count'); |
|
|
|
|
42
|
2 |
|
$this->objectCount = $response->getHeaderLine('X-Account-Object-Count'); |
|
|
|
|
43
|
2 |
|
$this->bytesUsed = $response->getHeaderLine('X-Account-Bytes-Used'); |
|
|
|
|
44
|
2 |
|
$this->tempUrl = $response->getHeaderLine('X-Account-Meta-Temp-URL-Key'); |
45
|
2 |
|
$this->metadata = $this->parseMetadata($response); |
46
|
2 |
|
|
47
|
|
|
return $this; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
1 |
|
* {@inheritdoc} |
52
|
|
|
*/ |
53
|
1 |
|
public function retrieve() |
54
|
1 |
|
{ |
55
|
1 |
|
$response = $this->execute($this->api->headAccount()); |
56
|
|
|
$this->populateFromResponse($response); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
1 |
|
* {@inheritdoc} |
61
|
|
|
*/ |
62
|
1 |
|
public function mergeMetadata(array $metadata) |
63
|
1 |
|
{ |
64
|
|
|
$response = $this->execute($this->api->postAccount(), ['metadata' => $metadata]); |
65
|
|
|
$this->metadata = $this->parseMetadata($response); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
1 |
|
* {@inheritdoc} |
70
|
|
|
*/ |
71
|
|
View Code Duplication |
public function resetMetadata(array $metadata) |
|
|
|
|
72
|
1 |
|
{ |
73
|
1 |
|
$options = [ |
74
|
1 |
|
'removeMetadata' => [], |
75
|
|
|
'metadata' => $metadata, |
76
|
1 |
|
]; |
77
|
1 |
|
|
78
|
1 |
|
foreach ($this->getMetadata() as $key => $val) { |
79
|
1 |
|
if (!array_key_exists($key, $metadata)) { |
80
|
1 |
|
$options['removeMetadata'][$key] = 'True'; |
81
|
|
|
} |
82
|
1 |
|
} |
83
|
1 |
|
|
84
|
|
|
$response = $this->execute($this->api->postAccount(), $options); |
85
|
|
|
$this->metadata = $this->parseMetadata($response); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
2 |
|
* {@inheritdoc} |
90
|
|
|
*/ |
91
|
2 |
|
public function getMetadata(): array |
92
|
2 |
|
{ |
93
|
|
|
$response = $this->execute($this->api->headAccount()); |
94
|
|
|
return $this->parseMetadata($response); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.