Skip to content

Commit dffa675

Browse files
authored
Merge pull request swaggest#39 from dabslants/skip-paths
skip paths
2 parents bc55b27 + cf4661f commit dffa675

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Diff for: 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
*/
@@ -85,16 +90,19 @@ class JsonDiff
8590
* @param mixed $original
8691
* @param mixed $new
8792
* @param int $options
93+
* @param array $skipPaths
8894
* @throws Exception
8995
*/
90-
public function __construct($original, $new, $options = 0)
96+
public function __construct($original, $new, $options = 0, $skipPaths = [])
9197
{
9298
if (!($options & self::SKIP_JSON_PATCH)) {
9399
$this->jsonPatch = new JsonPatch();
94100
}
95101

96102
$this->options = $options;
97103

104+
$this->skipPaths = $skipPaths;
105+
98106
if ($options & self::JSON_URI_FRAGMENT_ID) {
99107
$this->path = '#';
100108
}
@@ -265,7 +273,7 @@ private function process($original, $new)
265273
(!$original instanceof \stdClass && !is_array($original))
266274
|| (!$new instanceof \stdClass && !is_array($new))
267275
) {
268-
if ($original !== $new) {
276+
if ($original !== $new && !in_array($this->path, $this->skipPaths)) {
269277
$this->modifiedCnt++;
270278
if ($this->options & self::STOP_ON_DIFF) {
271279
return null;

0 commit comments

Comments
 (0)