free-elephants/json-api-dto

JsonApi Document Structure Types

0.1.0-rc 2025-03-20 12:08 UTC

This package is auto-updated.

Last update: 2025-03-24 10:31:02 UTC


README

Build Status codecov Installs Releases

Features:

Build Data Transfer Objects from PSR7 Messages.

Full typed objects from request or response body.

See example in test.

Union types support for relationships in PHP 8.

Usage

Extend super types in your own json api documents and it's parts:

  • \FreeElephants\JsonApi\DTO\AbstractAttributes
  • \FreeElephants\JsonApi\DTO\AbstractDocument
  • \FreeElephants\JsonApi\DTO\AbstractRelationships
  • \FreeElephants\JsonApi\DTO\AbstractResourceObject

And use as properties types:

  • \FreeElephants\JsonApi\DTO\RelationshipToOne
  • \FreeElephants\JsonApi\DTO\ResourceIdentifierObject

See tests/ for more examples.

Install

composer require free-elephants/json-api-dto

Development

All dev env is dockerized. Your can use make receipts and bin/ scripts without locally installed php, composer.

For run tests with different php version change PHP_VERSION value in .env and rebuild image with make build.