2017 © Pedro Peláez
 

library php-json-patch

PHP JSON Patch (RFC6902) implementation

image

gamringer/php-json-patch

PHP JSON Patch (RFC6902) implementation

  • Wednesday, March 23, 2016
  • by g.amringer
  • Repository
  • 2 Watchers
  • 9 Stars
  • 3,745 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 3 Versions
  • 19 % Grown

The README.md

JSONPointer

License Latest Stable Version Latest Unstable Version Total Downloads, (*1)

SensioLabsInsight, (*2)

Build Status, (*3)

Build Status Code Coverage Scrutinizer Code Quality, (*4)

A RFC6902 compliant JSON Patch PHP implementation, (*5)

License

JSONPatch is licensed under the MIT license., (*6)

Installation

composer require gamringer/php-json-patch

Tests

composer install
phpunit

Documentation

Operations can be constructed and applied independently

<?php

$target = ['1', '2', '3'];
$operation = new \gamringer\JSONPatch\Operation\Test('/foo', 'bar');
$operation->apply($target);

Operations can also be constructed from a JSON string

<?php

$operation = \gamringer\JSONPatch\Operation\Test::fromDecodedJSON(json_decode('{"path":"/foo","value":"bar"}'));

A patch can be constructed from a set of operations

<?php

$patch = new \gamringer\JSONPatch\Patch();

$patch->addOperation(new \gamringer\JSONPatch\Operation\Add('/foo', 'bar'));
$patch->addOperation(new \gamringer\JSONPatch\Operation\Test('/foo', 'bar'));

A patch can also be constructed from a JSON string

<?php

$patch = \gamringer\JSONPatch\Patch::fromJSON('[{"op":"add","path":"/foo","value":"bar"},{"op":"test","path":"/foo","value":"bar"}]');

A patch can be applied

<?php

$patch = \gamringer\JSONPatch\Patch::fromJSON('[{"op":"add","path":"/foo","value":"bar"},{"op":"test","path":"/foo","value":"bar"}]');

$target = [];
$patch->apply($target);

var_dump($target);

/* Results:

array(1) {
  'foo' =>
  string(3) "bar"
}

*/

If the patch fails, it gets completely reverted and an exception is thrown., (*7)

<?php

$patch = \gamringer\JSONPatch\Patch::fromJSON('[{"op":"add","path":"/foo","value":"bar"},{"op":"test","path":"/foo","value":"baz"}]');

$target = [];

try {
    $patch->apply($target);
} catch (\gamringer\JSONPatch\Exception $e) {
    var_dump($target);
}

/* Results:

array(0) {}

*/

The Versions

23/03 2016

dev-master

9999999-dev https://github.com/gamringer/JSONPatch

PHP JSON Patch (RFC6902) implementation

  Sources   Download

MIT

The Requires

 

The Development Requires

by Guillaume Amringer

json json patch rfc6902 6902

19/09 2015

1.0

1.0.0.0 https://github.com/gamringer/JSONPatch

PHP JSON Patch (RFC6902) implementation

  Sources   Download

MIT

The Requires

 

The Development Requires

by Guillaume Amringer

json json patch rfc6902 6902

06/09 2015

1.0-rc

1.0.0.0-RC https://github.com/gamringer/JSONPatch

PHP JSON Patch (RFC6902) implementation

  Sources   Download

MIT

The Requires

 

The Development Requires

by Guillaume Amringer

json json patch rfc6902 6902