free-elephants / json-api-dto
JsonApi Document Structure Types
0.1.0-rc
2025-03-20 12:08 UTC
Requires
- ext-json: *
- psr/http-message: *
Requires (Dev)
- nyholm/psr7: ^1.2
- phpunit/phpunit: >=9.3
Suggests
- free-elephants/di: *
- nyholm/psr7: ^1.2
README
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
.