Skip to content
Merged
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
12 changes: 10 additions & 2 deletions src/JsonDiff.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ class JsonDiff

private $options = 0;

/**
* @var array Skip included paths
*/
private $skipPaths = [];

/**
* @var mixed Merge patch container
*/
Expand Down Expand Up @@ -88,16 +93,19 @@ 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();
}

$this->options = $options;

$this->skipPaths = $skipPaths;

if ($options & self::JSON_URI_FRAGMENT_ID) {
$this->path = '#';
}
Expand Down Expand Up @@ -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;
Expand Down