-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathConnectionResult.php
120 lines (106 loc) · 2.79 KB
/
ConnectionResult.php
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
<?php
declare(strict_types=1);
namespace Upmind\ProvisionProviders\Servers\Data;
use Upmind\ProvisionBase\Provider\DataSet\DataSet;
use Upmind\ProvisionBase\Provider\DataSet\ResultData;
use Upmind\ProvisionBase\Provider\DataSet\Rules;
/**
* @property-read string $type Connection type
* @property-read string|null $command SSH command
* @property-read string|null $redirect_url Redirect URL
* @property-read VncConnection|null $vnc_connection VNC connection
* @property-read string|null $password
* @property-read string|null $expires_at
*/
class ConnectionResult extends ResultData
{
public static function rules(): Rules
{
return new Rules([
'type' => ['required', 'in:' . implode(',', self::VALID_TYPES)],
'command' => [
'required_if:type,' . self::TYPE_SSH,
'string',
'regex:/^ssh [a-z0-9\.\-\_]+@[a-z0-9\.\-]+/i',
],
'redirect_url' => [
'required_if:type,' . self::TYPE_REDIRECT,
'url',
],
'vnc_connection' => ['required_if:type,' . self::TYPE_VNC, 'nullable', VncConnection::class],
'password' => ['nullable', 'string'],
'expires_at' => ['nullable', 'date'],
]);
}
public const VALID_TYPES = [
self::TYPE_SSH,
self::TYPE_VNC,
self::TYPE_REDIRECT,
];
/**
* Connection is an SSH command.
*
* @var string
*/
public const TYPE_SSH = 'ssh';
/**
* Connection is over VNC.
*
* @var string
*/
public const TYPE_VNC = 'vnc';
/**
* Connection is in-browser via a redirect URL.
*
* @var string
*/
public const TYPE_REDIRECT = 'redirect';
/**
* @return self $this
*/
public function setType(string $type): self
{
$this->setValue('type', $type);
return $this;
}
/**
* @return self $this
*/
public function setCommand(?string $command): self
{
$this->setValue('command', $command);
return $this;
}
/**
* @return self $this
*/
public function setRedirectUrl(?string $url): self
{
$this->setValue('redirect_url', $url);
return $this;
}
/**
* @return self $this
*/
public function setVncConnection(?VncConnection $vnc): self
{
$this->setValue('vnc_connection', $vnc);
return $this;
}
/**
* @return self $this
*/
public function setPassword(?string $password): self
{
$this->setValue('password', $password);
return $this;
}
/**
* @return self $this
*/
public function setExpiresAt(?string $expires_at): self
{
$this->setValue('expires_at', $expires_at);
return $this;
}
}