Skip to content

Commit cc0831e

Browse files
committed
working on v3
1 parent 8595c87 commit cc0831e

119 files changed

Lines changed: 1912 additions & 1555 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

composer.lock

Lines changed: 222 additions & 286 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ACL/ACLAuthMethod.php

Lines changed: 98 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -22,54 +22,46 @@
2222

2323
use DCarbone\Go\Time;
2424
use DCarbone\PHPConsulAPI\AbstractModel;
25-
use DCarbone\PHPConsulAPI\Transcoding;
2625

2726
class ACLAuthMethod extends AbstractModel
2827
{
29-
protected const FIELDS = [
30-
self::FIELD_DISPLAY_NAME => Transcoding::OMITEMPTY_STRING_FIELD,
31-
self::FIELD_DESCRIPTION => Transcoding::OMITEMPTY_STRING_FIELD,
32-
self::FIELD_MAX_TOKEN_TTL => [
33-
Transcoding::FIELD_UNMARSHAL_CALLBACK => Transcoding::UNMARSHAL_DURATION,
34-
Transcoding::FIELD_MARSHAL_AS => Transcoding::STRING,
35-
Transcoding::FIELD_OMITEMPTY => true,
36-
],
37-
self::FIELD_TOKEN_LOCALITY => Transcoding::OMITEMPTY_STRING_FIELD,
38-
self::FIELD_NAMESPACE_RULES => [
39-
Transcoding::FIELD_TYPE => Transcoding::ARRAY,
40-
Transcoding::FIELD_CLASS => ACLAuthMethodNamespaceRule::class,
41-
Transcoding::FIELD_ARRAY_TYPE => Transcoding::class,
42-
Transcoding::FIELD_OMITEMPTY => true,
43-
],
44-
self::FIELD_NAMESPACE => Transcoding::OMITEMPTY_STRING_FIELD,
45-
];
46-
47-
private const FIELD_DISPLAY_NAME = 'DisplayName';
48-
private const FIELD_DESCRIPTION = 'Description';
49-
private const FIELD_MAX_TOKEN_TTL = 'MaxTokenTTL';
50-
private const FIELD_TOKEN_LOCALITY = 'TokenLocality';
51-
private const FIELD_NAMESPACE_RULES = 'NamespaceRules';
52-
private const FIELD_NAMESPACE = 'Namespace';
53-
54-
public string $ID = '';
55-
public string $Name = '';
56-
public string $Type = '';
57-
public string $DisplayName = '';
58-
public string $Description = '';
28+
public string $ID;
29+
public string $Name;
30+
public string $Type;
31+
public string $DisplayName;
32+
public string $Description;
5933
public Time\Duration $MaxTokenTTL;
60-
public string $TokenLocality = '';
61-
public array $config = [];
62-
public int $CreateIndex = 0;
63-
public int $ModifyIndex = 0;
64-
public array $NamespaceRules = [];
65-
public string $Namespace = '';
66-
67-
public function __construct(?array $data = null)
68-
{
69-
parent::__construct($data);
70-
if (!isset($this->MaxTokenTTL)) {
71-
$this->MaxTokenTTL = new Time\Duration();
72-
}
34+
public string $TokenLocality;
35+
public array $config;
36+
public int $CreateIndex;
37+
public int $ModifyIndex;
38+
public array $NamespaceRules;
39+
public string $Namespace;
40+
41+
public function __construct(
42+
string $ID = '',
43+
string $Name = '',
44+
string $Type = '',
45+
string $DisplayName = '',
46+
string $Description = '',
47+
null|int|float|string|\DateInterval|Time\Duration $MaxTokenTTL = null,
48+
string $TokenLocality = '',
49+
int $CreateIndex = 0,
50+
int $ModifyIndex = 0,
51+
iterable $NamespaceRules = [],
52+
string $Namespace = ''
53+
) {
54+
$this->ID = $ID;
55+
$this->Name = $Name;
56+
$this->Type = $Type;
57+
$this->DisplayName = $DisplayName;
58+
$this->Description = $Description;
59+
$this->setMaxTokenTTL($MaxTokenTTL);
60+
$this->TokenLocality = $TokenLocality;
61+
$this->CreateIndex = $CreateIndex;
62+
$this->ModifyIndex = $ModifyIndex;
63+
$this->setNamespaceRules(...$NamespaceRules);
64+
$this->Namespace = $Namespace;
7365
}
7466

7567
public function getID(): string
@@ -132,9 +124,9 @@ public function getMaxTokenTTL(): Time\Duration
132124
return $this->MaxTokenTTL;
133125
}
134126

135-
public function setMaxTokenTTL(int|string|Time\Duration $MaxTokenTTL): self
127+
public function setMaxTokenTTL(null|int|float|string|\DateInterval|Time\Duration $MaxTokenTTL): self
136128
{
137-
$this->MaxTokenTTL = Time::ParseDuration($MaxTokenTTL);
129+
$this->MaxTokenTTL = Time::Duration($MaxTokenTTL);
138130
return $this;
139131
}
140132

@@ -187,9 +179,15 @@ public function getNamespaceRules(): array
187179
return $this->NamespaceRules;
188180
}
189181

