Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ jobs:
path: /tmp/composer-cache
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}

- uses: php-actions/composer@v6
- name: Composer
uses: php-actions/composer@v6
with:
php_version: 8.1

- name: Archive build
run: mkdir /tmp/github-actions/ && tar -cvf /tmp/github-actions/build.tar ./
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": " Structured, type-safe, immutable JSON objects.",

"require": {
"php": ">=8.0",
"php": ">=8.1",
"ext-json": "*",

"phpgt/dataobject": "^1.0"
Expand Down
4 changes: 2 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 10 additions & 7 deletions src/JsonObjectBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Gt\Json\JsonPrimitive\JsonNullPrimitive;
use Gt\Json\JsonPrimitive\JsonPrimitive;
use Gt\Json\JsonPrimitive\JsonStringPrimitive;
use JsonException as NativeJsonException;
use stdClass;

class JsonObjectBuilder extends DataObjectBuilder {
Expand All @@ -18,13 +19,15 @@ public function __construct(
}

public function fromJsonString(string $jsonString):JsonObject {
$json = json_decode($jsonString, depth: $this->depth);
if(is_null($json)) {
// It's completely reasonable to have a null value here, so we need to check the
// error code before throwing an exception.
if(json_last_error() !== JSON_ERROR_NONE) {
throw new JsonDecodeException(json_last_error_msg());
}
try {
$json = json_decode(
$jsonString,
depth: $this->depth,
flags: JSON_THROW_ON_ERROR
);
}
catch(NativeJsonException $exception) {
throw new JsonDecodeException($exception->getMessage());
}

return $this->fromJsonDecoded($json);
Expand Down