-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved the basic usage code sample in README.md with exception hand…
…ling
- Loading branch information
Showing
1 changed file
with
13 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,15 +53,26 @@ composer require blancks/fast-jsonpatch-php | |
<?php require_once 'vendor/autoload.php'; | ||
|
||
use blancks\JsonPatch\FastJsonPatch; | ||
use blancks\JsonPatch\FastJsonPatch\exceptions\FastJsonPatchException; | ||
|
||
$json = '{"name": "John", "age": 30}'; | ||
$patch = '[ | ||
{"op": "replace", "path": "/name", "value": "Jane"}, | ||
{"op": "add", "path": "/email", "value": "[email protected]"} | ||
]'; | ||
|
||
echo FastJsonPatch::apply($json, $patch); | ||
// Output: {"name": "Jane", "age": 30, "email": "[email protected]"} | ||
try { | ||
|
||
echo FastJsonPatch::apply($json, $patch); | ||
// Output: {"name": "Jane", "age": 30, "email": "[email protected]"} | ||
|
||
} catch(FastJsonPatchException $e) { | ||
|
||
// FastJsonPatchException comes with two additional methods to fetch context data: | ||
// $e->getContextPointer() may return the context JSON pointer for given error | ||
// $e->getContextDocument() may return the portion of the document relevant for the error | ||
|
||
} | ||
``` | ||
|
||
## Methods Overview | ||
|