Skip to content

Commit 9be311f

Browse files
author
Wazabii
committed
Minor structure changes
1 parent 6f12260 commit 9be311f

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

Json.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,22 @@ public function __toString(): string
3535
return (string)$this->encode();
3636
}
3737

38+
/**
39+
* New json instance
40+
* @param array|string $data
41+
* @return self
42+
*/
43+
public function withData(array|string $data): self
44+
{
45+
$inst = new self();
46+
if(is_array($data)) {
47+
$inst->data = array_merge($this->data, $data);
48+
} else {
49+
$inst->data = $this->decode($data);
50+
}
51+
return $inst;
52+
}
53+
3854
/**
3955
* Merge array to json array
4056
* @param array $array
@@ -222,7 +238,7 @@ public function validate(): void
222238
if (!is_null($error)) {
223239
throw new \Exception($error, self::error());
224240
}
225-
throw new \Exception('An unexpected Json error has occurred', self::error());
241+
//throw new \Exception('An unexpected Json error has occurred', self::error());
226242
}
227243

228244
/**

0 commit comments

Comments
 (0)