GitHub - raphaelstolt/php-jsonpatch: JSON Patch implementation for PHP (original) (raw)

Now you can use JSON Patch for PHP via the available Composer autoload file.

Patch operations are defined in JSON and bundled in an array. Available JSON Patchoperations are add, remove, replace, move, copy, and test; if their mandatory properties are not set a Rs\Json\Patch\InvalidOperationException will be thrown.

If necessary you can disable some patch operations by setting a whitelist bitmask in the constructor e.g. $patch = new Patch($targetDocument, $patchDocument, Add::APPLY | Copy::APPLY | Replace::APPLY | Remove::APPLY);. This will not allow the usage of the move and test patch operation from the patch document. If used these operations are ignored. The default is to allow all patch operations.

patch=newPatch(patch = new Patch(patch=newPatch(targetDocument, $patchDocument); patchedDocument=patchedDocument = patchedDocument=patch->apply(); // {"a":{"b":["c","d","e"],"c":["a","b"],"e":["a"]}} } catch (InvalidPatchDocumentJsonException $e) { // Will be thrown when using invalid JSON in a patch document } catch (InvalidTargetDocumentJsonException $e) { // Will be thrown when using invalid JSON in a target document } catch (InvalidOperationException $e) { // Will be thrown when using an invalid JSON Pointer operation (i.e. missing property) } For some more usage examples of JSON Patch operations have a look at the integration tests located under `tests/integration/*`. This library is licensed under the MIT License. Please see [LICENSE](/raphaelstolt/php-jsonpatch/blob/main/LICENSE.md) for more information.