forked from php-opencloud/openstack
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathService.php
More file actions
89 lines (79 loc) · 2.42 KB
/
Copy pathService.php
File metadata and controls
89 lines (79 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
declare(strict_types=1);
namespace OpenStack\ObjectStore\v1;
use OpenStack\Common\Error\BadResponseError;
use OpenStack\Common\Service\AbstractService;
use OpenStack\ObjectStore\v1\Models\Account;
use OpenStack\ObjectStore\v1\Models\Container;
/**
* @property \OpenStack\ObjectStore\v1\Api $api
*/
class Service extends AbstractService
{
/**
* Retrieves an Account object.
*
* @return Account
*/
public function getAccount(): Account
{
return $this->model(Account::class);
}
/**
* Retrieves a collection of container resources in a generator format.
*
* @param array $options {@see \OpenStack\ObjectStore\v1\Api::getAccount}
* @param callable|null $mapFn allows a function to be mapped over each element in the collection
*
* @return \Generator
*/
public function listContainers(array $options = [], callable $mapFn = null): \Generator
{
$options = array_merge($options, ['format' => 'json']);
return $this->model(Container::class)->enumerate($this->api->getAccount(), $options, $mapFn);
}
/**
* Retrieves a Container object and populates its name according to the value provided. Please note that the
* remote API is not contacted.
*
* @param string $name The unique name of the container
*
* @return Container
*/
public function getContainer(string $name = null): Container
{
return $this->model(Container::class, ['name' => $name]);
}
/**
* Creates a new container according to the values provided.
*
* @param array $data {@see \OpenStack\ObjectStore\v1\Api::putContainer}
*
* @return Container
*/
public function createContainer(array $data): Container
{
return $this->getContainer()->create($data);
}
/**
* Checks the existence of a container.
*
* @param string $name The name of the container
*
* @return bool TRUE if exists, FALSE if it doesn't
*
* @throws BadResponseError Thrown for any non 404 status error
*/
public function containerExists(string $name): bool
{
try {
$this->execute($this->api->headContainer(), ['name' => $name]);
return true;
} catch (BadResponseError $e) {
if (404 === $e->getResponse()->getStatusCode()) {
return false;
}
throw $e;
}
}
}