Skip to content

Commit 37bbda8

Browse files
Add Jsonable interface to Listener class
Implement the Jsonable interface in the Listener class to support JSON serialization. Added explicit return types to methods and annotated the toJson method with the Override attribute for better clarity and functionality.
1 parent 5933a49 commit 37bbda8

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/Config/Listener.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@
77
ListenerPass,
88
Tls
99
};
10+
use Override;
1011
use UnitPhpSdk\Builders\EndpointBuilder;
1112
use UnitPhpSdk\Contracts\Arrayable;
13+
use UnitPhpSdk\Contracts\Jsonable;
1214
use UnitPhpSdk\Contracts\Uploadable;
1315
use UnitPhpSdk\Exceptions\UnitException;
1416
use UnitPhpSdk\Traits\CanUpload;
1517

1618
/**
1719
* This class presents "listeners" section from config
1820
*/
19-
class Listener implements Uploadable, Arrayable
21+
class Listener implements Uploadable, Arrayable, Jsonable
2022
{
2123
use CanUpload;
2224

@@ -26,6 +28,8 @@ class Listener implements Uploadable, Arrayable
2628
private ListenerPass $pass;
2729

2830
/**
31+
*
32+
*
2933
* @var int
3034
*/
3135
private int $port;
@@ -231,21 +235,22 @@ public function setForwarded(?Forwarded $forwarded): void
231235
/**
232236
* Return Listener as JSON
233237
*
234-
* @return string|false
238+
* @param int $options
239+
* @return string
235240
*/
236-
public function toJson(): string|false
241+
#[Override] public function toJson(int $options = 0): string
237242
{
238-
return json_encode($this->toArray());
243+
return json_encode($this->toArray(), $options);
239244
}
240245

241-
public function toUnitArray()
246+
public function toUnitArray(): array
242247
{
243248
return [
244249
$this->getListener() => $this->toArray()
245250
];
246251
}
247252

248-
public function getTarget()
253+
public function getTarget(): ListenerPass
249254
{
250255
return $this->getPass();
251256
}

0 commit comments

Comments
 (0)