-
Notifications
You must be signed in to change notification settings - Fork 155
Expand file tree
/
Copy pathCatalog.php
More file actions
65 lines (56 loc) · 1.87 KB
/
Copy pathCatalog.php
File metadata and controls
65 lines (56 loc) · 1.87 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
<?php declare(strict_types=1);
namespace OpenStack\Identity\v3\Models;
use OpenStack\Common\Resource\Alias;
use OpenStack\Common\Resource\OperatorResource;
/**
* @property \OpenStack\Identity\v3\Api $api
*/
class Catalog extends OperatorResource implements \OpenStack\Common\Auth\Catalog
{
/** @var []Service */
public $services;
/**
* @inheritdoc
*/
protected function getAliases(): array
{
return parent::getAliases() + [
'services' => new Alias('services', Service::class, true)
];
}
public function populateFromArray(array $data): self
{
foreach ($data as $service) {
$this->services[] = $this->model(Service::class, $service);
}
return $this;
}
/**
* Retrieve a base URL for a service, according to its catalog name, type, region.
*
* @param string $name The name of the service as it appears in the catalog.
* @param string $type The type of the service as it appears in the catalog.
* @param string $region The region of the service as it appears in the catalog.
* @param string $urlType Unused.
*
* @return false|string FALSE if no URL found
*/
public function getServiceUrl(string $name, string $type, string $region, string $urlType): string
{
if (empty($this->services)) {
throw new \RuntimeException('No services are defined');
}
foreach ($this->services as $service) {
if (false !== ($url = $service->getUrl($name, $type, $region, $urlType))) {
return $url;
}
}
throw new \RuntimeException(sprintf(
"Endpoint URL could not be found in the catalog for this service.\nName: %s\nType: %s\nRegion: %s\nURL type: %s",
$name,
$type,
$region,
$urlType
));
}
}