@@ -47,7 +47,7 @@ class QueryOptions implements RequestOptions
4747 public bool $ Pretty ;
4848
4949 public function __construct (
50- array $ data = [] , // Deprecated do not use.
50+ null | array $ data = null , // Deprecated do not use.
5151 string $ Namespace = '' ,
5252 string $ Datacenter = '' ,
5353 bool $ AllowStale = false ,
@@ -68,10 +68,6 @@ public function __construct(
6868 null |int |float |string |\DateInterval |Time \Duration $ Timeout = null ,
6969 bool $ Pretty = false ,
7070 ) {
71- if ([] !== $ data ) {
72- $ this ->jsonUnserialize ((object )$ data , $ this );
73- return ;
74- }
7571 $ this ->Namespace = $ Namespace ;
7672 $ this ->Datacenter = $ Datacenter ;
7773 $ this ->AllowStale = $ AllowStale ;
@@ -91,6 +87,9 @@ public function __construct(
9187 $ this ->Connect = $ Connect ;
9288 $ this ->Timeout = Time::Duration ($ Timeout );
9389 $ this ->Pretty = $ Pretty ;
90+ if (null !== $ data && [] !== $ data ) {
91+ $ this ->_fromMap ((object )$ data );
92+ }
9493 }
9594
9695 public function getNamespace (): string
@@ -355,27 +354,23 @@ public function apply(Request $r): void
355354 }
356355
357356 /**
358- * @param \stdClass $decoded
359- * @param \DCarbone\PHPConsulAPI\QueryOptions|null $into
360- * @return self
357+ * @param \stdClass $data
361358 * @deprecated This is only here to support construction with map. It will be removed in a future version.
362359 */
363- public static function jsonUnserialize (\stdClass $ decoded , null | self $ into = null ): static
360+ private function _fromMap (\stdClass $ data ): void
364361 {
365- $ n = $ into ?? new self ();
366- foreach ($ decoded as $ k => $ v ) {
362+ foreach ($ data as $ k => $ v ) {
367363 if ('MaxAge ' === $ k ) {
368- $ n ->MaxAge = Time::Duration ($ v );
364+ $ this ->MaxAge = Time::Duration ($ v );
369365 } elseif ('StaleIfError ' === $ k ) {
370- $ n ->StaleIfError = Time::Duration ($ v );
366+ $ this ->StaleIfError = Time::Duration ($ v );
371367 } elseif ('WaitTime ' === $ k ) {
372- $ n ->WaitTime = Time::Duration ($ v );
368+ $ this ->WaitTime = Time::Duration ($ v );
373369 } elseif ('Timeout ' === $ k ) {
374- $ n ->Timeout = Time::Duration ($ v );
370+ $ this ->Timeout = Time::Duration ($ v );
375371 } else {
376- $ n ->{$ k } = $ v ;
372+ $ this ->{$ k } = $ v ;
377373 }
378374 }
379- return $ n ;
380375 }
381376}
0 commit comments