Skip to content

Commit 50ad3d0

Browse files
committed
let serializer implements Stringable
1 parent 6d0a059 commit 50ad3d0

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed

docs/usage.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ Using this methods you can use every Redmine API endpoint. The following example
598598
```php
599599
$client->requestPut(
600600
'/projects/1.xml',
601-
\Redmine\Serializer\XmlSerializer::createFromArray([
601+
(string) \Redmine\Serializer\XmlSerializer::createFromArray([
602602
'project' => [
603603
'name' => 'renamed project',
604604
'custom_fields' => [
@@ -610,7 +610,7 @@ $client->requestPut(
610610
],
611611
],
612612
]
613-
])->getEncoded()
613+
])
614614
);
615615
```
616616

@@ -620,7 +620,7 @@ Or to fetch data with complex query parameters you can use `requestGet()` with t
620620

621621
```php
622622
$client->requestGet(
623-
\Redmine\Serializer\PathSerializer::create(
623+
(string) \Redmine\Serializer\PathSerializer::create(
624624
'/time_entries.json',
625625
[
626626
'f' => ['spent_on'],
@@ -632,7 +632,7 @@ $client->requestGet(
632632
],
633633
],
634634
],
635-
)->getPath()
635+
)
636636
);
637637
```
638638

src/Redmine/Serializer/JsonSerializer.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44

55
use JsonException;
66
use Redmine\Exception\SerializerException;
7+
use Stringable;
78

89
/**
910
* JsonSerializer.
1011
*/
11-
final class JsonSerializer
12+
final class JsonSerializer implements Stringable
1213
{
1314
/**
1415
* @throws SerializerException if $data is not valid JSON
@@ -55,6 +56,11 @@ public function getEncoded(): string
5556
return $this->encoded;
5657
}
5758

59+
public function __toString(): string
60+
{
61+
return $this->getEncoded();
62+
}
63+
5864
private function decode(string $encoded): void
5965
{
6066
$this->encoded = $encoded;

src/Redmine/Serializer/PathSerializer.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
namespace Redmine\Serializer;
44

5+
use Stringable;
6+
57
/**
6-
* PathSerializer.
8+
* PathSerializer to handle query parameters.
79
*/
8-
final class PathSerializer
10+
final class PathSerializer implements Stringable
911
{
1012
public static function create(string $path, array $queryParams = []): self
1113
{
@@ -38,4 +40,9 @@ public function getPath(): string
3840

3941
return $this->path.$queryString;
4042
}
43+
44+
public function __toString(): string
45+
{
46+
return $this->getPath();
47+
}
4148
}

src/Redmine/Serializer/XmlSerializer.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
use JsonException;
66
use Redmine\Exception\SerializerException;
77
use SimpleXMLElement;
8+
use Stringable;
89
use Throwable;
910

1011
/**
1112
* XmlSerializer.
1213
*/
13-
final class XmlSerializer
14+
final class XmlSerializer implements Stringable
1415
{
1516
/**
1617
* @throws SerializerException if $data is not valid XML
@@ -59,6 +60,11 @@ public function getEncoded(): string
5960
return $this->encoded;
6061
}
6162

63+
public function __toString(): string
64+
{
65+
return $this->getEncoded();
66+
}
67+
6268
private function deserialize(string $encoded): void
6369
{
6470
$this->encoded = $encoded;

0 commit comments

Comments
 (0)