190-
public function setNamespaceRules(array $NamespaceRules): self
182+
public function addNamespaceRule(ACLAuthMethodNamespaceRule $rule): self
183+
{
184+
$this->NamespaceRules[] = $rule;
185+
return $this;
186+
}
187+
188+
public function setNamespaceRules(ACLAuthMethodNamespaceRule ...$rules): self
191189
{
192-
$this->NamespaceRules = $NamespaceRules;
190+
$this->NamespaceRules = $rules;
193191
return $this;
194192
}
195193

@@ -203,4 +201,56 @@ public function setNamespace(string $Namespace): self
203201
$this->Namespace = $Namespace;
204202
return $this;
205203
}
204+
205+
public static function jsonUnserialize(\stdClass $decoded): self
206+
{
207+
$n = new static();
208+
foreach ($decoded as $k => $v) {
209+
switch ($k) {
210+
case 'MaxTokenTTL':
211+
$n->setMaxTokenTTL($v);
212+
break;
213+
case 'NamespaceRules':
214+
foreach ($v as $vv) {
215+
$n->addNamespaceRule(ACLAuthMethodNamespaceRule::jsonUnserialize($vv));
216+
}
217+
break;
218+
219+
default:
220+
$n->{$k} = $v;
221+
}
222+
}
223+
return $n;
224+
}
225+
226+
public function jsonSerialize(): \stdClass
227+
{
228+
$out = new \stdClass();
229+
foreach ($this->_getDynamicFields() as $k => $v) {
230+
$out->{$k} = $v;
231+
}
232+
$out->ID = $this->ID;
233+
$out->Name = $this->Name;
234+
if ('' !== $this->DisplayName) {
235+
$out->DisplayName = $this->DisplayName;
236+
}
237+
if ('' !== $this->Description) {
238+
$out->Description = $this->Description;
239+
}
240+
if (0 !== $this->MaxTokenTTL->Nanoseconds()) {
241+
$out->MaxTokenTTL = (string)$this->MaxTokenTTL;
242+
}
243+
if ('' !== $this->TokenLocality) {
244+
$out->TokenLocality = $this->TokenLocality;
245+
}
246+
$out->CreateIndex = $this->CreateIndex;
247+
$out->ModifyIndex = $this->ModifyIndex;
248+
if ([] !== $this->NamespaceRules) {
249+
$out->NamespaceRules = $this->NamespaceRules;
250+
}
251+
if ('' !== $this->Namespace) {
252+
$out->Namespace = $this->Namespace;
253+
}
254+
return $out;
255+
}
206256
}

src/ACL/ACLAuthMethodListEntry.php

Lines changed: 70 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -22,42 +22,45 @@
2222

2323
use DCarbone\Go\Time;
2424
use DCarbone\PHPConsulAPI\AbstractModel;
25-
use DCarbone\PHPConsulAPI\Transcoding;
2625

2726
class ACLAuthMethodListEntry extends AbstractModel
2827
{
29-
protected const FIELDS = [
30-
self::FIELD_DISPLAY_NAME => Transcoding::OMITEMPTY_STRING_FIELD,
31-
self::FIELD_DESCRIPTION => Transcoding::OMITEMPTY_STRING_FIELD,
32-
self::FIELD_MAX_TOKEN_TTL => [
33-
Transcoding::FIELD_MARSHAL_AS => Transcoding::STRING,
34-
Transcoding::FIELD_OMITEMPTY => true,
35-
Transcoding::FIELD_UNMARSHAL_CALLBACK => Transcoding::UNMARSHAL_DURATION,
36-
],
37-
self::FIELD_TOKEN_LOCALITY => Transcoding::OMITEMPTY_STRING_FIELD,
38-
self::FIELD_NAMESPACE => Transcoding::OMITEMPTY_STRING_FIELD,
39-
];
40-
41-
private const FIELD_DISPLAY_NAME = 'DisplayName';
42-
private const FIELD_DESCRIPTION = 'Description';
43-
private const FIELD_MAX_TOKEN_TTL = 'MaxTokenTTL';
44-
private const FIELD_TOKEN_LOCALITY = 'TokenLocality';
45-
private const FIELD_NAMESPACE = 'Namespace';
46-
47-
public string $Name = '';
48-
public string $Type = '';
49-
public string $DisplayName = '';
50-
public string $Description = '';
28+
public string $Name;
29+
public string $Type;
30+
public string $DisplayName;
31+
public string $Description;
5132
public Time\Duration $MaxTokenTTL;
5233
/**
5334
* TokenLocality defines the kind of token that this auth method produces.
5435
* This can be either 'local' or 'global'. If empty 'local' is assumed.
5536
* @var string
5637
*/
5738
public string $TokenLocality;
58-
public int $CreateIndex = 0;
59-
public int $ModifyIndex = 0;
60-
public string $Namespace = '';
39+
public int $CreateIndex;
40+
public int $ModifyIndex;
41+
public string $Namespace;
42+
43+
public function __construct(
44+
string $Name = '',
45+
string $Type = '',
46+
string $DisplayName = '',
47+
string $Description = '',
48+
null|int|float|string|\DateInterval|Time\Duration $MaxTokenTTL = null,
49+
string $TokenLocality = '',
50+
int $CreateIndex = 0,
51+
int $ModifyIndex = 0,
52+
string $Namespace = ''
53+
) {
54+
$this->Name = $Name;
55+
$this->Type = $Type;
56+
$this->DisplayName = $DisplayName;
57+
$this->Description = $Description;
58+
$this->setMaxTokenTTL($MaxTokenTTL);
59+
$this->TokenLocality = $TokenLocality;
60+
$this->CreateIndex = $CreateIndex;
61+
$this->ModifyIndex = $ModifyIndex;
62+
$this->Namespace = $Namespace;
63+
}
6164

6265
public function getName(): string
6366
{
@@ -108,9 +111,9 @@ public function getMaxTokenTTL(): Time\Duration
108111
return $this->MaxTokenTTL;
109112
}
110113

111-
public function setMaxTokenTTL(Time\Duration $MaxTokenTTL): self
114+
public function setMaxTokenTTL(null|int|float|string|\DateInterval|Time\Duration $MaxTokenTTL): self
112115
{
113-
$this->MaxTokenTTL = $MaxTokenTTL;
116+
$this->MaxTokenTTL = Time::Duration($MaxTokenTTL);
114117
return $this;
115118
}
116119

@@ -171,13 +174,46 @@ public function setNamespace(string $Namespace): self
171174
return $this;
172175
}
173176

