-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathEnvironmentDeployment.php
More file actions
122 lines (111 loc) · 3.83 KB
/
EnvironmentDeployment.php
File metadata and controls
122 lines (111 loc) · 3.83 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
declare(strict_types=1);
namespace Platformsh\Client\Model\Deployment;
use Platformsh\Client\Model\ApiResourceBase;
/**
* A Platform.sh environment deployment.
*
* @property-read Route[] $routes
* @property-read Service[] $services
* @property-read WebApp[] $webapps
* @property-read Worker[] $workers
*
* @property-read array $container_profiles
*
* @method Route getRoute(string $originalUrl)
* @method Service getService(string $name)
* @method WebApp getWebApp(string $name)
* @method Worker getWorker(string $name)
*/
class EnvironmentDeployment extends ApiResourceBase
{
private static array $types = [
'services' => Service::class,
'routes' => Route::class,
'webapps' => WebApp::class,
'workers' => Worker::class,
];
public function __get(string $name)
{
if (isset(self::$types[$name])) {
$className = self::$types[$name];
return array_map(function (array $data) use ($className) {
return $className::fromData($data);
}, $this->data[$name]);
}
return parent::__get($name);
}
/**
* Dynamically get an item from a list of sub-properties by name.
*
* This represents the getWebApp(), getService, getRoute() and
* getWorker() methods.
*/
public function __call($name, $arguments)
{
if (str_starts_with($name, 'get')) {
$type = substr($name, 3);
$property = strtolower($type) . 's';
if (! isset(self::$types[$property])) {
throw new \BadMethodCallException(sprintf('Method not found: %s()', $name));
}
if (count($arguments) !== 1) {
throw new \InvalidArgumentException(sprintf('%s() expects exactly one argument', $name));
}
$key = $arguments[0];
if (! isset($this->data[$property][$key])) {
throw new \InvalidArgumentException(sprintf('%s not found: %s', $type, $key));
}
$className = self::$types[$property];
return $className::fromData($this->data[$property][$key]);
}
throw new \BadMethodCallException(sprintf('Method not found: %s()', $name));
}
/**
* Returns the runtime operations defined on all the apps in this deployment.
*
* To fetch a specific runtime operation use the WebApp or Worker object.
*
* @see AppBase::getRuntimeOperations()
* @see AppBase::getRuntimeOperation()
*
* @return array<string, array<string, RuntimeOperation>>
* A list of runtime operations keyed by operation name and app name.
*/
public function getRuntimeOperations(): array
{
$operations = [];
foreach (['webapps', 'workers'] as $appType) {
foreach ($this->{$appType} as $appName => $app) {
/** @var AppBase $app */
$operations[$appName] = $app->getRuntimeOperations();
}
}
return $operations;
}
/**
* Executes a runtime operation on this deployment.
*
* @param string $name
* The operation name.
* @param string $service
* The name of the service or application to run the operation on.
* @param array<string, string> $parameters
* Parameters to pass to the operation, as key-value pairs.
*
*@see RuntimeOperation
* @see AppBase::getRuntimeOperations()
* @see AppBase::getRuntimeOperation()
*/
public function execRuntimeOperation(string $name, string $service, array $parameters = []): \Platformsh\Client\Model\Result
{
$body = [
'operation' => $name,
'service' => $service,
];
if ($parameters) {
$body['parameters'] = (object) $parameters;
}
return $this->runOperation('operations', 'post', $body);
}
}