File tree 7 files changed +34
-3
lines changed
7 files changed +34
-3
lines changed Original file line number Diff line number Diff line change 9
9
"issues" : " https://github.com/php-type-language/phpdoc/issues"
10
10
},
11
11
"require" : {
12
- "php" : " ^8.1"
12
+ "php" : " ^8.1" ,
13
+ "ext-json" : " *"
13
14
},
14
15
"autoload" : {
15
16
"psr-4" : {
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ final class DocBlock implements
21
21
OptionalDescriptionProviderInterface,
22
22
TagsProviderInterface,
23
23
\IteratorAggregate,
24
+ \JsonSerializable,
24
25
\ArrayAccess,
25
26
\Countable
26
27
{
@@ -94,6 +95,14 @@ public function getIterator(): \Traversable
94
95
return new \ArrayIterator ($ this ->tags );
95
96
}
96
97
98
+ public function jsonSerialize (): array
99
+ {
100
+ return [
101
+ 'description ' => $ this ->description ,
102
+ 'tags ' => $ this ->tags ,
103
+ ];
104
+ }
105
+
97
106
/**
98
107
* @return int<0, max>
99
108
*/
Original file line number Diff line number Diff line change @@ -37,6 +37,11 @@ public static function fromStringableOrNull(string|\Stringable|null $description
37
37
return self ::fromStringable ($ description );
38
38
}
39
39
40
+ public function jsonSerialize (): string
41
+ {
42
+ return $ this ->value ;
43
+ }
44
+
40
45
public function __toString (): string
41
46
{
42
47
return $ this ->value ;
Original file line number Diff line number Diff line change 8
8
* Any class that implements this interface is a description object
9
9
* that can be represented as a raw string scalar value.
10
10
*/
11
- interface DescriptionInterface extends \Stringable
11
+ interface DescriptionInterface extends \JsonSerializable, \ Stringable
12
12
{
13
13
/**
14
14
* Returns a plain string representation of this description.
Original file line number Diff line number Diff line change @@ -88,6 +88,11 @@ public function offsetUnset(mixed $offset): void
88
88
throw new \BadMethodCallException (static ::class . ' objects are immutable ' );
89
89
}
90
90
91
+ public function jsonSerialize (): array
92
+ {
93
+ return $ this ->components ;
94
+ }
95
+
91
96
public function __toString (): string
92
97
{
93
98
return \implode ('' , $ this ->components );
Original file line number Diff line number Diff line change @@ -31,6 +31,14 @@ public function getDescription(): ?DescriptionInterface
31
31
return $ this ->description ;
32
32
}
33
33
34
+ public function jsonSerialize (): array
35
+ {
36
+ return \array_filter ([
37
+ 'name ' => $ this ->name ,
38
+ 'description ' => $ this ->description ,
39
+ ], static fn (mixed $ value ): bool => $ value !== null );
40
+ }
41
+
34
42
public function __toString (): string
35
43
{
36
44
if ($ this ->description === null ) {
Original file line number Diff line number Diff line change 6
6
7
7
use TypeLang \PHPDoc \Tag \Description \OptionalDescriptionProviderInterface ;
8
8
9
- interface TagInterface extends OptionalDescriptionProviderInterface, \Stringable
9
+ interface TagInterface extends
10
+ OptionalDescriptionProviderInterface,
11
+ \JsonSerializable,
12
+ \Stringable
10
13
{
11
14
/**
12
15
* Returns the non-empty tag name string without the '@' prefix.
You can’t perform that action at this time.
0 commit comments