diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 03d977c..90c2512 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 ./ diff --git a/composer.json b/composer.json index e984106..ab2a9e7 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": " Structured, type-safe, immutable JSON objects.", "require": { - "php": ">=8.0", + "php": ">=8.1", "ext-json": "*", "phpgt/dataobject": "^1.0" diff --git a/composer.lock b/composer.lock index 096317e..90059db 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "8f48b785533048a61d02f7e70c650982", + "content-hash": "7f8afeff72fc2fd8f7dd8e7558b14302", "packages": [ { "name": "phpgt/dataobject", @@ -1902,7 +1902,7 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=8.0", + "php": ">=8.1", "ext-json": "*" }, "platform-dev": [], diff --git a/src/JsonObjectBuilder.php b/src/JsonObjectBuilder.php index 6304e9b..f845b4d 100644 --- a/src/JsonObjectBuilder.php +++ b/src/JsonObjectBuilder.php @@ -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 { @@ -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);