Skip to content

Commit fc4176b

Browse files
committed
smidge more work
1 parent 2727a44 commit fc4176b

10 files changed

Lines changed: 508 additions & 63 deletions

src/ConfigEntry/ConfigEntryTrait.php

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,35 +22,11 @@
2222

2323
trait ConfigEntryTrait
2424
{
25-
public string $Kind;
26-
public string $Name;
2725
public string $Namespace;
2826
public null|\stdClass $Meta;
2927
public int $CreateIndex;
3028
public int $ModifyIndex;
3129

32-
public function getKind(): string
33-
{
34-
return $this->Kind;
35-
}
36-
37-
public function setKind(string $Kind): self
38-
{
39-
$this->Kind = $Kind;
40-
return $this;
41-
}
42-
43-
public function getName(): string
44-
{
45-
return $this->Name;
46-
}
47-
48-
public function setName(string $Name): self
49-
{
50-
$this->Name = $Name;
51-
return $this;
52-
}
53-
5430
public function getNamespace(): string
5531
{
5632
return $this->Namespace;

src/ConfigEntry/EnvoyExtension.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ class EnvoyExtension extends AbstractModel
3030
public string $ConsulVersion;
3131
public string $EnvoyVersion;
3232

33+
/**
34+
* @param array<string,mixed>|null $data
35+
*/
3336
public function __construct(
3437
null|array $data = null, // Deprecated, will be removed.
3538
string $Name = '',

src/ConfigEntry/ExposeConfig.php

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,28 @@
2121
*/
2222

2323
use DCarbone\PHPConsulAPI\AbstractModel;
24-
use DCarbone\PHPConsulAPI\Transcoding;
2524

2625
class ExposeConfig extends AbstractModel
2726
{
28-
protected const FIELDS = [
29-
self::FIELD_CHECKS => Transcoding::OMITEMPTY_STRING_FIELD,
30-
self::FIELD_PATHS => [
31-
Transcoding::FIELD_TYPE => Transcoding::ARRAY,
32-
Transcoding::FIELD_CLASS => ExposePath::class,
33-
Transcoding::FIELD_ARRAY_TYPE => Transcoding::OBJECT,
34-
Transcoding::FIELD_OMITEMPTY => true,
35-
],
36-
];
37-
38-
private const FIELD_CHECKS = 'Checks';
39-
private const FIELD_PATHS = 'Paths';
40-
4127
public bool $Checks;
28+
/** @var array<\DCarbone\PHPConsulAPI\ConfigEntry\ExposePath> */
4229
public array $Paths;
4330

31+
/**
32+
* @param array<string,mixed>|null $data
33+
*/
34+
public function __construct(
35+
null|array $data = null, // Deprecated, will be removed.
36+
bool $Checks = false,
37+
array $Paths = [],
38+
) {
39+
$this->Checks = $Checks;
40+
$this->setPaths(...$Paths);
41+
if (null !== $data && [] !== $data) {
42+
self::jsonUnserialize((object)$data, $this);
43+
}
44+
}
45+
4446
public function isChecks(): bool
4547
{
4648
return $this->Checks;
@@ -52,14 +54,47 @@ public function setChecks(bool $Checks): self
5254
return $this;
5355
}
5456

57+
/**
58+
* @return \DCarbone\PHPConsulAPI\ConfigEntry\ExposePath[]
59+
*/
5560
public function getPaths(): array
5661
{
5762
return $this->Paths;
5863
}
5964

60-
public function setPaths(array $Paths): self
65+
public function setPaths(ExposePath ...$Paths): self
6166
{
6267
$this->Paths = $Paths;
6368
return $this;
6469
}
70+
71+
public static function jsonUnserialize(\stdClass $decoded, null|self $n = null): static
72+
{
73+
$n = $n ?? new self();
74+
foreach ($decoded as $k => $v) {
75+
if ('Paths' === $k) {
76+
foreach ($v as $vv) {
77+
$n->Paths[] = ExposePath::jsonUnserialize($vv);
78+
}
79+
} else {
80+
$n->{$k} = $v;
81+
}
82+
}
83+
return $n;
84+
}
85+
86+
public function jsonSerialize(): \stdClass
87+
{
88+
$out = new \stdClass();
89+
foreach ($this->_getDynamicFields() as $k => $v) {
90+
$out->{$k} = $v;
91+
}
92+
if ($this->Checks) {
93+
$out->Checks = true;
94+
}
95+
if ([] !== $this->Paths) {
96+
$out->Paths = $this->Paths;
97+
}
98+
return $out;
99+
}
65100
}

src/ConfigEntry/ExposePath.php

Lines changed: 60 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,36 @@
2121
*/
2222

2323
use DCarbone\PHPConsulAPI\AbstractModel;
24-
use DCarbone\PHPConsulAPI\Transcoding;
2524

2625
class ExposePath extends AbstractModel
2726
{
28-
protected const FIELDS = [
29-
self::FIELD_LISTENER_PORT => Transcoding::OMITEMPTY_INTEGER_FIELD,
30-
self::FIELD_PATH => Transcoding::OMITEMPTY_STRING_FIELD,
31-
self::FIELD_LOCAL_PORT_PATH => Transcoding::OMITEMPTY_INTEGER_FIELD,
32-
self::FIELD_PROTOCOL => Transcoding::OMITEMPTY_STRING_FIELD,
33-
];
34-
35-
private const FIELD_LISTENER_PORT = 'ListenerPort';
36-
private const FIELD_PATH = 'Path';
37-
private const FIELD_LOCAL_PORT_PATH = 'LocalPortPath';
38-
private const FIELD_PROTOCOL = 'Protocol';
39-
4027
public int $ListenerPort;
4128
public string $Path;
4229
public int $LocalPathPort;
4330
public string $Protocol;
4431
public bool $ParsedFromCheck;
4532

33+
/**
34+
* @param array<string,mixed>|null $data
35+
*/
36+
public function __construct(
37+
null|array $data = null, // Deprecated, will be removed.
38+
int $ListenerPort = 0,
39+
string $Path = '',
40+
int $LocalPathPort = 0,
41+
string $Protocol = '',
42+
bool $ParsedFromCheck = false
43+
) {
44+
$this->ListenerPort = $ListenerPort;
45+
$this->Path = $Path;
46+
$this->LocalPathPort = $LocalPathPort;
47+
$this->Protocol = $Protocol;
48+
$this->ParsedFromCheck = $ParsedFromCheck;
49+
if (null !== $data && [] !== $data) {
50+
self::jsonUnserialize((object)$data, $this);
51+
}
52+
}
53+
4654
public function getListenerPort(): int
4755
{
4856
return $this->ListenerPort;
@@ -97,4 +105,43 @@ public function setParsedFromCheck(bool $ParsedFromCheck): self
97105
$this->ParsedFromCheck = $ParsedFromCheck;
98106
return $this;
99107
}
108+
109+
public static function jsonUnserialize(\stdClass $decoded, null|self $n = null): static
110+
{
111+
$n = $n ?? new self();
112+
foreach ($decoded as $k => $v) {
113+
if ('listener_port' === $k) {
114+
$n->ListenerPort = $v;
115+
} elseif ('local_path_port' === $k) {
116+
$n->LocalPathPort = $v;
117+
} else {
118+
$n->{$k} = $v;
119+
}
120+
}
121+
return $n;
122+
}
123+
124+
public function jsonSerialize(): \stdClass
125+
{
126+
$out = new \stdClass();
127+
foreach ($this->_getDynamicFields() as $k => $v) {
128+
$out->{$k} = $v;
129+
}
130+
if (0 !== $this->ListenerPort) {
131+
$out->listener_port = $this->ListenerPort;
132+
}
133+
if ('' !== $this->Path) {
134+
$out->Path = $this->Path;
135+
}
136+
if (0 !== $this->LocalPathPort) {
137+
$out->local_path_port = $this->LocalPathPort;
138+
}
139+
if ('' !== $this->Protocol) {
140+
$out->Protocol = $this->Protocol;
141+
}
142+
if ($this->ParsedFromCheck) {
143+
$out->ParsedFromCheck = true;
144+
}
145+
return $out;
146+
}
100147
}

src/ConfigEntry/MeshConfigEntry.php

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,57 @@
2121
*/
2222

2323
use DCarbone\PHPConsulAPI\AbstractModel;
24-
use DCarbone\PHPConsulAPI\Transcoding;
24+
use DCarbone\PHPConsulAPI\Consul;
2525

2626
class MeshConfigEntry extends AbstractModel implements ConfigEntry
2727
{
2828
use ConfigEntryTrait;
2929

30-
protected const FIELDS = COnfigEntry::INTERFACE_FIELDS + [
31-
self::FIELD_TRANSPARENT_PROXY => [
32-
Transcoding::FIELD_TYPE => Transcoding::OBJECT,
33-
Transcoding::FIELD_CLASS => TransparentProxyConfig::class,
34-
Transcoding::FIELD_NULLABLE => false,
35-
Transcoding::FIELD_OMITEMPTY => false,
36-
],
37-
];
30+
public string $Partition;
31+
public TransparentProxyConfig $TransparentProxy;
32+
public bool $AllowEnablingPermissiveMutualTLS;
33+
public null|MeshTLSConfig $TLS;
34+
public null|MeshHTTPConfig $HTTP;
35+
public null|PeeringMeshConfig $Peering;
3836

39-
private const FIELD_TRANSPARENT_PROXY = 'TransparentProxy';
37+
public function __construct(
38+
null|array $data = null, // Deprecated, will be removed.
39+
string $Partition = '',
40+
string $Namespace = '',
41+
null|TransparentProxyConfig $TransparentProxy = null,
42+
bool $AllowEnablingPermissiveMutualTLS = false,
43+
null|MeshTLSConfig $TLS = null,
44+
null|MeshHTTPConfig $HTTP = null,
45+
null|PeeringMeshConfig $Peering = null,
46+
null|\stdClass $Meta = null,
47+
int $CreateIndex = 0,
48+
int $ModifyIndex = 0
49+
) {
50+
$this->Partition = $Partition;
51+
$this->Namespace = $Namespace;
52+
$this->Meta = $Meta;
53+
$this->CreateIndex = $CreateIndex;
54+
$this->ModifyIndex = $ModifyIndex;
55+
$this->TransparentProxy = $TransparentProxy;
56+
$this->AllowEnablingPermissiveMutualTLS = $AllowEnablingPermissiveMutualTLS;
57+
$this->TLS = $TLS;
58+
$this->HTTP = $HTTP;
59+
$this->Peering = $Peering;
4060

41-
public TransparentProxyConfig $TransparentProxy;
61+
if (null !== $data && [] !== $data) {
62+
self::jsonUnserialize((object)$data, $this);
63+
}
64+
}
65+
66+
public function getKind(): string
67+
{
68+
return Consul::MeshConfig;
69+
}
70+
71+
public function getName(): string
72+
{
73+
return Consul::MeshConfigMesh;
74+
}
4275

4376
public function getTransparentProxy(): TransparentProxyConfig
4477
{

0 commit comments

Comments
 (0)