Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel 11.x Compatibility #49

Merged
merged 16 commits into from
Mar 13, 2024
255 changes: 132 additions & 123 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,128 +1,137 @@
name: CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
push:
branches:
- main
pull_request:
branches:
- main

jobs:
lint:
runs-on: ubuntu-latest
name: 'Lint'
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
coverage: pcov

- name: Install dependencies
run: composer update

- name: Check platform requirements
run: composer check-platform-reqs

- name: PHP-CS-Fixer
run: composer fix -- --dry-run

# - name: composer normalize
# run: composer normalize --dry-run --no-interaction --verbose

# - name: test coverage
# run: |
# ./vendor/bin/phpunit --coverage-clover=coverage.xml --debug --verbose
# bash <(curl -s https://codecov.io/bash)
# env:
# CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

# - name: Infection
# run: ./vendor/bin/infection --show-mutations --min-covered-msi=100 --no-progress --no-interaction --verbose
# env:
# INFECTION_BADGE_API_KEY: ${{ secrets.INFECTION_BADGE_API_KEY }}

# - name: Psalm
# run: ./vendor/bin/psalm --shepherd --no-progress

# - name: PHPStan
# run: ./vendor/bin/phpstan --no-interaction --verbose
#
# composer-require-checker
# composer-unused

tests:
runs-on: ubuntu-latest
name: 'PHP: ${{ matrix.php }}; Laravel: ${{ matrix.laravel }}; Prefer: ${{ matrix.prefer }}'
strategy:
matrix:
php: ['8.1', '8.2']
laravel: ['^9.0', '^10.0']
prefer: ['prefer-lowest', 'prefer-stable']
include:
- testbench: '^7.0'
laravel: '^9.0'
- testbench: '^8.0'
laravel: '^10.0'

steps:
- name: checkout code
uses: actions/checkout@v3

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-php-${{ matrix.php }}-laravel-${{ matrix.laravel }}-prefer-${{ matrix.prefer }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-php-${{ matrix.php }}-laravel-{{ matrix.laravel }}-prefer-${{ matrix.prefer}}-composer-

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none

- name: Remove dev packages
run: |
composer remove --dev --no-update \
friendsofphp/php-cs-fixer \
infection/infection \
nunomaduro/larastan \
phpstan/phpstan-strict-rules

- name: Require Laravel and Testbench version
run: composer require --no-update laravel/framework:"${{ matrix.laravel }}" illuminate/collections:"${{ matrix.laravel }}" illuminate/database:"${{ matrix.laravel }}" illuminate/http:"${{ matrix.laravel }}" illuminate/support:"${{ matrix.laravel }}" orchestra/testbench:"${{ matrix.testbench }}"

- name: Support prefer-lowest in PHP 8.1
if: ${{ matrix.php == 8.1 && matrix.prefer == 'prefer-lowest' }}
run: composer require --no-update nesbot/carbon:"^2.62.1"

- name: Support prefer-lowest in PHP 8.2
if: ${{ matrix.php == 8.2 && matrix.prefer == 'prefer-lowest' }}
run: composer require --no-update nesbot/carbon:"^2.62.1"

- name: Install dependencies
run: composer update --${{ matrix.prefer }}

- name: Check platform requirements
run: composer check-platform-reqs --verbose

- name: Run tests
run: composer test
lint:
runs-on: ubuntu-latest
name: Lint
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use php 8.3 as latest version

Copy link
Owner

@timacdonald timacdonald Mar 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is okay as it is just linting / fixing.

coverage: pcov

- name: Install dependencies
run: composer update

- name: Check platform requirements
run: composer check-platform-reqs

- name: PHP-CS-Fixer
run: composer fix -- --dry-run

# - name: composer normalize
# run: composer normalize --dry-run --no-interaction --verbose

# - name: test coverage
# run: "./vendor/bin/phpunit --coverage-clover=coverage.xml --debug --verbose && bash <(curl -s https://codecov.io/bash)"
# env:
# CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

# - name: Infection
# run: "./vendor/bin/infection --show-mutations --min-covered-msi=100 --no-progress --no-interaction --verbose"
# env:
# INFECTION_BADGE_API_KEY: ${{ secrets.INFECTION_BADGE_API_KEY }}

# - name: Psalm
# run: ./vendor/bin/psalm --shepherd --no-progress

# - name: PHPStan
# run: ./vendor/bin/phpstan --no-interaction --verbose

# composer-require-checker
# composer-unused

tests:
runs-on: ubuntu-latest
name: "PHP: ${{ matrix.php }}; Laravel: ${{ matrix.laravel }}; Prefer: ${{ matrix.prefer }}"
strategy:
matrix:
php: ['8.1', '8.2', '8.3']
laravel: [^9.0, ^10.0, ^11.0]
prefer: [prefer-lowest, prefer-stable]
include:
- testbench: ^7.0
laravel: ^9.0
- testbench: ^8.0
laravel: ^10.0
- testbench: ^9.0
laravel: ^11.0
exclude:
- laravel: ^11.0
php: '8.1'

steps:
- name: checkout code
uses: actions/checkout@v3

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-php-${{ matrix.php }}-laravel-${{ matrix.laravel }}-prefer-${{ matrix.prefer }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-php-${{ matrix.php }}-laravel-{{ matrix.laravel }}-prefer-${{ matrix.prefer}}-composer-

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none

- name: Remove dev packages
run: |
composer remove --dev --no-update \
friendsofphp/php-cs-fixer \
infection/infection \
nunomaduro/larastan \
phpstan/phpstan-strict-rules

- name: Require Laravel and Testbench version
run: composer require --no-update laravel/framework:"${{ matrix.laravel }}" illuminate/collections:"${{ matrix.laravel }}" illuminate/database:"${{ matrix.laravel }}" illuminate/http:"${{ matrix.laravel }}" illuminate/support:"${{ matrix.laravel }}" orchestra/testbench:"${{ matrix.testbench }}"

- name: Support prefer-lowest in PHP 8.1
if: ${{ matrix.php == 8.1 && matrix.prefer == 'prefer-lowest' }}
run: composer require --no-update nesbot/carbon:"^2.62.1"

- name: Support prefer-lowest in PHP 8.2
if: ${{ matrix.php == 8.2 && matrix.prefer == 'prefer-lowest' }}
run: composer require --no-update nesbot/carbon:"^2.62.1"

- name: Support prefer-lowest in PHP 8.3
if: ${{ matrix.php == 8.3 && matrix.prefer == 'prefer-lowest' }}
run: composer require --no-update nesbot/carbon:"^2.62.1"

- name: Install dependencies
run: composer update --${{ matrix.prefer }}

- name: Check platform requirements
run: composer check-platform-reqs --verbose

- name: Run tests
run: composer test
27 changes: 27 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,30 @@ Now collections are formatted correctly. The `posts` value is now an object and
}
}
```

## Server implementation no longer included by default

Previously, the top level `jsonapi` property was included in every response...

```json5
{
// ...
"jsonapi": {
"version": "1.0"
}
}
```

This is no longer the case. If you would like to include a server implementation in your API responses you may call the `JsonApiResource::resolveServerImplementationUsing` method in a service provider or middleware:

```php
use TiMacDonald\JsonApi\JsonApiResource;
use TiMacDonald\JsonApi\ServerImplementation;


