Skip to content

Commit cf4661f

Browse files
author
Michael Sobande
committed
skip paths
1 parent f373420 commit cf4661f

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/JsonDiff.php

+10-2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ class JsonDiff
4848

4949
private $options = 0;
5050

51+
/**
52+
* @var array Skip included paths
53+
*/
54+
private $skipPaths = [];
55+
5156
/**
5257
* @var mixed Merge patch container
5358
*/
@@ -88,16 +93,19 @@ class JsonDiff
8893
* @param mixed $original
8994
* @param mixed $new
9095
* @param int $options
96+
* @param array $skipPaths
9197
* @throws Exception
9298
*/
93-
public function __construct($original, $new, $options = 0)
99+
public function __construct($original, $new, $options = 0, $skipPaths = [])
94100
{
95101
if (!($options & self::SKIP_JSON_PATCH)) {
96102
$this->jsonPatch = new JsonPatch();
97103
}
98104

99105
$this->options = $options;
100106

107+
$this->skipPaths = $skipPaths;
108+
101109
if ($options & self::JSON_URI_FRAGMENT_ID) {
102110
$this->path = '#';
103111
}
@@ -268,7 +276,7 @@ private function process($original, $new)
268276
(!$original instanceof \stdClass && !is_array($original))
269277
|| (!$new instanceof \stdClass && !is_array($new))
270278
) {
271-
if ($original !== $new) {
279+
if ($original !== $new && !in_array($this->path, $this->skipPaths)) {
272280
$this->modifiedCnt++;
273281
if ($this->options & self::STOP_ON_DIFF) {
274282
return null;

0 commit comments

Comments
 (0)