You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The expected workflow is that once you got a `FastJsonPatch` instance you can call the `apply` method each time a new patch is received and this is particularly handy in long-running context like a websocket client/server.
79
90
80
-
81
-
### Error Handling Example
82
-
83
-
All exceptions implement the interface `blancks\JsonPatch\exceptions\FastJsonPatchException` and so catching an error is pretty straightforward:
84
-
85
-
```php
86
-
use blancks\JsonPatch\FastJsonPatch;
87
-
use blancks\JsonPatch\exceptions\FastJsonPatchException;
Patch application is designed to be atomic. If any operation of a given patch fails the original document is restored.\
128
-
In this example you can see that the number of "John" has not changed.
91
+
Patch application is designed to be atomic. If any operation of a given patch fails the original document is restored, ensuring a consistent state of the document.
-**Description**: Initializes a new instance of the `FastJsonPatch` class.
136
99
-**Parameters**:
137
100
-`mixed &$document`: The decoded JSON document.
138
101
-`?JsonHandlerInterface $JsonHandler`: An instance of the JSON handler which will be responsible for encoding/decoding and CRUD operations.\
139
102
The default handler is `blancks\JsonPatch\json\handlers\BasicJsonHandler` and decodes json objects as php \stdClass instances. This is the recommended way.\
140
103
If you application requires working with associative arrays only, you can pass a `blancks\JsonPatch\json\handlers\ArrayJsonHandler` instance instead.
104
+
-`?JsonPointerHandlerInterface $JsonPointerHandler`: Instance of the object responsible to validate and parse JSON Pointers.\
105
+
The default handler is `blancks\JsonPatch\json\pointer\JsonPointer6901`
141
106
-**Returns**: Instance of the `FastJsonPatch` class.
142
107
-**Example**:
143
108
```php
@@ -147,14 +112,16 @@ In this example you can see that the number of "John" has not changed.
-**Description**: Returns a new instance of the `FastJsonPatch` class.
153
118
-**Parameters**:
154
119
-`string $document`: A json encoded document to which the patches will be applied
155
120
-`?JsonHandlerInterface $JsonHandler`: An instance of the JSON handler which will be responsible for encoding/decoding and CRUD operations.\
156
121
The default handler is `blancks\JsonPatch\json\handlers\BasicJsonHandler` and decodes json objects as php \stdClass instances. This is the recommended way.\
157
122
If you application requires working with associative arrays only, you can pass a `blancks\JsonPatch\json\handlers\ArrayJsonHandler` instance instead.
123
+
-`?JsonPointerHandlerInterface $JsonPointerHandler`: Instance of the object responsible to validate and parse JSON Pointers.\
124
+
The default handler is `blancks\JsonPatch\json\pointer\JsonPointer6901`
@@ -163,7 +130,7 @@ In this example you can see that the number of "John" has not changed.
163
130
164
131
#### `function apply(string $patch) : void`
165
132
166
-
-**Description**: Applies a series of patch operations to the specified JSON document. Ensures atomicity by applying all operations successfully or making no changes at all if any operation fails.
133
+
-**Description**: Applies a series of patch operations to the specified JSON document. Ensures atomicity by applying all operations successfully or restoring the original document if any operation fails.
167
134
-**Parameters**:
168
135
-`string $patch`: A json-encoded array of patch operations.
169
136
-**Exceptions**:
@@ -311,7 +278,14 @@ Test cases comes from [json-patch/json-patch-tests](https://github.com/json-patc
311
278
Contributions are welcome! 🎉\
312
279
Feel free to fork the repository if you'd like to contribute to this project!
313
280
314
-
Please ensure your contributions align with the project's goals and code style. If you have any questions or need guidance, feel free to open an issue or start a discussion.
281
+
Please ensure your contributions align with the project's goals and code style:
282
+
* Use `composer run static-analyse` for static analysis
283
+
* Use `composer run pretty-php` to reformat your code before commit
284
+
* Provide unit tests for the code you wrote, this project targets 100% coverage
285
+
* It is ok to write alternative handlers to address slower operations, such as working with huge json files
286
+
* Any changes that hurts the package performance in its default configuration must be motivated with a good reason
287
+
288
+
If you have any questions, need guidance, reporting a bug or suggesting an improvement feel free to open an issue. Every bit helps!
0 commit comments