| @@ 56-77 (lines=22) @@ | ||
| 53 | return $changes; |
|
| 54 | } |
|
| 55 | ||
| 56 | protected function handleObject(\stdClass $srcStruct, \stdClass $desStruct, string $path): array |
|
| 57 | { |
|
| 58 | $changes = []; |
|
| 59 | ||
| 60 | if ($this->shouldPartiallyReplace($srcStruct, $desStruct)) { |
|
| 61 | foreach ($desStruct as $key => $val) { |
|
| 62 | if (!property_exists($srcStruct, $key)) { |
|
| 63 | $changes[] = $this->makePatch(self::OP_ADD, $this->path($path, $key), $val); |
|
| 64 | } elseif ($srcStruct->$key != $val) { |
|
| 65 | $changes = array_merge($changes, $this->makeDiff($srcStruct->$key, $val, $this->path($path, $key))); |
|
| 66 | } |
|
| 67 | } |
|
| 68 | } elseif ($this->shouldPartiallyReplace($desStruct, $srcStruct)) { |
|
| 69 | foreach ($srcStruct as $key => $val) { |
|
| 70 | if (!property_exists($desStruct, $key)) { |
|
| 71 | $changes[] = $this->makePatch(self::OP_REMOVE, $this->path($path, $key)); |
|
| 72 | } |
|
| 73 | } |
|
| 74 | } |
|
| 75 | ||
| 76 | return $changes; |
|
| 77 | } |
|
| 78 | ||
| 79 | protected function shouldPartiallyReplace(\stdClass $o1, \stdClass $o2): bool |
|
| 80 | { |
|
| @@ 24-45 (lines=22) @@ | ||
| 21 | * We need to override the proper way to handle objects because Glance v2 does not |
|
| 22 | * support whole document replacement with empty JSON pointers. |
|
| 23 | */ |
|
| 24 | protected function handleObject(\stdClass $srcStruct, \stdClass $desStruct, string $path): array |
|
| 25 | { |
|
| 26 | $changes = []; |
|
| 27 | ||
| 28 | foreach ($desStruct as $key => $val) { |
|
| 29 | if (!property_exists($srcStruct, $key)) { |
|
| 30 | $changes[] = $this->makePatch(self::OP_ADD, $this->path($path, $key), $val); |
|
| 31 | } elseif ($srcStruct->$key != $val) { |
|
| 32 | $changes = array_merge($changes, $this->makeDiff($srcStruct->$key, $val, $this->path($path, $key))); |
|
| 33 | } |
|
| 34 | } |
|
| 35 | ||
| 36 | if ($this->shouldPartiallyReplace($desStruct, $srcStruct)) { |
|
| 37 | foreach ($srcStruct as $key => $val) { |
|
| 38 | if (!property_exists($desStruct, $key)) { |
|
| 39 | $changes[] = $this->makePatch(self::OP_REMOVE, $this->path($path, $key)); |
|
| 40 | } |
|
| 41 | } |
|
| 42 | } |
|
| 43 | ||
| 44 | return $changes; |
|
| 45 | } |
|
| 46 | ||
| 47 | protected function handleArray(array $srcStruct, array $desStruct, string $path): array |
|
| 48 | { |
|