Skip to content

Commit 3825404

Browse files
authored
Merge pull request #15 from jsonCarmock/add-merge-patch
Add JSON Merge Patch support #13
2 parents 32f3f48 + a911cf2 commit 3825404

14 files changed

+914
-113
lines changed

Diff for: .gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@
1111
/phpunit.xml export-ignore
1212
/changelog.md export-ignore
1313
/Makefile export-ignore
14+
/.gitlab-ci.yml

Diff for: .gitlab-ci.yml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
before_script:
2+
- apt-get update -yqq
3+
- apt-get install git unzip -yqq
4+
- curl https://composer.github.io/installer.sig | tr -d '\n' > installer.sig
5+
- php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
6+
- 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;"
7+
- php composer-setup.php
8+
- php -r "unlink('composer-setup.php'); unlink('installer.sig');"
9+
- php composer.phar install --prefer-dist --no-ansi --no-interaction --no-progress
10+
11+
test:5.6:
12+
image: php:5.6
13+
script:
14+
- pecl install xdebug-2.5.5
15+
- docker-php-ext-enable xdebug
16+
- vendor/bin/phpunit --configuration phpunit.xml -v --coverage-text --colors=never --stderr
17+
18+
test:7.0:
19+
image: php:7.0
20+
script:
21+
- pecl install xdebug
22+
- docker-php-ext-enable xdebug
23+
- vendor/bin/phpunit --configuration phpunit.xml -v --coverage-text --colors=never --stderr
24+
25+
test:7.1:
26+
image: php:7.1
27+
script:
28+
- pecl install xdebug
29+
- docker-php-ext-enable xdebug
30+
- vendor/bin/phpunit --configuration phpunit.xml -v --coverage-text --colors=never --stderr
31+
32+
test:7.2:
33+
image: php:7.2
34+
script:
35+
- pecl install xdebug
36+
- docker-php-ext-enable xdebug
37+
- vendor/bin/phpunit --configuration phpunit.xml -v --coverage-text --colors=never --stderr
38+
- curl https://github.com/phpstan/phpstan/releases/download/0.9.2/phpstan.phar -sLo ./phpstan.phar
39+
- php phpstan.phar analyze -l 7 ./src

Diff for: .travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ cache:
2020
# execute any number of scripts before the test run, custom env's are available as variables
2121
before_script:
2222
- composer install --dev --no-interaction --prefer-dist
23-
- 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
23+
- 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
2424
- 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
2525
- 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
2626
- if [[ $(phpenv version-name) =~ 7.2 ]] ; then $HOME/.composer/cache/cctr before-build; fi

Diff for: README.md

+18
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ A PHP implementation for finding unordered diff between two `JSON` documents.
1313
* To detect breaking changes by analyzing removals and changes from original `JSON`.
1414
* To keep original order of object sets (for example `swagger.json` [parameters](https://swagger.io/docs/specification/describing-parameters/) list).
1515
* To make and apply JSON Patches, specified in [RFC 6902](http://tools.ietf.org/html/rfc6902) from the IETF.
16+
* To make and apply JSON Merge Patches, specified in [RFC 7386](https://tools.ietf.org/html/rfc7386) from the IETF.
1617
* To retrieve and modify data by [JSON Pointer](http://tools.ietf.org/html/rfc6901).
1718
* To recursively replace by JSON value.
1819

@@ -55,11 +56,23 @@ $r = new JsonDiff(
5556
);
5657
```
5758

59+
Available options:
60+
* `REARRANGE_ARRAYS` is an option to enable arrays rearrangement to minimize the difference.
61+
* `STOP_ON_DIFF` is an option to improve performance by stopping comparison when a difference is found.
62+
* `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").
63+
* `SKIP_JSON_PATCH` is an option to improve performance by not building JsonPatch for this diff.
64+
* `SKIP_JSON_MERGE_PATCH` is an option to improve performance by not building JSON Merge Patch value for this diff.
65+
66+
Options can be combined, e.g. `JsonDiff::REARRANGE_ARRAYS + JsonDiff::STOP_ON_DIFF`.
67+
5868
On created object you have several handy methods.
5969

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

73+
#### `getMergePatch`
74+
Returns [JSON Merge Patch](https://tools.ietf.org/html/rfc7386) value of difference
75+
6376
#### `getRearranged`
6477
Returns new value, rearranged with original order.
6578

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

153+
### `JsonMergePatch`
154+
155+
#### `apply`
156+
Applies patch to `JSON`-decoded data.
157+
140158
### `JsonValueReplace`
141159

142160
#### `process`

Diff for: composer.json

+32-29
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,35 @@
11
{
2-
"name": "swaggest/json-diff",
3-
"description": "JSON diff/rearrange/patch/pointer library for PHP",
4-
"type": "library",
5-
"license": "MIT",
6-
"authors": [
7-
{
8-
"name": "Viacheslav Poturaev",
9-
"email": "[email protected]"
10-
}
11-
],
12-
"require-dev": {
13-
"phpunit/phpunit": "^4.8.23",
14-
"phpunit/php-code-coverage": "2.2.4",
15-
"codeclimate/php-test-reporter": "^0.4.0"
16-
},
17-
"autoload": {
18-
"psr-4": {
19-
"Swaggest\\JsonDiff\\": "src/"
20-
}
21-
},
22-
"autoload-dev": {
23-
"psr-4": {
24-
"Swaggest\\JsonDiff\\Tests\\": "tests/src"
25-
}
26-
},
27-
"config": {
28-
"platform": {
29-
"php": "5.4.45"
30-
}
2+
"name": "swaggest/json-diff",
3+
"description": "JSON diff/rearrange/patch/pointer library for PHP",
4+
"type": "library",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "Viacheslav Poturaev",
9+
"email": "[email protected]"
3110
}
11+
],
12+
"require": {
13+
"ext-json": "*"
14+
},
15+
"require-dev": {
16+
"phpunit/phpunit": "^4.8.23",
17+
"phpunit/php-code-coverage": "2.2.4",
18+
"codeclimate/php-test-reporter": "^0.4.0"
19+
},
20+
"autoload": {
21+
"psr-4": {
22+
"Swaggest\\JsonDiff\\": "src/"
23+
}
24+
},
25+
"autoload-dev": {
26+
"psr-4": {
27+
"Swaggest\\JsonDiff\\Tests\\": "tests/src"
28+
}
29+
},
30+
"config": {
31+
"platform": {
32+
"php": "5.4.45"
33+
}
34+
}
3235
}

0 commit comments

Comments
 (0)