diff --git a/src/JsonDiff.php b/src/JsonDiff.php index dfd3c90..7f2b3f3 100644 --- a/src/JsonDiff.php +++ b/src/JsonDiff.php @@ -48,6 +48,11 @@ class JsonDiff private $options = 0; + /** + * @var array Skip included paths + */ + private $skipPaths = []; + /** * @var mixed Merge patch container */ @@ -88,9 +93,10 @@ class JsonDiff * @param mixed $original * @param mixed $new * @param int $options + * @param array $skipPaths * @throws Exception */ - public function __construct($original, $new, $options = 0) + public function __construct($original, $new, $options = 0, $skipPaths = []) { if (!($options & self::SKIP_JSON_PATCH)) { $this->jsonPatch = new JsonPatch(); @@ -98,6 +104,8 @@ public function __construct($original, $new, $options = 0) $this->options = $options; + $this->skipPaths = $skipPaths; + if ($options & self::JSON_URI_FRAGMENT_ID) { $this->path = '#'; } @@ -268,7 +276,7 @@ private function process($original, $new) (!$original instanceof \stdClass && !is_array($original)) || (!$new instanceof \stdClass && !is_array($new)) ) { - if ($original !== $new) { + if ($original !== $new && !in_array($this->path, $this->skipPaths)) { $this->modifiedCnt++; if ($this->options & self::STOP_ON_DIFF) { return null;