Skip to content

Commit a22cc86

Browse files
author
n.gnato
committed
Copy and adopt files from parent project
1 parent 8ca8bb9 commit a22cc86

26 files changed

+678
-0
lines changed

.github/workflows/ci.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: CI
2+
3+
on: push
4+
5+
jobs:
6+
php-tests:
7+
strategy:
8+
matrix:
9+
php:
10+
- 7.4
11+
- 8.0
12+
- 8.1
13+
- 8.2
14+
- 8.3
15+
- 8.4
16+
prefer:
17+
- lowest
18+
- stable
19+
fail-fast: false
20+
21+
name: Test on PHP ${{ matrix.php }} with ${{ matrix.prefer }} composer prefer option
22+
runs-on: ubuntu-latest
23+
24+
steps:
25+
- name: Checkout Code
26+
uses: actions/checkout@v2
27+
28+
- name: Install PHP
29+
uses: shivammathur/setup-php@v2
30+
with:
31+
php-version: ${{ matrix.php }}
32+
33+
- name: Check PHP Version
34+
run: php -v
35+
36+
- name: Xdebug Action
37+
uses: MilesChou/docker-xdebug@master
38+
39+
- name: Cache Composer packages
40+
id: composer-cache
41+
uses: actions/cache@v2
42+
with:
43+
path: vendor
44+
key: ${{ runner.os }}-php-${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}-${{ matrix.prefer }}-
45+
restore-keys: |
46+
${{ runner.os }}-php-${{ matrix.php }}-composer-${{ matrix.prefer }}-
47+
- name: Install dependencies
48+
if: steps.composer-cache.outputs.cache-hit != 'true'
49+
run: composer update --prefer-${{ matrix.prefer }} --prefer-dist --no-progress
50+
51+
- name: Run tests
52+
env:
53+
XDEBUG_MODE: coverage
54+
run: vendor/bin/phpunit

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/.env
2+
3+
/.idea/
4+
5+
/.phpunit.cache/
6+
7+
/composer.lock
8+
9+
/phpunit.xml
10+
/_coverage/
11+
12+
/vendor/

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Changelog
2+
All notable changes to this project will be documented in this file.
3+
4+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6+
7+
## [Unreleased]
8+
9+
### Added
10+
- Extract all DTO types from FreeElephants/json-api-php-toolkit to this project
11+
12+
[Unreleased]: https://github.com/FreeElephants/json-api-dto/compare/0.0.1...HEAD
13+
[0.0.1]: https://github.com/FreeElephants/json-api-dto/releases/tag/0.0.1

Dockerfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
ARG PHP_VERSION=8.3
2+
3+
FROM php:${PHP_VERSION}-cli
4+
5+
RUN apt-get update \
6+
&& apt-get install -y \
7+
git \
8+
libzip-dev \
9+
unzip \
10+
libicu-dev
11+
12+
RUN docker-php-ext-install \
13+
zip \
14+
intl
15+
16+
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
17+
18+
19+
RUN pecl install xdebug \
20+
&& docker-php-ext-enable xdebug
21+
22+
23+
RUN echo "xdebug.mode=coverage" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
24+
25+
WORKDIR /app

Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
PATH := $(shell pwd)/bin:$(PATH)
2+
$(shell cp -n dev.env .env)
3+
include .env
4+
5+
build:
6+
docker build --build-arg PHP_VERSION=$(PHP_VERSION) -t $(PHP_DEV_IMAGE) .
7+
8+
install: build
9+
composer install
10+
11+
test:
12+
vendor/bin/phpunit
13+

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Json Api Toolkit
2+
3+
[![Build Status](https://github.com/FreeElephants/json-api-dto/workflows/CI/badge.svg)](https://github.com/FreeElephants/json-api-dto/actions)
4+
[![codecov](https://codecov.io/gh/FreeElephants/json-api-dto/branch/master/graph/badge.svg)](https://codecov.io/gh/FreeElephants/json-api-dto)
5+
[![Installs](https://img.shields.io/packagist/dt/free-elephants/json-api-dto.svg)](https://packagist.org/packages/free-elephants/json-api-dto)
6+
[![Releases](https://img.shields.io/packagist/v/free-elephants/json-api-dto.svg)](https://github.com/FreeElephants/json-api-dto/releases)
7+
8+
## Features:
9+
10+
Build Data Transfer Objects from PSR7 Messages.
11+
12+
Full typed objects from request or response body.
13+
14+
See example in [test](/tests/FreeElephants/JsonApiToolkit/DTO/DocumentTest.php).
15+
16+
Union types support for relationships in PHP 8.
17+
18+
19+
## Usage
20+
21+
Extend super types in your own json api documents and it's parts:
22+
- \FreeElephants\JsonApiToolkit\DTO\AbstractAttributes
23+
- \FreeElephants\JsonApiToolkit\DTO\AbstractDocument
24+
- \FreeElephants\JsonApiToolkit\DTO\AbstractRelationships
25+
- \FreeElephants\JsonApiToolkit\DTO\AbstractResourceObject
26+
27+
And use as properties types:
28+
- \FreeElephants\JsonApiToolkit\DTO\RelationshipToOne
29+
- \FreeElephants\JsonApiToolkit\DTO\ResourceIdentifierObject
30+
31+
See tests/ for more examples.
32+
33+
### Install
34+
35+
`composer require free-elephants/json-api-dto`
36+
37+
## Development
38+
39+
All dev env is dockerized. Your can use make receipts and `bin/` scripts without locally installed php, composer.
40+
41+
For run tests with different php version change `PHP_VERSION` value in .env and rebuild image with `make build`.

bin/composer

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
mkdir -p $HOME/.composer/cache/
4+
5+
test -t 1 && USE_TTY="--tty"
6+
7+
docker run --rm --interactive ${USE_TTY} \
8+
--init \
9+
--user `id -u`:`id -g` \
10+
--volume $PWD:/app \
11+
--volume $HOME/.composer:/tmp/.composer \
12+
--env COMPOSER_HOME=/tmp/.composer \
13+
${PHP_DEV_IMAGE} composer "$@"

bin/php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
test -t 1 && USE_TTY="--tty"
4+
5+
docker run --rm --interactive ${USE_TTY} \
6+
--init \
7+
--user `id -u`:`id -g` \
8+
--volume $PWD:/app \
9+
${PHP_DEV_IMAGE} php "$@"

composer.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "free-elephants/json-api-dto",
3+
"description": "JsonApi Document Structure Types",
4+
"license": "BSD-2-Clause",
5+
"authors": [
6+
{
7+
"name": "samizdam",
8+
"email": "[email protected]"
9+
}
10+
],
11+
"config": {
12+
"sort-packages": true
13+
},
14+
"require": {
15+
"ext-json": "*",
16+
"psr/http-message": "*"
17+
},
18+
"require-dev": {
19+
"helmich/phpunit-psr7-assert": "^4",
20+
"nyholm/psr7": "^1.2",
21+
"phpunit/phpunit": "^10.5.38|^11.0"
22+
},
23+
"suggest": {
24+
"free-elephants/di": "*",
25+
"nyholm/psr7": "^1.2"
26+
},
27+
"autoload": {
28+
"psr-4": {
29+
"FreeElephants\\": [
30+
"src/FreeElephants"
31+
]
32+
}
33+
},
34+
"autoload-dev": {
35+
"psr-4": {
36+
"FreeElephants\\": [
37+
"tests/FreeElephants"
38+
]
39+
}
40+
}
41+
}

dev.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
PHP_DEV_IMAGE=free-elephants/json-api-dto
2+
PHP_VERSION=8.3
3+

0 commit comments

Comments
 (0)