1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Lookyman\Rundeck\Api\Endpoints\Execution; |
5
|
|
|
|
6
|
|
|
use GuzzleHttp\Promise\PromiseInterface; |
7
|
|
|
use GuzzleHttp\Psr7\Request; |
8
|
|
|
use Lookyman\Rundeck\Api\Client; |
9
|
|
|
|
10
|
|
|
class Output |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var Client |
14
|
|
|
*/ |
15
|
|
|
private $client; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @param Client $client |
19
|
|
|
*/ |
20
|
|
|
public function __construct(Client $client) |
21
|
|
|
{ |
22
|
|
|
$this->client = $client; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param string $id |
27
|
|
|
* @param string|null $node |
28
|
|
|
* @param string|null $step |
29
|
|
|
* @param array $params |
30
|
|
|
* @return PromiseInterface |
31
|
|
|
*/ |
32
|
|
|
public function output(string $id, string $node = null, string $step = null, array $params = []): PromiseInterface |
33
|
|
|
{ |
34
|
|
|
if ($node && $step) { |
|
|
|
|
35
|
|
|
$path = sprintf('/execution/%s/output/node/%s/step/%s', urlencode($id), urlencode($node), urlencode($step)); |
36
|
|
|
} elseif ($node && !$step) { |
|
|
|
|
37
|
|
|
$path = sprintf('/execution/%s/output/node/%s', urlencode($id), urlencode($node)); |
38
|
|
|
} elseif (!$node && $step) { |
|
|
|
|
39
|
|
|
$path = sprintf('/execution/%s/output/step/%s', urlencode($id), urlencode($step)); |
40
|
|
|
} else { |
41
|
|
|
$path = sprintf('/execution/%s/output', urlencode($id)); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
return $this->client->getConfiguration()->getGuzzle()->sendAsync( |
45
|
|
|
new Request('GET', $this->client->getConfiguration()->getBaseUri() . $path, [], $this->client->getConfiguration()->getFormat()->formatParams($params)) |
46
|
|
|
); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param string $id |
51
|
|
|
* @param bool $stateOnly |
52
|
|
|
* @return PromiseInterface |
53
|
|
|
*/ |
54
|
|
|
public function outputWithState(string $id, bool $stateOnly = false): PromiseInterface |
55
|
|
|
{ |
56
|
|
|
return $this->client->getConfiguration()->getGuzzle()->sendAsync( |
57
|
|
|
new Request('GET', $this->client->getConfiguration()->getBaseUri() . sprintf('/execution/%s/output/state%s', urlencode($id), $stateOnly ? '?stateOnly=true' : '')) |
58
|
|
|
); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: