1. Go to this page and download the library: Download freddiegar/json-api-mapper library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
freddiegar / json-api-mapper example snippets
use FreddieGar\JsonApiMapper\JsonApiMapper;
$jsonApi = new JsonApiMapper($jsonApiResponse);
$data = $jsonApi->getData(0);
$
echo get_class($>getIncluded(0)->getType(); // people
echo $cluded->getIncluded(1); // null, it is not defined in response
$jsonApi = new JsonApiMapper($jsonApiResponse);
echo get_class($jsonApi->getErrors()); // Return ErrorsMapperInterface
$firstError = $jsonApi->getErrors(0); // Get first error
echo $firstError->getStatus(); // 422
echo print_r($firstError->getSource(), true); // ['pointer' => '/data/attributes/first-name']
echo $firstError->getTitle(); // Invalid Attribute
echo $firstError->getDetail(); // First name must contain at least three characters.
$secondError = $jsonApi->getErrors(1); // null, it is not defined in response
$dataWithIdTwo = $data->find(2); // Return DataMapperInterface if exist else null