1 | <?php |
||
16 | class Service extends AbstractService implements IdentityService |
||
17 | { |
||
18 | 5 | public static function factory(ClientInterface $client) |
|
22 | |||
23 | /** |
||
24 | * Authenticates credentials, giving back a token and a base URL for the service. |
||
25 | * |
||
26 | * @param array $options {@see \OpenStack\Identity\v3\Api::postTokens} |
||
27 | * |
||
28 | * @return array Returns a {@see Models\Token} as the first element, a string base URL as the second |
||
29 | */ |
||
30 | 6 | public function authenticate(array $options) |
|
31 | { |
||
32 | 6 | $authOptions = array_intersect_key($options, $this->api->postTokens()['params']); |
|
33 | |||
34 | 6 | $token = $this->generateToken($authOptions); |
|
35 | |||
36 | 2 | $name = $options['catalogName']; |
|
37 | 2 | $type = $options['catalogType']; |
|
38 | 2 | $region = $options['region']; |
|
39 | 2 | $interface = isset($options['interface']) ? $options['interface'] : Enum::INTERFACE_PUBLIC; |
|
40 | |||
41 | 2 | if ($baseUrl = $token->catalog->getServiceUrl($name, $type, $region, $interface)) { |
|
42 | 1 | return [$token, $baseUrl]; |
|
43 | } |
||
44 | |||
45 | 1 | throw new \RuntimeException(sprintf("No service found with type [%s] name [%s] region [%s] interface [%s]", |
|
46 | 1 | $type, $name, $region, $interface)); |
|
47 | } |
||
48 | |||
49 | /** |
||
50 | * Generates a new authentication token |
||
51 | * |
||
52 | * @param array $options {@see \OpenStack\Identity\v3\Api::postTokens} |
||
53 | * |
||
54 | * @return Models\Token |
||
55 | */ |
||
56 | 8 | public function generateToken(array $options) |
|
60 | |||
61 | /** |
||
62 | * Retrieves a token object and populates its unique identifier object. This operation will not perform a GET or |
||
63 | * HEAD request by default; you will need to call retrieve() if you want to pull in remote state from the API. |
||
64 | * |
||
65 | * @param string $id The unique ID of the token to retrieve |
||
66 | * |
||
67 | * @return Models\Token |
||
68 | */ |
||
69 | 1 | public function getToken($id) |
|
73 | |||
74 | /** |
||
75 | * Validates a token, identified by its ID, and returns TRUE if its valid, FALSE if not. |
||
76 | * |
||
77 | * @param string $id The unique ID of the token |
||
78 | * |
||
79 | * @return bool |
||
80 | */ |
||
81 | 2 | public function validateToken($id) |
|
90 | |||
91 | /** |
||
92 | * Revokes a token, identified by its ID. After this operation completes, users will not be able to use this token |
||
93 | * again for authentication. |
||
94 | * |
||
95 | * @param string $id The unique ID of the token |
||
96 | * |
||
97 | * @return Models\Token |
||
98 | */ |
||
99 | 1 | public function revokeToken($id) |
|
103 | |||
104 | /** |
||
105 | * Creates a new service according to the provided options. |
||
106 | * |
||
107 | * @param array $options {@see \OpenStack\Identity\v3\Api::postServices} |
||
108 | * |
||
109 | * @return Models\Service |
||
110 | */ |
||
111 | 1 | public function createService(array $options) |
|
115 | |||
116 | /** |
||
117 | * Returns a generator which will yield a collection of service objects. The elements which generators yield can be |
||
118 | * accessed using a foreach loop. Often the API will not return the full state of the resource in collections; you |
||
119 | * will need to use retrieve() to pull in the full state of the remote resource from the API. |
||
120 | * |
||
121 | * @param array $options {@see \OpenStack\Identity\v3\Api::getServices} |
||
122 | * |
||
123 | * @return \Generator |
||
124 | */ |
||
125 | 1 | public function listServices(array $options = []) |
|
129 | |||
130 | /** |
||
131 | * Retrieves a service object and populates its unique identifier object. This operation will not perform a GET or |
||
132 | * HEAD request by default; you will need to call retrieve() if you want to pull in remote state from the API. |
||
133 | * |
||
134 | * @param string $id The unique ID of the service |
||
135 | * |
||
136 | * @return Models\Service |
||
137 | */ |
||
138 | 1 | public function getService($id) |
|
142 | |||
143 | /** |
||
144 | * Creates a new endpoint according to the provided options. |
||
145 | * |
||
146 | * @param array $options {@see \OpenStack\Identity\v3\Api::postEndpoints} |
||
147 | * |
||
148 | * @return Models\Endpoint |
||
149 | */ |
||
150 | 2 | public function createEndpoint(array $options) |
|
154 | |||
155 | /** |
||
156 | * Retrieves an endpoint object and populates its unique identifier object. This operation will not perform a GET or |
||
157 | * HEAD request by default; you will need to call retrieve() if you want to pull in remote state from the API. |
||
158 | * |
||
159 | * @param string $id The unique ID of the service |
||
160 | * |
||
161 | * @return Models\Endpoint |
||
162 | */ |
||
163 | 1 | public function getEndpoint($id) |
|
167 | |||
168 | /** |
||
169 | * Returns a generator which will yield a collection of endpoint objects. The elements which generators yield can be |
||
170 | * accessed using a foreach loop. Often the API will not return the full state of the resource in collections; you |
||
171 | * will need to use retrieve() to pull in the full state of the remote resource from the API. |
||
172 | * |
||
173 | * @param array $options {@see \OpenStack\Identity\v3\Api::getEndpoints} |
||
174 | * |
||
175 | * @return \Generator |
||
176 | */ |
||
177 | 1 | public function listEndpoints(array $options = []) |
|
181 | |||
182 | /** |
||
183 | * Creates a new domain according to the provided options. |
||
184 | * |
||
185 | * @param array $options {@see \OpenStack\Identity\v3\Api::postDomains} |
||
186 | * |
||
187 | * @return Models\Domain |
||
188 | */ |
||
189 | 1 | public function createDomain(array $options) |
|
193 | |||
194 | /** |
||
195 | * Returns a generator which will yield a collection of domain objects. The elements which generators yield can be |
||
196 | * accessed using a foreach loop. Often the API will not return the full state of the resource in collections; you |
||
197 | * will need to use retrieve() to pull in the full state of the remote resource from the API. |
||
198 | * |
||
199 | * @param array $options {@see \OpenStack\Identity\v3\Api::getDomains} |
||
200 | * |
||
201 | * @return \Generator |
||
202 | */ |
||
203 | 1 | public function listDomains(array $options = []) |
|
207 | |||
208 | /** |
||
209 | * Retrieves a domain object and populates its unique identifier object. This operation will not perform a GET or |
||
210 | * HEAD request by default; you will need to call retrieve() if you want to pull in remote state from the API. |
||
211 | * |
||
212 | * @param string $id The unique ID of the domain |
||
213 | * |
||
214 | * @return Models\Domain |
||
215 | */ |
||
216 | 1 | public function getDomain($id) |
|
220 | |||
221 | /** |
||
222 | * Creates a new project according to the provided options. |
||
223 | * |
||
224 | * @param array $options {@see \OpenStack\Identity\v3\Api::postProjects} |
||
225 | * |
||
226 | * @return Models\Project |
||
227 | */ |
||
228 | 1 | public function createProject(array $options) |
|
232 | |||
233 | /** |
||
234 | * Returns a generator which will yield a collection of project objects. The elements which generators yield can be |
||
235 | * accessed using a foreach loop. Often the API will not return the full state of the resource in collections; you |
||
236 | * will need to use retrieve() to pull in the full state of the remote resource from the API. |
||
237 | * |
||
238 | * @param array $options {@see \OpenStack\Identity\v3\Api::getProjects} |
||
239 | * |
||
240 | * @return \Generator |
||
241 | */ |
||
242 | 1 | public function listProjects(array $options = []) |
|
246 | |||
247 | /** |
||
248 | * Retrieves a project object and populates its unique identifier object. This operation will not perform a GET or |
||
249 | * HEAD request by default; you will need to call retrieve() if you want to pull in remote state from the API. |
||
250 | * |
||
251 | * @param string $id The unique ID of the project |
||
252 | * |
||
253 | * @return Models\Project |
||
254 | */ |
||
255 | 1 | public function getProject($id) |
|
259 | |||
260 | /** |
||
261 | * Creates a new user according to the provided options. |
||
262 | * |
||
263 | * @param array $options {@see \OpenStack\Identity\v3\Api::postUsers} |
||
264 | * |
||
265 | * @return Models\User |
||
266 | */ |
||
267 | 1 | public function createUser(array $options) |
|
271 | |||
272 | /** |
||
273 | * Returns a generator which will yield a collection of user objects. The elements which generators yield can be |
||
274 | * accessed using a foreach loop. Often the API will not return the full state of the resource in collections; you |
||
275 | * will need to use retrieve() to pull in the full state of the remote resource from the API. |
||
276 | * |
||
277 | * @param array $options {@see \OpenStack\Identity\v3\Api::getUsers} |
||
278 | * |
||
279 | * @return \Generator |
||
280 | */ |
||
281 | 1 | public function listUsers(array $options = []) |
|
285 | |||
286 | /** |
||
287 | * Retrieves a user object and populates its unique identifier object. This operation will not perform a GET or |
||
288 | * HEAD request by default; you will need to call retrieve() if you want to pull in remote state from the API. |
||
289 | * |
||
290 | * @param string $id The unique ID of the user |
||
291 | * |
||
292 | * @return Models\User |
||
293 | */ |
||
294 | 1 | public function getUser($id) |
|
298 | |||
299 | /** |
||
300 | * Creates a new group according to the provided options. |
||
301 | * |
||
302 | * @param array $options {@see \OpenStack\Identity\v3\Api::postGroups} |
||
303 | * |
||
304 | * @return Models\Group |
||
305 | */ |
||
306 | 1 | public function createGroup(array $options) |
|
310 | |||
311 | /** |
||
312 | * Returns a generator which will yield a collection of group objects. The elements which generators yield can be |
||
313 | * accessed using a foreach loop. Often the API will not return the full state of the resource in collections; you |
||
314 | * will need to use retrieve() to pull in the full state of the remote resource from the API. |
||
315 | * |
||
316 | * @param array $options {@see \OpenStack\Identity\v3\Api::getGroups} |
||
317 | * |
||
318 | * @return \Generator |
||
319 | */ |
||
320 | 1 | public function listGroups(array $options = []) |
|
324 | |||
325 | /** |
||
326 | * Retrieves a group object and populates its unique identifier object. This operation will not perform a GET or |
||
327 | * HEAD request by default; you will need to call retrieve() if you want to pull in remote state from the API. |
||
328 | * |
||
329 | * @param string $id The unique ID of the group |
||
330 | * |
||
331 | * @return Models\Group |
||
332 | */ |
||
333 | 1 | public function getGroup($id) |
|
337 | |||
338 | /** |
||
339 | * Creates a new credential according to the provided options. |
||
340 | * |
||
341 | * @param array $options {@see \OpenStack\Identity\v3\Api::postCredentials} |
||
342 | * |
||
343 | * @return Models\Credential |
||
344 | */ |
||
345 | 1 | public function createCredential(array $options) |
|
349 | |||
350 | /** |
||
351 | * Returns a generator which will yield a collection of credential objects. The elements which generators yield can |
||
352 | * be accessed using a foreach loop. Often the API will not return the full state of the resource in collections; |
||
353 | * you will need to use retrieve() to pull in the full state of the remote resource from the API. |
||
354 | * |
||
355 | * @return \Generator |
||
356 | */ |
||
357 | 1 | public function listCredentials() |
|
361 | |||
362 | /** |
||
363 | * Retrieves a credential object and populates its unique identifier object. This operation will not perform a GET |
||
364 | * or HEAD request by default; you will need to call retrieve() if you want to pull in remote state from the API. |
||
365 | * |
||
366 | * @param string $id The unique ID of the credential |
||
367 | * |
||
368 | * @return Models\Credential |
||
369 | */ |
||
370 | 1 | public function getCredential($id) |
|
374 | |||
375 | /** |
||
376 | * Creates a new role according to the provided options. |
||
377 | * |
||
378 | * @param array $options {@see \OpenStack\Identity\v3\Api::postRoles} |
||
379 | * |
||
380 | * @return Models\Role |
||
381 | */ |
||
382 | 1 | public function createRole(array $options) |
|
386 | |||
387 | /** |
||
388 | * Returns a generator which will yield a collection of role objects. The elements which generators yield can be |
||
389 | * accessed using a foreach loop. Often the API will not return the full state of the resource in collections; you |
||
390 | * will need to use retrieve() to pull in the full state of the remote resource from the API. |
||
391 | * |
||
392 | * @param array $options {@see \OpenStack\Identity\v3\Api::getRoles} |
||
393 | * |
||
394 | * @return \Generator |
||
395 | */ |
||
396 | 1 | public function listRoles(array $options = []) |
|
400 | |||
401 | /** |
||
402 | * Returns a generator which will yield a collection of role assignment objects. The elements which generators |
||
403 | * yield can be accessed using a foreach loop. Often the API will not return the full state of the resource in |
||
404 | * collections; you will need to use retrieve() to pull in the full state of the remote resource from the API. |
||
405 | * |
||
406 | * @param array $options {@see \OpenStack\Identity\v3\Api::getRoleAssignments} |
||
407 | * |
||
408 | * @return \Generator |
||
409 | */ |
||
410 | 1 | public function listRoleAssignments(array $options = []) |
|
414 | |||
415 | /** |
||
416 | * Creates a new policy according to the provided options. |
||
417 | * |
||
418 | * @param array $options {@see \OpenStack\Identity\v3\Api::postPolicies} |
||
419 | * |
||
420 | * @return Models\Policy |
||
421 | */ |
||
422 | 1 | public function createPolicy(array $options) |
|
426 | |||
427 | /** |
||
428 | * Returns a generator which will yield a collection of policy objects. The elements which generators yield can be |
||
429 | * accessed using a foreach loop. Often the API will not return the full state of the resource in collections; you |
||
430 | * will need to use retrieve() to pull in the full state of the remote resource from the API. |
||
431 | * |
||
432 | * @param array $options {@see \OpenStack\Identity\v3\Api::getPolicies} |
||
433 | * |
||
434 | * @return \Generator |
||
435 | */ |
||
436 | 1 | public function listPolicies(array $options = []) |
|
440 | |||
441 | /** |
||
442 | * Retrieves a policy object and populates its unique identifier object. This operation will not perform a GET or |
||
443 | * HEAD request by default; you will need to call retrieve() if you want to pull in remote state from the API. |
||
444 | * |
||
445 | * @param string $id The unique ID of the policy |
||
446 | * |
||
447 | * @return Models\Policy |
||
448 | */ |
||
449 | 1 | public function getPolicy($id) |
|
453 | } |
||
454 |
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: