2222
2323use DCarbone \Go \Time ;
2424use DCarbone \PHPConsulAPI \AbstractModel ;
25- use DCarbone \PHPConsulAPI \Transcoding ;
2625
2726class 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}
0 commit comments