174-
public function jsonSerialize(): array
177+
public static function jsonUnserialize(\stdClass $decoded): self
175178
{
176-
$out = parent::jsonSerialize();
177-
if (!isset($this->MaxTokenTTL) || 0 === $this->MaxTokenTTL->Nanoseconds()) {
178-
$out[self::FIELD_MAX_TOKEN_TTL] = '';
179-
} else {
180-
$out[self::FIELD_MAX_TOKEN_TTL] = (string)$this->MaxTokenTTL;
179+
$n = new static();
180+
foreach ($decoded as $k => $v) {
181+
if (null === $v) {
182+
continue;
183+
}
184+
if ('MaxTokenTTL' === $k) {
185+
$n->setMaxTokenTTL($v);
186+
} else {
187+
$n->{$k} = $v;
188+
}
189+
}
190+
return $n;
191+
}
192+
193+
public function jsonSerialize(): \stdClass
194+
{
195+
$out = new \stdClass();
196+
foreach ($this->_getDynamicFields() as $k => $v) {
197+
$out->{$k} = $v;
198+
}
199+
$out->Name = $this->Name;
200+
$out->Type = $this->Type;
201+
if ('' !== $this->DisplayName) {
202+
$out->DisplayName = $this->DisplayName;
203+
}
204+
if ('' !== $this->Description) {
205+
$out->Description = $this->Description;
206+
}
207+
if (0 !== $this->MaxTokenTTL->Nanoseconds()) {
208+
$out->MaxTokenTTL = (string)$this->MaxTokenTTL;
209+
}
210+
if ('' !== $this->TokenLocality) {
211+
$out->TokenLocality = $this->TokenLocality;
212+
}
213+
$out->CreateIndex = $this->CreateIndex;
214+
$out->ModifyIndex = $this->ModifyIndex;
215+
if ('' !== $this->Namespace) {
216+
$out->Namespace = $this->Namespace;
181217
}
182218
return $out;
183219
}

src/ACL/ACLAuthMethodListEntryQueryResponse.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,17 @@
2525

2626
class ACLAuthMethodListEntryQueryResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface
2727
{
28-
public ?array $ACLAuthMethodListEntries = [];
28+
public array $ACLAuthMethodListEntries = [];
2929

30-
public function getValue(): ?array
30+
public function getValue(): array
3131
{
3232
return $this->ACLAuthMethodListEntries;
3333
}
3434

3535
public function unmarshalValue(mixed $decodedData): void
3636
{
37-
$this->ACLAuthMethodListEntries = [];
3837
foreach ($decodedData as $datum) {
39-
$this->ACLAuthMethodListEntries[] = new ACLAuthMethodListEntry($datum);
38+
$this->ACLAuthMethodListEntries[] = ACLAuthMethodListEntry::jsonUnserialize($datum);
4039
}
4140
}
4241
}

src/ACL/ACLAuthMethodNamespaceRule.php

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,17 @@
2121
*/
2222

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

2625
class ACLAuthMethodNamespaceRule extends AbstractModel
2726
{
28-
protected const FIELDS = [
29-
self::FIELD_SELECTOR => Transcoding::OMITEMPTY_STRING_FIELD,
30-
self::FIELD_BIND_NAMESPACE => Transcoding::OMITEMPTY_STRING_FIELD,
31-
];
27+
public string $Selector;
28+
public string $BindNamespace;
3229

33-
private const FIELD_SELECTOR = 'Selector';
34-
private const FIELD_BIND_NAMESPACE = 'BindNamespace';
35-
36-
public string $Selector = '';
37-
public string $BindNamespace = '';
30+
public function __construct(string $Selector = '', string $BindNamespace = '')
31+
{
32+
$this->Selector = $Selector;
33+
$this->BindNamespace = $BindNamespace;
34+
}
3835

3936
public function getSelector(): string
4037
{
@@ -57,4 +54,28 @@ public function setBindNamespace(string $BindNamespace): self
5754
$this->BindNamespace = $BindNamespace;
5855
return $this;
5956
}
57+
58+
public static function jsonUnserialize(\stdClass $decoded): self
59+
{
60+
$n = new static();
61+
foreach ($decoded as $k => $v) {
62+
$n->{$k} = $v;
63+
}
64+
return $n;
65+
}
66+
67+
public function jsonSerialize(): \stdClass
68+
{
69+
$out = new \stdClass();
70+
foreach ($this->_getDynamicFields() as $k => $v) {
71+
$out->{$k} = $v;
72+
}
73+
if ('' !== $this->Selector) {
74+
$out->Selector = $this->Selector;
75+
}
76+
if ('' !== $this->BindNamespace) {
77+
$out->BindNamespace = $this->BindNamespace;
78+
}
79+
return $out;
80+
}
6081
}

0 commit comments

Comments
 (0)