diff --git a/docs/README.md b/docs/README.md index 607aaf6..017e94f 100644 --- a/docs/README.md +++ b/docs/README.md @@ -7,7 +7,7 @@ Take a look at the [Parser](helper-parser.md) to quickstart with JsonApiClient. ### Helper Tools: * [Parser](helper-parser.md) * [Manager](manager.md) -* [Factory](utils-factory.md) +* [Factory](factory.md) * [Exceptions](exception-introduction.md) ### Objects: @@ -30,7 +30,3 @@ Take a look at the [Parser](helper-parser.md) to quickstart with JsonApiClient. * [Error Link object](objects-error-link.md) * [Jsonapi object](objects-jsonapi.md) * [Meta object](objects-meta.md) - -### Deprecated Utils: -* [Manager](utils-manager.md) -* [Helper](utils-helper.md) diff --git a/docs/utils-factory.md b/docs/factory.md similarity index 99% rename from docs/utils-factory.md rename to docs/factory.md index 26718a7..230ca27 100644 --- a/docs/utils-factory.md +++ b/docs/factory.md @@ -1,4 +1,4 @@ -# Utils\Factory +# Factory [Back to Navigation](README.md) The `Art4\JsonApiClient\V1\Factory` provides a simple way to override [all objects](objects-introduction.md#all-objects) by injecting your own classes. diff --git a/docs/manager.md b/docs/manager.md index b42ec29..4ce18c0 100644 --- a/docs/manager.md +++ b/docs/manager.md @@ -1,7 +1,7 @@ # Manager [Back to Navigation](README.md) -The `Art4\JsonApiClient\Manager` can be used to parse a JSON API input and to inject a [Factory](utils-factory.md) for overriding classes. +The `Art4\JsonApiClient\Manager` can be used to parse a JSON API input and to inject a [Factory](factory.md) for overriding classes. The `Art4\JsonApiClient\Manager` needs a `Art4\JsonApiClient\Input\Input` instance for parsing. The Input instance is a normalizer that provides the JSON API as a simple object with public attributes like `\stdClass`. @@ -67,7 +67,7 @@ This returns a [Document](objects-document.md) object which provided all content ### Working with a factory -You can set a custom [Factory](utils-factory.md) to the manager through the constructor. +You can set a custom [Factory](factory.md) to the manager through the constructor. ```php use Art4\JsonApiClient\Manager\ErrorAbortManager; @@ -83,4 +83,4 @@ You can call `getFactory()` to get the setted factory. $factory = $manager->getFactory(); ``` -Learn more about the [Factory](utils-factory.md). +Learn more about the [Factory](factory.md). diff --git a/docs/objects-introduction.md b/docs/objects-introduction.md index 5bd5548..e12d9a9 100644 --- a/docs/objects-introduction.md +++ b/docs/objects-introduction.md @@ -135,4 +135,4 @@ You can get all data as an array using the [ArraySerializer](serializer.md#array ### Need more? -If you need more opportunities to get the values take a look at the [Factory](utils-factory.md) to inject more functionality. +If you need more opportunities to get the values take a look at the [Factory](factory.md) to inject more functionality. diff --git a/docs/utils-helper.md b/docs/utils-helper.md deleted file mode 100644 index 0e4d562..0000000 --- a/docs/utils-helper.md +++ /dev/null @@ -1,80 +0,0 @@ -# Utils\Helper -[Back to Navigation](README.md) - -**Attention:** `Utils\Helper` is deprecated and will be removed in JsonApiClient 1.0, use [Helper\Parser](helper-parser.md) instead. - -The `Utils\Helper` provides some useful methods to deal with JSON. - -### Parse a JSON API response body - -Assuming you have get a response from a JSON API server. Use `parseResponseBody()` to work with the data. - -```php - -// The Response body from a JSON API server -$jsonapiString = '{"meta":{"info":"Testing the JsonApiClient library."}}'; - -$document = \Art4\JsonApiClient\Utils\Helper::parseResponseBody($jsonapiString); -``` - -This returns a [Document](objects-document.md) object which provided all contents. - -> **Note:** If `$jsonapiString` contains not valid JSON or JSON API a [ValidationException](exception-introduction.md#validationexception) will be thrown. -> -> See more about Exceptions in the [Exception section](exception-introduction.md). - -### Parse a JSON API request body - -Assuming you have get a request for creating a new resource. In this case the `id` in the resource item can be missed and you have to tell the Manager about this case. Use `parseRequestBody()` to work with the data. - -```php - -// The requst body from a client -$jsonapiString = '{"data":{"type":"posts","attributes":{"title":"Post Title"}}}'; - -$document = \Art4\JsonApiClient\Utils\Helper::parseRequestBody($jsonapiString); -``` - -This returns a [Document](objects-document.md) object which provided all contents. - -> **Note:** If `$jsonapiString` contains not valid JSON or JSON API a [ValidationException](exception-introduction.md#validationexception) will be thrown. -> -> See more about Exceptions in the [Exception section](exception-introduction.md). - -### Validate a JSON API response body - -JsonApiClient can be used as a validator for a response body: - -```php -$wrong_jsonapi = '{"data":{},"meta":{"info":"This is wrong JSON API. `data` has to be `null` or containing at least `type` and `id`."}}'; - -if ( \Art4\JsonApiClient\Utils\Helper::isValidResponseBody($wrong_jsonapi) ) -{ - echo 'string is valid.'; -} -else -{ - echo 'string is invalid json api!'; -} - -// echos 'string is invalid json api!' -``` - -### Validate a JSON API request body - -JsonApiClient can also be used as a validator for a request body: - -```php -$wrong_jsonapi = '{"data":{"type":"post","attributes":{"body":"The post body"}}}'; - -if ( \Art4\JsonApiClient\Utils\Helper::isValidRequestBody($wrong_jsonapi) ) -{ - echo 'string is valid.'; -} -else -{ - echo 'string is invalid json api!'; -} - -// echos 'string is valid.' -``` diff --git a/docs/utils-manager.md b/docs/utils-manager.md deleted file mode 100644 index 7599878..0000000 --- a/docs/utils-manager.md +++ /dev/null @@ -1,63 +0,0 @@ -# Utils\Manager -[Back to Navigation](README.md) - -**Attention:** `Utils\Manager` is deprecated and will be removed in JsonApiClient 1.0, use [Manager\ErrorAbortManager](manager.md) instead. - -The `Utils\Manager` can be used to parse JSON API string and to inject a [Factory](utils-factory.md) for overriding classes. - -### Parse a JSON API string - -Assuming you have get a response from a JSON API server. Use `parse()` to work with the data. - -```php - -// The Response body from a JSON API server -$jsonapiString = '{"meta":{"info":"Testing the JsonApiClient library."}}'; - -$manager = new \Art4\JsonApiClient\Utils\Manager(); - -$document = $manager->parse($jsonapiString); -``` - -This returns a [Document](objects-document.md) object which provided all contents. - -> **Note:** If `$jsonapiString` contains not valid JSON or JSON API a [ValidationException](exception-introduction.md#validationexception) will be thrown. - -### Parse a JSON API string for creating a new resource - -Assuming you have get a request for creating a new resource. In this case the `id` in the resource item can be missed and you have to tell the Manager about this case. - -```php - -// The request body from a client -$jsonapiString = '{"data":{"type":"posts","attributes":{"title":"Post Title"}}}'; - -$manager = new \Art4\JsonApiClient\Utils\Manager(); - -// Set this to `true` -$manager->setConfig('optional_item_id', true); - -$document = $manager->parse($jsonapiString); -``` - -This returns a [Document](objects-document.md) object which provided all contents. - -> **Note:** If `$jsonapiString` contains not valid JSON or JSON API a [ValidationException](exception-introduction.md#validationexception) will be thrown. - -### Working with a factory - -You can set a custom [Factory](utils-factory.md) to the manager through `setFactory()` or the constructor. - -```php -$manager = new \Art4\JsonApiClient\Utils\Manager($factory); -// or -$manager->setFactory($factory); -``` - -With `getFactory()` you can get the setted factory. If you havn't set your own factory you will get the default created factory. - -```php -$factory = $manager->getFactory(); -``` - -Learn more about the [Factory](utils-factory.md).