2017 © Pedro Peláez
 

library php-jsonpatch

Implementation of JSON Patch (http://tools.ietf.org/html/rfc6902)

image

php-jsonpatch/php-jsonpatch

Implementation of JSON Patch (http://tools.ietf.org/html/rfc6902)

  • PHP
  • 6 Dependents
  • 0 Suggesters
  • 18 Forks
  • 5 Open issues
  • 27 Versions
  • 8 % Grown

The README.md

JSON Patch for PHP

Test Version PHP Version, (*1)

This is an implementation of JSON Patch written in PHP., (*2)

Installation via Composer

``` bash composer require php-jsonpatch/php-jsonpatch, (*3)


### Usage 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 Patch [operations](http://tools.ietf.org/html/rfc6902#section-4) 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. ``` php <?php require_once 'vendor/autoload.php'; use Rs\Json\Patch; use Rs\Json\Patch\InvalidPatchDocumentJsonException; use Rs\Json\Patch\InvalidTargetDocumentJsonException; use Rs\Json\Patch\InvalidOperationException; try { $targetDocument = '{"a":{"b":["c","d","e"]}}'; $patchDocument = '[ {"op":"add", "path":"/a/d", "value":["a","b"]}, // {"a":{"b":["c","d","e"],"d":["a","b"]}} {"op":"test", "path":"/a/d/-", "value":"b"}, // previous target document {"op":"remove", "path":"/a/d/-"}, // {"a":{"b":["c","d","e"],"d":["a"]}} {"op":"test", "path":"/a/d/-", "value":"a"}, // previous target document {"op":"add", "path":"/a/d/-", "value":"b"}, // {"a":{"b":["c","d","e"],"d":["a","b"]}} {"op":"test", "path":"/a/d", "value":["a","b"]}, // previous target document {"op":"move", "path":"/a/c", "from":"/a/d"}, // {"a":{"b":["c","d","e"],"c":["a","b"]}} {"op":"test", "path":"/a/c", "value":["a","b"]}, // previous target document {"op":"copy", "path":"/a/e", "from":"/a/c"}, // {"a":{"b":["c","d","e"],"c":["a","b"],"e":["a","b"]}} {"op":"test", "path":"/a/e", "value":["a","b"]}, // previous target document {"op":"replace", "path":"/a/e", "value":["a"]}, // {"a":{"b":["c","d","e"],"c":["a","b"],"e":["a"]}} {"op":"test", "path":"/a/e", "value":["a"]} // previous target document ]'; $patch = new Patch($targetDocument, $patchDocument); $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/*., (*4)

Running tests

bash composer test, (*5)

License

This library is licensed under the MIT License. Please see LICENSE for more information., (*6)

Changelog

Please see CHANGELOG for more information., (*7)

Contributing

Please see CONTRIBUTING for more information., (*8)

The Versions

15/06 2018

dev-master

9999999-dev https://github.com/raphaelstolt/php-jsonpatch

Implementation of JSON Patch (http://tools.ietf.org/html/rfc6902)

  Sources   Download

MIT

The Requires

 

The Development Requires

json json patch json modification

25/11 2016

v3.0.2

3.0.2.0 https://github.com/raphaelstolt/php-jsonpatch

Implementation of JSON Patch (http://tools.ietf.org/html/rfc6902)

  Sources   Download

MIT

The Requires

 

The Development Requires

json json patch json modification

25/08 2016

v3.0.1

3.0.1.0 https://github.com/raphaelstolt/php-jsonpatch

Implementation of JSON Patch (http://tools.ietf.org/html/rfc6902)

  Sources   Download

MIT

The Requires

 

The Development Requires

json json patch json modification

22/08 2016

v3.0.0

3.0.0.0 https://github.com/raphaelstolt/php-jsonpatch

Implementation of JSON Patch (http://tools.ietf.org/html/rfc6902)

  Sources   Download

MIT

The Requires

 

The Development Requires

json json patch json modification

12/08 2016

v2.1.4

2.1.4.0 https://github.com/raphaelstolt/php-jsonpatch

Implementation of JSON Patch (http://tools.ietf.org/html/rfc6902)

  Sources   Download

MIT

The Requires

 

The Development Requires

json json patch json modification

21/07 2016

v2.1.3

2.1.3.0 https://github.com/raphaelstolt/php-jsonpatch

Implementation of JSON Patch (http://tools.ietf.org/html/rfc6902)

  Sources   Download

MIT

The Requires

 

The Development Requires

json json patch json modification

20/07 2016

v2.1.2

2.1.2.0 https://github.com/raphaelstolt/php-jsonpatch

Implementation of JSON Patch (http://tools.ietf.org/html/rfc6902)

  Sources   Download

MIT

The Requires

 

The Development Requires

json json patch json modification

25/06 2016

v2.1.1

2.1.1.0 https://github.com/raphaelstolt/php-jsonpatch

Implementation of JSON Patch (http://tools.ietf.org/html/rfc6902)

  Sources   Download

MIT

The Requires

 

The Development Requires

json json patch json modification

24/06 2016

v2.1.0

2.1.0.0 https://github.com/raphaelstolt/php-jsonpatch

Implementation of JSON Patch (http://tools.ietf.org/html/rfc6902)

  Sources   Download

MIT

The Requires

 

The Development Requires

json json patch json modification

23/06 2016

v2.0.1

2.0.1.0 https://github.com/raphaelstolt/php-jsonpatch

Implementation of JSON Patch (http://tools.ietf.org/html/rfc6902)

  Sources   Download

MIT

The Requires

 

The Development Requires

json json patch json modification

20/06 2016

v2.0.0

2.0.0.0 https://github.com/raphaelstolt/php-jsonpatch

Implementation of JSON Patch (http://tools.ietf.org/html/rfc6902)

  Sources   Download

MIT

The Requires

 

The Development Requires

json json patch json modification

27/04 2016

2.0.x-dev

2.0.9999999.9999999-dev https://github.com/raphaelstolt/php-jsonpatch

Implementation of JSON Patch (http://tools.ietf.org/html/rfc6902)

  Sources   Download

MIT

The Requires

 

The Development Requires

json json patch json modification

27/04 2016

v1.3.1

1.3.1.0 https://github.com/raphaelstolt/php-jsonpatch

Implementation of JSON Patch (http://tools.ietf.org/html/rfc6902)

  Sources   Download

MIT

The Requires

 

The Development Requires

json json patch json modification

08/04 2016

v1.3.0

1.3.0.0 https://github.com/raphaelstolt/php-jsonpatch

Implementation of JSON Patch (http://tools.ietf.org/html/rfc6902)

  Sources   Download

MIT

The Requires

 

The Development Requires

json json patch json modification

08/04 2016

v1.2.6

1.2.6.0 https://github.com/raphaelstolt/php-jsonpatch

Implementation of JSON Patch (http://tools.ietf.org/html/rfc6902)

  Sources   Download

MIT

The Requires

 

The Development Requires

json json patch json modification

25/02 2016

v1.2.5

1.2.5.0 https://github.com/raphaelstolt/php-jsonpatch

Implementation of JSON Patch (http://tools.ietf.org/html/rfc6902)

  Sources   Download

MIT

The Requires

 

The Development Requires

json json patch json modification

12/02 2016

v1.2.4

1.2.4.0 https://github.com/raphaelstolt/php-jsonpatch

Implementation of JSON Patch (http://tools.ietf.org/html/rfc6902)

  Sources   Download

MIT

The Requires

 

The Development Requires

json json patch json modification

04/01 2016

v1.2.3

1.2.3.0 https://github.com/raphaelstolt/php-jsonpatch

Implementation of JSON Patch (http://tools.ietf.org/html/rfc6902)

  Sources   Download

MIT

The Requires

 

The Development Requires

json json patch json modification

21/08 2015

v1.2.2

1.2.2.0 https://github.com/raphaelstolt/php-jsonpatch

Implementation of JSON Patch (http://tools.ietf.org/html/rfc6902)

  Sources   Download

MIT

The Requires

 

The Development Requires

json json patch json modification

20/08 2015

v1.2.1

1.2.1.0 https://github.com/raphaelstolt/php-jsonpatch

Implementation of JSON Patch (http://tools.ietf.org/html/rfc6902)

  Sources   Download

MIT

The Requires

 

The Development Requires

json json patch json modification

05/06 2015

1.2.x-dev

1.2.9999999.9999999-dev https://github.com/raphaelstolt/php-jsonpatch

Implementation of JSON Patch (http://tools.ietf.org/html/rfc6902)

  Sources   Download

MIT

The Requires

 

The Development Requires

json json patch json modification

21/05 2015

v1.2.0

1.2.0.0 https://github.com/raphaelstolt/php-jsonpatch

Implementation of JSON Patch (http://tools.ietf.org/html/rfc6902)

  Sources   Download

MIT

The Requires

 

json json patch json modification

27/04 2015

v1.2.0-RC1

1.2.0.0-RC1 https://github.com/raphaelstolt/php-jsonpatch

Implementation of JSON Patch (http://tools.ietf.org/html/rfc6902)

  Sources   Download

MIT

The Requires

 

json json patch json modification

02/12 2014

v1.1.0-RC1

1.1.0.0-RC1 https://github.com/raphaelstolt/php-jsonpatch

Implementation of JSON Patch (http://tools.ietf.org/html/rfc6902)

  Sources   Download

MIT

The Requires

 

json json patch json modification

02/12 2014

v1.0.0-RC3

1.0.0.0-RC3 https://github.com/raphaelstolt/php-jsonpatch

Implementation of JSON Patch (http://tools.ietf.org/html/rfc6902)

  Sources   Download

MIT

The Requires

 

json json patch json modification

28/11 2014

v1.0.0-RC2

1.0.0.0-RC2 https://github.com/raphaelstolt/php-jsonpatch

Implementation of JSON Patch (http://tools.ietf.org/html/rfc6902)

  Sources   Download

MIT

The Requires

 

json json patch json modification

19/04 2013

v1.0.0-RC1

1.0.0.0-RC1 https://github.com/raphaelstolt/php-jsonpatch

Implementation of JSON Patch (http://tools.ietf.org/html/rfc6902)

  Sources   Download

MIT

The Requires

 

json json patch json modification