Skip to content

Commit e1abb62

Browse files
committed
Update docs, README.md and CHANGELOG.md
1 parent cfa7f1d commit e1abb62

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).
55

66
## [Unreleased]
77

8+
### Added
9+
10+
- `Helper::isValid()` checks if a string is valid JSON API
11+
812
### Fixed
913

1014
- **BREAKING**: pagination links moved from `Pagination` to `DocumentLink` and `RelationshipLink`

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,16 @@ JSON API Client can be used as a validator for JSON API contents:
6161
```php
6262
$wrong_jsonapi = '{"data":{},"meta":{"info":"This is wrong JSON API. `data` has to be `null` or containing at least `type` and `id`."}}';
6363

64-
$manager = new \Art4\JsonApiClient\Utils\Manager();
65-
66-
try
64+
if ( \Art4\JsonApiClient\Utils\Helper::isValid($wrong_jsonapi) )
6765
{
68-
$document = $manager->parse($wrong_jsonapi);
66+
echo 'string is valid.';
6967
}
70-
catch (\Art4\JsonApiClient\Exception\ValidationException $e)
68+
else
7169
{
72-
echo $e->getMessage(); // "A resource object MUST contain a type"
70+
echo 'string is invalid json api!';
7371
}
72+
73+
// echos 'string is invalid json api!'
7474
```
7575

7676
### Extend the client

docs/utils-helper.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,24 @@ $document = \Art4\JsonApiClient\Utils\Helper::parse($jsonapi_string);
1818
This returns a [Document](objects-document.md) object which provided all contents.
1919

2020
> **Note:** If `$jsonapi_string` contains not valid JSON or JSON API a [Exception\ValidationException](exception-introduction.md#exceptionvalidationexception) will be thrown.
21+
>
22+
> See more about Exceptions in the [Exception section](exception-introduction.md).
2123
2224
### Validate a JSON API response body
2325

24-
JSON API Client can be used as a validator. It will throw an [Exception\ValidationException](exception-introduction.md#exceptionvalidationexception) if the body contains not valid JSON or JSON API.
26+
JSON API Client can be used as a validator:
2527

2628
```php
2729
$wrong_jsonapi = '{"data":{},"meta":{"info":"This is wrong JSON API. `data` has to be `null` or containing at least `type` and `id`."}}';
2830

29-
try
31+
if ( \Art4\JsonApiClient\Utils\Helper::isValid($wrong_jsonapi) )
3032
{
31-
$document = \Art4\JsonApiClient\Utils\Helper::parse($wrong_jsonapi);
33+
echo 'string is valid.';
3234
}
33-
catch (\Art4\JsonApiClient\Exception\ValidationException $e)
35+
else
3436
{
35-
echo $e->getMessage(); // "A resource object MUST contain a type"
37+
echo 'string is invalid json api!';
3638
}
37-
```
3839

39-
See more about Exceptions in the [Exception section](exception-introduction.md).
40+
// echos 'string is invalid json api!'
41+
```

0 commit comments

Comments
 (0)