Skip to content

Commit 85895f8

Browse files
author
nejc
committed
feat: add composite types (Json, Struct, Union, Dictionary, ListData)
1 parent 56fbe10 commit 85895f8

File tree

1 file changed

+3
-18
lines changed

1 file changed

+3
-18
lines changed

src/Composite/Json.php

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
use JsonException;
99
use Nejcc\PhpDatatypes\Interfaces\DecoderInterface;
1010
use Nejcc\PhpDatatypes\Interfaces\EncoderInterface;
11-
11+
use Nejcc\PhpDatatypes\Abstract\ArrayAbstraction;
1212

1313
/**
1414
* Class Json
1515
* A strict and immutable type for handling JSON data with advanced features.
1616
*/
17-
final class Json
17+
final class Json extends ArrayAbstraction
1818
{
1919
/**
2020
* @var string The JSON string.
@@ -43,24 +43,9 @@ public function __construct(string $json, ?string $schema = null)
4343
$this->validateJson($json);
4444
$this->schema = $schema;
4545
$this->json = $json;
46+
parent::__construct([]); // Not used, but required by ArrayAbstraction
4647
}
4748

48-
/**
49-
* Validates if a string is valid JSON.
50-
*
51-
* @param string $json
52-
* @throws InvalidArgumentException
53-
*/
54-
private function validateJson(string $json): void
55-
{
56-
try {
57-
json_decode($json, true, 512, JSON_THROW_ON_ERROR);
58-
} catch (JsonException $e) {
59-
throw new InvalidArgumentException('Invalid JSON provided: ' . $e->getMessage());
60-
}
61-
}
62-
63-
6449
/**
6550
* Serializes the JSON data to an array.
6651
*

0 commit comments

Comments
 (0)