|
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 Group extends OperatorResource implements Creatable, Listable, Retrievable, Updateable, Deletable |
|
17
|
|
|
{ |
|
18
|
|
|
/** @var string */ |
|
19
|
|
|
public $domainId; |
|
20
|
|
|
|
|
21
|
|
|
/** @var string */ |
|
22
|
|
|
public $id; |
|
23
|
|
|
|
|
24
|
|
|
/** @var string */ |
|
25
|
|
|
public $description; |
|
26
|
|
|
|
|
27
|
|
|
/** @var array */ |
|
28
|
|
|
public $links; |
|
29
|
|
|
|
|
30
|
|
|
/** @var string */ |
|
31
|
|
|
public $name; |
|
32
|
|
|
|
|
33
|
|
|
protected $aliases = ['domain_id' => 'domainId']; |
|
34
|
|
|
|
|
35
|
|
|
protected $resourceKey = 'group'; |
|
36
|
|
|
protected $resourcesKey = 'groups'; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* {@inheritDoc} |
|
40
|
|
|
* |
|
41
|
|
|
* @param array $data {@see \OpenStack\Identity\v3\Api::postGroups} |
|
42
|
|
|
*/ |
|
43
|
2 |
|
public function create(array $data): Creatable |
|
44
|
|
|
{ |
|
45
|
2 |
|
$response = $this->execute($this->api->postGroups(), $data); |
|
46
|
2 |
|
return $this->populateFromResponse($response); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* {@inheritDoc} |
|
51
|
|
|
*/ |
|
52
|
1 |
|
public function retrieve() |
|
53
|
|
|
{ |
|
54
|
1 |
|
$response = $this->execute($this->api->getGroup(), ['id' => $this->id]); |
|
55
|
1 |
|
$this->populateFromResponse($response); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* {@inheritDoc} |
|
60
|
|
|
*/ |
|
61
|
1 |
|
public function update() |
|
62
|
|
|
{ |
|
63
|
1 |
|
$response = $this->executeWithState($this->api->patchGroup()); |
|
64
|
1 |
|
$this->populateFromResponse($response); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* {@inheritDoc} |
|
69
|
|
|
*/ |
|
70
|
1 |
|
public function delete() |
|
71
|
|
|
{ |
|
72
|
1 |
|
$this->execute($this->api->deleteGroup(), ['id' => $this->id]); |
|
73
|
1 |
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @param array $options {@see \OpenStack\Identity\v3\Api::getGroupUsers} |
|
77
|
|
|
* |
|
78
|
|
|
* @return \Generator |
|
79
|
|
|
*/ |
|
80
|
1 |
|
public function listUsers(array $options = []): \Generator |
|
81
|
|
|
{ |
|
82
|
1 |
|
$options['id'] = $this->id; |
|
83
|
1 |
|
return $this->model(User::class)->enumerate($this->api->getGroupUsers(), $options); |
|
|
|
|
|
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @param array $options {@see \OpenStack\Identity\v3\Api::putGroupUser} |
|
88
|
|
|
*/ |
|
89
|
1 |
|
public function addUser(array $options) |
|
90
|
|
|
{ |
|
91
|
1 |
|
$this->execute($this->api->putGroupUser(), ['groupId' => $this->id] + $options); |
|
92
|
1 |
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @param array $options {@see \OpenStack\Identity\v3\Api::deleteGroupUser} |
|
96
|
|
|
*/ |
|
97
|
2 |
|
public function removeUser(array $options) |
|
98
|
|
|
{ |
|
99
|
1 |
|
$this->execute($this->api->deleteGroupUser(), ['groupId' => $this->id] + $options); |
|
100
|
2 |
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @param array $options {@see \OpenStack\Identity\v3\Api::headGroupUser} |
|
104
|
|
|
* |
|
105
|
|
|
* @return bool |
|
106
|
|
|
*/ |
|
107
|
2 |
View Code Duplication |
public function checkMembership(array $options): bool |
|
|
|
|
|
|
108
|
|
|
{ |
|
109
|
|
|
try { |
|
110
|
2 |
|
$this->execute($this->api->headGroupUser(), ['groupId' => $this->id] + $options); |
|
111
|
1 |
|
return true; |
|
112
|
1 |
|
} catch (BadResponseError $e) { |
|
113
|
1 |
|
return false; |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|
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: