1 | <?php |
||
19 | class Gson |
||
20 | { |
||
21 | /** |
||
22 | * A service to fetch the correct [@see TypeAdapter] for a given type |
||
23 | * |
||
24 | * @var TypeAdapterProvider |
||
25 | */ |
||
26 | private $typeAdapterProvider; |
||
27 | |||
28 | /** |
||
29 | * A factory that reflects over class properties and returns a collection |
||
30 | * of [@see Property] objects |
||
31 | * |
||
32 | * @var \Tebru\Gson\Internal\Data\PropertyCollectionFactory |
||
33 | */ |
||
34 | private $propertyCollectionFactory; |
||
35 | |||
36 | /** |
||
37 | * True if we should serialize nulls |
||
38 | * |
||
39 | * @var bool |
||
40 | */ |
||
41 | private $serializeNull; |
||
42 | |||
43 | /** |
||
44 | * Constructor |
||
45 | * |
||
46 | * @param TypeAdapterProvider $typeAdapterProvider |
||
47 | * @param PropertyCollectionFactory $propertyCollectionFactory |
||
48 | * @param bool $serializeNull |
||
49 | */ |
||
50 | 25 | public function __construct( |
|
59 | |||
60 | /** |
||
61 | * Create a new builder object |
||
62 | * |
||
63 | * @return GsonBuilder |
||
64 | */ |
||
65 | 28 | public static function builder(): GsonBuilder |
|
69 | |||
70 | /** |
||
71 | * Converts an object to a json string |
||
72 | * |
||
73 | * @param mixed $object |
||
74 | * @return string |
||
75 | * @throws \Tebru\Gson\Exception\MalformedTypeException If the type cannot be parsed |
||
76 | * @throws \InvalidArgumentException if the type cannot be handled by a type adapter |
||
77 | */ |
||
78 | 11 | public function toJson($object): string |
|
85 | |||
86 | /** |
||
87 | * Converts a json string to a valid json type |
||
88 | * |
||
89 | * @param string $json |
||
90 | * @param object|string $type |
||
91 | * @return mixed |
||
92 | * @throws \Tebru\Gson\Exception\MalformedTypeException If the type cannot be parsed |
||
93 | * @throws \InvalidArgumentException if the type cannot be handled by a type adapter |
||
94 | * @throws \RuntimeException If the value is not valid |
||
95 | * @throws \Tebru\Gson\Exception\MalformedTypeException If the type cannot be parsed |
||
96 | * @throws \InvalidArgumentException if the type cannot be handled by a type adapter |
||
97 | */ |
||
98 | 15 | public function fromJson(string $json, $type) |
|
117 | |||
118 | /** |
||
119 | * Converts an object to a [@see JsonElement] |
||
120 | * |
||
121 | * This is a convenience method that first converts an object to json utilizing all of the |
||
122 | * type adapters, then converts that json to a JsonElement. From here you can modify the |
||
123 | * JsonElement and call json_encode() on it to get json. |
||
124 | * |
||
125 | * @param mixed $object |
||
126 | * @return JsonElement |
||
127 | * @throws \Tebru\Gson\Exception\MalformedTypeException If the type cannot be parsed |
||
128 | * @throws \InvalidArgumentException if the type cannot be handled by a type adapter |
||
129 | * @throws \RuntimeException If the value is not valid |
||
130 | * @throws \Tebru\Gson\Exception\MalformedTypeException If the type cannot be parsed |
||
131 | * @throws \InvalidArgumentException if the type cannot be handled by a type adapter |
||
132 | */ |
||
133 | 1 | public function toJsonElement($object): JsonElement |
|
137 | } |
||
138 |