|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace OpenStack\Identity\v3\Models; |
|
4
|
|
|
|
|
5
|
|
|
use OpenStack\Common\Error\BadResponseError; |
|
6
|
|
|
use OpenStack\Common\Resource\OperatorResource; |
|
7
|
|
|
use OpenStack\Common\Resource\Creatable; |
|
8
|
|
|
use OpenStack\Common\Resource\Deletable; |
|
9
|
|
|
use OpenStack\Common\Resource\Listable; |
|
10
|
|
|
use OpenStack\Common\Resource\Retrievable; |
|
11
|
|
|
use OpenStack\Common\Resource\Updateable; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @property \OpenStack\Identity\v3\Api $api |
|
15
|
|
|
*/ |
|
16
|
|
|
class Domain extends OperatorResource implements Creatable, Listable, Retrievable, Updateable, Deletable |
|
17
|
|
|
{ |
|
18
|
|
|
/** @var string */ |
|
19
|
|
|
public $id; |
|
20
|
|
|
|
|
21
|
|
|
/** @var string */ |
|
22
|
|
|
public $name; |
|
23
|
|
|
|
|
24
|
|
|
/** @var array */ |
|
25
|
|
|
public $links; |
|
26
|
|
|
|
|
27
|
|
|
/** @var bool */ |
|
28
|
|
|
public $enabled; |
|
29
|
|
|
|
|
30
|
|
|
/** @var string */ |
|
31
|
|
|
public $description; |
|
32
|
|
|
|
|
33
|
|
|
protected $resourceKey = 'domain'; |
|
34
|
|
|
protected $resourcesKey = 'domains'; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* {@inheritDoc} |
|
38
|
|
|
* |
|
39
|
|
|
* @param array $data {@see \OpenStack\Identity\v3\Api::postDomains} |
|
40
|
|
|
*/ |
|
41
|
1 |
|
public function create(array $data): Creatable |
|
42
|
|
|
{ |
|
43
|
1 |
|
$response = $this->execute($this->api->postDomains(), $data); |
|
44
|
1 |
|
return $this->populateFromResponse($response); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* {@inheritDoc} |
|
49
|
|
|
*/ |
|
50
|
1 |
|
public function retrieve() |
|
51
|
|
|
{ |
|
52
|
1 |
|
$response = $this->executeWithState($this->api->getDomain()); |
|
53
|
1 |
|
$this->populateFromResponse($response); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* {@inheritDoc} |
|
58
|
|
|
*/ |
|
59
|
1 |
|
public function update() |
|
60
|
|
|
{ |
|
61
|
1 |
|
$response = $this->executeWithState($this->api->patchDomain()); |
|
62
|
1 |
|
$this->populateFromResponse($response); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* {@inheritDoc} |
|
67
|
|
|
*/ |
|
68
|
1 |
|
public function delete() |
|
69
|
|
|
{ |
|
70
|
1 |
|
$this->executeWithState($this->api->deleteDomain()); |
|
71
|
1 |
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @param array $options {@see \OpenStack\Identity\v3\Api::getUserRoles} |
|
75
|
|
|
* |
|
76
|
|
|
* @return \Generator |
|
77
|
|
|
*/ |
|
78
|
1 |
|
public function listUserRoles(array $options = []): \Generator |
|
79
|
|
|
{ |
|
80
|
1 |
|
$options['domainId'] = $this->id; |
|
81
|
1 |
|
return $this->model(Role::class)->enumerate($this->api->getUserRoles(), $options); |
|
|
|
|
|
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @param array $options {@see \OpenStack\Identity\v3\Api::putUserRoles} |
|
86
|
|
|
*/ |
|
87
|
1 |
|
public function grantUserRole(array $options = []) |
|
88
|
|
|
{ |
|
89
|
1 |
|
$this->execute($this->api->putUserRoles(), ['domainId' => $this->id] + $options); |
|
90
|
1 |
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @param array $options {@see \OpenStack\Identity\v3\Api::headUserRole} |
|
94
|
|
|
* |
|
95
|
|
|
* @return bool |
|
96
|
|
|
*/ |
|
97
|
3 |
View Code Duplication |
public function checkUserRole(array $options = []): bool |
|
|
|
|
|
|
98
|
|
|
{ |
|
99
|
|
|
try { |
|
100
|
3 |
|
$this->execute($this->api->headUserRole(), ['domainId' => $this->id] + $options); |
|
101
|
1 |
|
return true; |
|
102
|
1 |
|
} catch (BadResponseError $e) { |
|
103
|
1 |
|
return false; |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @param array $options {@see \OpenStack\Identity\v3\Api::deleteUserRole} |
|
109
|
|
|
*/ |
|
110
|
1 |
|
public function revokeUserRole(array $options = []) |
|
111
|
|
|
{ |
|
112
|
1 |
|
$this->execute($this->api->deleteUserRole(), ['domainId' => $this->id] + $options); |
|
113
|
1 |
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* @param array $options {@see \OpenStack\Identity\v3\Api::getGroupRoles} |
|
117
|
|
|
* |
|
118
|
|
|
* @return \Generator |
|
119
|
|
|
*/ |
|
120
|
1 |
|
public function listGroupRoles(array $options = []): \Generator |
|
121
|
|
|
{ |
|
122
|
1 |
|
$options['domainId'] = $this->id; |
|
123
|
1 |
|
return $this->model(Role::class)->enumerate($this->api->getGroupRoles(), $options); |
|
|
|
|
|
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* @param array $options {@see \OpenStack\Identity\v3\Api::putGroupRole} |
|
128
|
|
|
*/ |
|
129
|
1 |
|
public function grantGroupRole(array $options = []) |
|
130
|
|
|
{ |
|
131
|
1 |
|
$this->execute($this->api->putGroupRole(), ['domainId' => $this->id] + $options); |
|
132
|
1 |
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* @param array $options {@see \OpenStack\Identity\v3\Api::headGroupRole} |
|
136
|
|
|
* |
|
137
|
|
|
* @return bool |
|
138
|
|
|
*/ |
|
139
|
2 |
View Code Duplication |
public function checkGroupRole(array $options = []): bool |
|
|
|
|
|
|
140
|
|
|
{ |
|
141
|
|
|
try { |
|
142
|
2 |
|
$this->execute($this->api->headGroupRole(), ['domainId' => $this->id] + $options); |
|
143
|
1 |
|
return true; |
|
144
|
1 |
|
} catch (BadResponseError $e) { |
|
145
|
1 |
|
return false; |
|
146
|
|
|
} |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* @param array $options {@see \OpenStack\Identity\v3\Api::deleteGroupRole} |
|
151
|
|
|
*/ |
|
152
|
1 |
|
public function revokeGroupRole(array $options = []) |
|
153
|
|
|
{ |
|
154
|
1 |
|
$this->execute($this->api->deleteGroupRole(), ['domainId' => $this->id] + $options); |
|
155
|
1 |
|
} |
|
156
|
|
|
} |
|
157
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: