Skip to content

Commit 9e96a96

Browse files
authored
Union types support (#25)
* Remove unused import * Support union types for relationships dto * Split testsuites by php versions * Add test case without union types * Use php version var for docker * Check union types case first * Fix typo in const name * Extract common resource examples * Update docs * Suggest nyholm/psr7 package
1 parent ecc4d0f commit 9e96a96

25 files changed

+244
-16
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/.env
2+
13
/.idea/
24

35
/.phpunit.result.cache

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
- Data Transfer Object classes generation from swagger spec
1111
- JsonApiResponseFactory::createResponse() `meta` and `links` arguments
1212
- CacheableDispatcherFactoryProxy
13+
- Union types support for `data.relationships` DTO: use suitable type for input data structure
1314

1415
### Changed
1516
- Best composer dependencies compatibility: allow more versions

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
FROM php:8-cli
1+
ARG PHP_VERSION
2+
3+
FROM php:${PHP_VERSION}-cli
24

35
RUN apt-get update \
46
&& apt-get install -y \

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
PATH := $(shell pwd)/bin:$(PATH)
2+
$(shell cp -n dev.env .env)
3+
include .env
24

35
build:
4-
docker build -t free-elephants/json-api-php-toolkit .
6+
docker build --build-arg PHP_VERSION=${PHP_VERSION} -t free-elephants/json-api-php-toolkit .
57

68
install: build
79
composer install

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,9 @@ Available in [/docs](/docs).
2828
1. [Serialize doctrine entities](/docs/doctrine.md)
2929
1. [DTO from psr server request](/docs/dto-psr7.md)
3030
1. [Validation](/docs/validation.md)
31+
32+
## Development
33+
34+
All dev env is dockerized. Your can use make receipts and `bin/` scripts without locally installed php, composer.
35+
36+
For run tests with different php version change `PHP_VERSION` value in .env and rebuild image with `make build`.

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
"suggest": {
4141
"doctrine/orm": "^2.7",
4242
"free-elephants/di": "*",
43-
"laminas/laminas-httphandlerrunner": "*"
43+
"laminas/laminas-httphandlerrunner": "*",
44+
"nyholm/psr7": "^1.2"
4445
},
4546
"autoload": {
4647
"psr-4": {

dev.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PHP_VERSION=8.0

docs/dto-psr7.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
Full typed objects from request or response body.
44

55
See example in [test](/tests/FreeElephants/JsonApiToolkit/DTO/DocumentTest.php).
6+
7+
Union types support for relationships in PHP 8.

docs/routing.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,8 @@ JSON
6060

6161
(new DispatcherFactory(null, new Parsers\JsonFileParser()))->buildDispatcher('swagger.json');
6262
```
63+
64+
## About performance
65+
66+
Parse large swagger files have performance issues. Use `FreeElephants\JsonApiToolkit\Routing\FastRoute\CacheableDispatcherFactoryProxy` for production usage: it based on psr/cache component compare swagger file hash.
67+

phpunit.xml.dist

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@
1313
<ini name="error_reporting" value="E_ALL"/>
1414
</php>
1515
<testsuites>
16-
<testsuite name="JsonApi Toolkit Tests">
17-
<directory>./tests</directory>
16+
<testsuite name="8.0">
17+
<directory suffix="TestPHP8.php" phpVersion="8.0">./tests</directory>
18+
</testsuite>
19+
<testsuite name="7.4">
20+
<directory suffix="Test.php" phpVersion="7.4">./tests</directory>
1821
</testsuite>
1922
</testsuites>
2023
<logging/>

0 commit comments

Comments
 (0)