Skip to content

Add JSON Merge Patch support #13 #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
/phpunit.xml export-ignore
/changelog.md export-ignore
/Makefile export-ignore
/.gitlab-ci.yml
39 changes: 39 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
before_script:
- apt-get update -yqq
- apt-get install git unzip -yqq
- curl https://composer.github.io/installer.sig | tr -d '\n' > installer.sig
- php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
- php -r "if (hash_file('SHA384', 'composer-setup.php') === file_get_contents('installer.sig')) { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
- php composer-setup.php
- php -r "unlink('composer-setup.php'); unlink('installer.sig');"
- php composer.phar install --prefer-dist --no-ansi --no-interaction --no-progress

test:5.6:
image: php:5.6
script:
- pecl install xdebug-2.5.5
- docker-php-ext-enable xdebug
- vendor/bin/phpunit --configuration phpunit.xml -v --coverage-text --colors=never --stderr

test:7.0:
image: php:7.0
script:
- pecl install xdebug
- docker-php-ext-enable xdebug
- vendor/bin/phpunit --configuration phpunit.xml -v --coverage-text --colors=never --stderr

test:7.1:
image: php:7.1
script:
- pecl install xdebug
- docker-php-ext-enable xdebug
- vendor/bin/phpunit --configuration phpunit.xml -v --coverage-text --colors=never --stderr

test:7.2:
image: php:7.2
script:
- pecl install xdebug
- docker-php-ext-enable xdebug
- vendor/bin/phpunit --configuration phpunit.xml -v --coverage-text --colors=never --stderr
- curl https://github.com/phpstan/phpstan/releases/download/0.9.2/phpstan.phar -sLo ./phpstan.phar
- php phpstan.phar analyze -l 7 ./src
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ cache:
# execute any number of scripts before the test run, custom env's are available as variables
before_script:
- composer install --dev --no-interaction --prefer-dist
- if [[ $(phpenv version-name) =~ 7.2 ]] ; then test -f $HOME/.composer/cache/phpstan.phar || wget https://github.com/phpstan/phpstan/releases/download/0.9.1/phpstan.phar -O $HOME/.composer/cache/phpstan.phar; fi
- if [[ $(phpenv version-name) =~ 7.2 ]] ; then test -f $HOME/.composer/cache/phpstan.phar || wget https://github.com/phpstan/phpstan/releases/download/0.9.2/phpstan.phar -O $HOME/.composer/cache/phpstan.phar; fi
- if [[ $(phpenv version-name) =~ 7.2 ]] ; then test -f $HOME/.composer/cache/ocular.phar || wget https://scrutinizer-ci.com/ocular.phar -O $HOME/.composer/cache/ocular.phar; fi
- if [[ $(phpenv version-name) =~ 7.2 ]] ; then test -f $HOME/.composer/cache/cctr || wget https://codeclimate.com/downloads/test-reporter/test-reporter-0.1.4-linux-amd64 -O $HOME/.composer/cache/cctr && chmod +x $HOME/.composer/cache/cctr; fi
- if [[ $(phpenv version-name) =~ 7.2 ]] ; then $HOME/.composer/cache/cctr before-build; fi
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ A PHP implementation for finding unordered diff between two `JSON` documents.
* To detect breaking changes by analyzing removals and changes from original `JSON`.
* To keep original order of object sets (for example `swagger.json` [parameters](https://swagger.io/docs/specification/describing-parameters/) list).
* To make and apply JSON Patches, specified in [RFC 6902](http://tools.ietf.org/html/rfc6902) from the IETF.
* To make and apply JSON Merge Patches, specified in [RFC 7386](https://tools.ietf.org/html/rfc7386) from the IETF.
* To retrieve and modify data by [JSON Pointer](http://tools.ietf.org/html/rfc6901).
* To recursively replace by JSON value.

Expand Down Expand Up @@ -55,11 +56,23 @@ $r = new JsonDiff(
);
```

Available options:
* `REARRANGE_ARRAYS` is an option to enable arrays rearrangement to minimize the difference.
* `STOP_ON_DIFF` is an option to improve performance by stopping comparison when a difference is found.
* `JSON_URI_FRAGMENT_ID` is an option to use URI Fragment Identifier Representation (example: "#/c%25d"). If not set default JSON String Representation (example: "/c%d").
* `SKIP_JSON_PATCH` is an option to improve performance by not building JsonPatch for this diff.
* `SKIP_JSON_MERGE_PATCH` is an option to improve performance by not building JSON Merge Patch value for this diff.

Options can be combined, e.g. `JsonDiff::REARRANGE_ARRAYS + JsonDiff::STOP_ON_DIFF`.

On created object you have several handy methods.

#### `getPatch`
Returns [`JsonPatch`](#jsonpatch) of difference

#### `getMergePatch`
Returns [JSON Merge Patch](https://tools.ietf.org/html/rfc7386) value of difference

#### `getRearranged`
Returns new value, rearranged with original order.

Expand Down Expand Up @@ -137,6 +150,11 @@ Gets value from data at path specified `JSON Pointer` string.
#### `remove`
Removes value from data at path specified by segments.

### `JsonMergePatch`

#### `apply`
Applies patch to `JSON`-decoded data.

### `JsonValueReplace`

#### `process`
Expand Down
61 changes: 32 additions & 29 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
{
"name": "swaggest/json-diff",
"description": "JSON diff/rearrange/patch/pointer library for PHP",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Viacheslav Poturaev",
"email": "[email protected]"
}
],
"require-dev": {
"phpunit/phpunit": "^4.8.23",
"phpunit/php-code-coverage": "2.2.4",
"codeclimate/php-test-reporter": "^0.4.0"
},
"autoload": {
"psr-4": {
"Swaggest\\JsonDiff\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Swaggest\\JsonDiff\\Tests\\": "tests/src"
}
},
"config": {
"platform": {
"php": "5.4.45"
}
"name": "swaggest/json-diff",
"description": "JSON diff/rearrange/patch/pointer library for PHP",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Viacheslav Poturaev",
"email": "[email protected]"
}
],
"require": {
"ext-json": "*"
},
"require-dev": {
"phpunit/phpunit": "^4.8.23",
"phpunit/php-code-coverage": "2.2.4",
"codeclimate/php-test-reporter": "^0.4.0"
},
"autoload": {
"psr-4": {
"Swaggest\\JsonDiff\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Swaggest\\JsonDiff\\Tests\\": "tests/src"
}
},
"config": {
"platform": {
"php": "5.4.45"
}
}
}
Loading