JsonApiResource::resolveServerImplementationUsing(function () {
return new ServerImplementation(version: '1.4.3', meta: [
'secure' => true,
]);
});
```
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@
}
],
"require": {
"php": "~8.1.0 || ~8.2.0",
"illuminate/collections": "^9.0 || ^10.0",
"illuminate/database": "^9.0 || ^10.0",
"illuminate/http": "^9.0 || ^10.0",
"illuminate/support": "^9.0 || ^10.0",
"symfony/http-kernel": "^6.0"
"php": "~8.1.0 || ~8.2.0 || ~8.3.0",
"illuminate/collections": "^9.0 || ^10.0 || ^11.0",
"illuminate/database": "^9.0 || ^10.0 || ^11.0",
"illuminate/http": "^9.0 || ^10.0 || ^11.0",
"illuminate/support": "^9.0 || ^10.0 || ^11.0",
"symfony/http-kernel": "^6.0 || ^7.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.13",
"laravel/framework": "^9.0 || ^10.0",
"laravel/framework": "^9.0 || ^10.0 || ^11.0",
"opis/json-schema": "^2.3",
"orchestra/testbench": "^7.0 || ^8.0",
"phpunit/phpunit": "^9.0"
"orchestra/testbench": "^7.0 || ^8.0 || ^9.0",
"phpunit/phpunit": "^9.0 || ^10.5"
},
"config": {
"preferred-install": "dist",
Expand Down
4 changes: 2 additions & 2 deletions src/Concerns/Implementation.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ trait Implementation
/**
* @api
*
* @param (callable(): JsonApiServerImplementation) $callback
* @param (callable(): ServerImplementation) $callback
* @return void
*/
public static function resolveServerImplementationUsing(callable $callback)
Expand All @@ -24,7 +24,7 @@ public static function resolveServerImplementationUsing(callable $callback)
/**
* @internal
*
* @return (callable(Request): (JsonApiServerImplementation|null))
* @return (callable(Request): (ServerImplementation|null))
*/
public static function serverImplementationResolver()
{
Expand Down
7 changes: 4 additions & 3 deletions src/JsonApiResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function toResourceIdentifier(Request $request)
}

/**
* @return JsonApiServerImplementation|null
* @return ServerImplementation|null
*/
public static function toServerImplementation(Request $request)
{
Expand All @@ -124,9 +124,10 @@ public function toArray($request)
}

/**
* @return array{included?: array<int, JsonApiResource>, jsonapi: JsonApiServerImplementation}
* @param Request $request
* @return array{included?: array<int, JsonApiResource>, jsonapi: ServerImplementation}
*/
public function with(Request $request)
public function with($request)
{
return [
...($included = $this->included($request)
Expand Down
5 changes: 3 additions & 2 deletions src/JsonApiResourceCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ private function resolveResourceIdentifiers(Request $request)
}

/**
* @return array{included?: array<int, JsonApiResource>, jsonapi?: JsonApiServerImplementation}
* @param Request $request
* @return array{included?: array<int, JsonApiResource>, jsonapi?: ServerImplementation}
*/
public function with(Request $request)
public function with($request)
{
return [
...($included = $this->collection
Expand Down
Loading
Loading