2017 © Pedro Peláez
 

library php-json-patch

JSON Patch (RFC-6902) PHP implementation

image

remorhaz/php-json-patch

JSON Patch (RFC-6902) PHP implementation

  • Thursday, February 15, 2018
  • by remorhaz
  • Repository
  • 2 Watchers
  • 2 Stars
  • 723 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 9 Versions
  • 28 % Grown

The README.md

PHP JSON Patch

Latest Stable Version Build Scrutinizer Code Quality codecov Mutation testing badgeTotal Downloads License, (*1)

This library implements RFC6902-compliant JSON patch tool., (*2)

Requirements

Installation

You will need composer to perform install., (*3)

composer require remorhaz/php-json-patch

Documentation

Accessing JSON document

You can create accessible JSON document either from encoded JSON string or from decoded JSON data using corresponding node value factory:, (*4)

use Remorhaz\JSON\Data\Value\EncodedJson;
use Remorhaz\JSON\Data\Value\DecodedJson;

// Creating document from JSON-encoded string:
$encodedValueFactory = EncodedJson\NodeValueFactory::create();
$encodedJson = '{"a":1}';
$document1 = $encodedValueFactory->createValue($encodedJson);

// Creating document from decoded JSON data:
$decodedValueFactory = DecodedJson\NodeValueFactory::create();
$decodedJson = (object) ['a' => 1];
$document2 = $decodedValueFactory->createValue($decodedJson);

Creating and processing query

You should use query factory to create query from JSON Patch document. Then you should use processor to apply that query:, (*5)

<?php
use Remorhaz\JSON\Data\Value\EncodedJson;
use Remorhaz\JSON\Patch\Processor\Processor;
use Remorhaz\JSON\Patch\Query\QueryFactory;

$encodedValueFactory = EncodedJson\NodeValueFactory::create();
$queryFactory = QueryFactory::create();
$processor = Processor::create();

$patch = $encodedValueFactory->createValue('[{"op":"remove","path":"/0"}]');
$query = $queryFactory->createQuery($patch);

$document = $encodedValueFactory->createValue('[1,2]');
$result = $processor->apply($query, $document);

var_dump($result->encode()); // string: '[2]'
var_dump($result->decode()); // array: [2]

Note that result can be exported either to JSON-encoded string or to raw PHP value., (*6)

License

PHP JSON Patch is licensed under MIT license., (*7)

The Versions

15/02 2018

dev-master

9999999-dev https://github.com/remorhaz/php-json-patch

JSON Patch (RFC-6902) PHP implementation

  Sources   Download

MIT

The Requires

 

The Development Requires

by Edward Surov

json json patch rfc6902

15/02 2018

v0.4.0

0.4.0.0 https://github.com/remorhaz/php-json-patch

JSON Patch (RFC-6902) PHP implementation

  Sources   Download

MIT

The Requires

 

The Development Requires

by Edward Surov

json json patch rfc6902

13/02 2018

v0.3.1

0.3.1.0 https://github.com/remorhaz/php-json-patch

JSON Patch (RFC-6902) PHP implementation

  Sources   Download

MIT

The Requires

 

The Development Requires

by Edward Surov

json json patch rfc6902

12/04 2017

v0.3.0

0.3.0.0 https://github.com/remorhaz/php-json-patch

JSON Patch (RFC-6902) PHP implementation

  Sources   Download

MIT

The Requires

 

The Development Requires

by Edward Surov

json json patch rfc6902

07/03 2017

v0.2.2

0.2.2.0 https://github.com/remorhaz/php-json-patch

JSON Patch (RFC-6902) PHP implementation

  Sources   Download

MIT

The Requires

 

The Development Requires

by Edward Surov

json json patch rfc6902

11/11 2016

v0.2.1

0.2.1.0 https://github.com/remorhaz/php-json-patch

JSON Patch (RFC-6902) PHP implementation

  Sources   Download

MIT

The Requires

 

The Development Requires

by Edward Surov

json json patch rfc6902

11/11 2016

v0.2.0

0.2.0.0 https://github.com/remorhaz/php-json-patch

JSON Patch (RFC-6902) PHP implementation

  Sources   Download

MIT

The Requires

 

The Development Requires

by Edward Surov

json json patch rfc6902

10/11 2016

v0.1.1

0.1.1.0 https://github.com/remorhaz/php-json-patch

JSON Patch (RFC-6902) PHP implementation

  Sources   Download

MIT

The Requires

 

The Development Requires

by Edward Surov

json json patch rfc6902

09/11 2016

v0.1.0

0.1.0.0 https://github.com/remorhaz/php-json-patch

JSON Patch (RFC-6902) PHP implementation

  Sources   Download

MIT

The Requires

 

The Development Requires

by Edward Surov

json json patch rfc6902