Skip to content

Commit

Permalink
feat(laravel): laravel component
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka committed Jun 18, 2024
1 parent e463d0b commit f3e58ed
Show file tree
Hide file tree
Showing 101 changed files with 92,103 additions and 8 deletions.
1 change: 1 addition & 0 deletions .commitlintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
2,
"always",
[
"laravel",
"symfony",
"doctrine",
"metadata",
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ jobs:
run: |
./vendor/bin/phpstan --version
./vendor/bin/phpstan analyse --no-interaction --no-progress --ansi
- name: Run PHPStan analysis (laravel)
working-directory: 'src/Laravel'
run: |
composer update
./vendor/bin/phpstan analyse --no-interaction --no-progress --ansi
phpunit:
name: PHPUnit (PHP ${{ matrix.php }})
Expand Down Expand Up @@ -1333,3 +1338,38 @@ jobs:
name: openapi-docs-php${{ matrix.php }}
path: build/out/openapi
continue-on-error: true

laravel:
name: Laravel (PHP ${{ matrix.php }})
runs-on: ubuntu-latest
timeout-minutes: 20
strategy:
matrix:
php:
- '8.2'
- '8.3'
include:
- php: '8.2'
coverage: true
- php: '8.3'
coverage: true
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: pecl, composer
extensions: intl, bcmath, curl, openssl, mbstring, pdo_sqlite, mongodb
ini-values: memory_limit=-1
- name: Run ${{ matrix.component }} install
run: |
composer update
composer api-platform/laravel update
- name: PHP version tweaks
run: |
composer run-script build
composer run-script test
working-directory: 'src/Laravel'
15 changes: 13 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@
"friends-of-behat/mink-extension": "^2.2",
"friends-of-behat/symfony-extension": "^2.1",
"guzzlehttp/guzzle": "^6.0 || ^7.0",
"illuminate/config": "^10.0||^11.0",
"illuminate/container": "^10.0||^11.0",
"illuminate/contracts": "^10.0||^11.0",
"illuminate/database": "^10.0||^11.0",
"illuminate/http": "^10.0||^11.0",
"illuminate/pagination": "^10.0||^11.0",
"illuminate/routing": "^10.0||^11.0",
"illuminate/support": "^10.0||^11.0",
"laravel/framework": "^10.0||^11.0",
"jangregor/phpstan-prophecy": "^1.0",
"justinrainbow/json-schema": "^5.2.1",
"phpspec/prophecy-phpunit": "^2.0",
Expand Down Expand Up @@ -181,7 +190,8 @@
"api-platform/serializer",
"api-platform/state",
"api-platform/symfony",
"api-platform/validator"
"api-platform/validator",
"api-platform/laravel"
]
},
"repositories": [
Expand All @@ -202,6 +212,7 @@
{"type": "path", "url": "./src/Serializer"},
{"type": "path", "url": "./src/State"},
{"type": "path", "url": "./src/Symfony"},
{"type": "path", "url": "./src/Validator"}
{"type": "path", "url": "./src/Validator"},
{"type": "path", "url": "./src/Laravel"}
]
}
3 changes: 2 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ parameters:
- src/Symfony/Bundle/Test/Constraint/ArraySubset.php
- tests/Fixtures/app/AppKernel.php
excludePaths:
# uses larastan
- src/Laravel
- src/Symfony/Bundle/Command/OpenApiCommand.php
# Symfony config
- tests/Fixtures/app/config/config_swagger.php
Expand Down Expand Up @@ -99,5 +101,4 @@ parameters:
# Backward compatibility
- '#Call to method hasCacheableSupportsMethod\(\) on an unknown class Symfony\\Component\\Serializer\\Normalizer\\CacheableSupportsMethodInterface\.#'
- '#Class Symfony\\Component\\Serializer\\Normalizer\\CacheableSupportsMethodInterface not found\.#'
- '#Access to undefined constant Symfony\\Component\\HttpKernel\\HttpKernelInterface::MASTER_REQUEST\.#'
- '#Attribute class PHPUnit\\Framework\\Attributes\\DataProvider does not exist.#'
1 change: 1 addition & 0 deletions src/Documentation/Action/DocumentationAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class: OpenApi::class,
);

if ('html' === $format) {
// TODO: support laravel this bounds Documentation with Symfony so it's not perfect
$operation = $operation->withProcessor('api_platform.swagger_ui.processor')->withWrite(true);
}
if ('json' === $format) {
Expand Down
4 changes: 4 additions & 0 deletions src/JsonLd/Action/ContextAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ public function __construct(
*/
public function __invoke(string $shortName = 'Entrypoint', ?Request $request = null): array|Response
{
if (!$shortName) {
$shortName = 'Entrypoint';
}

if (null !== $request && $this->provider && $this->processor && $this->serializer) {
$operation = new Get(
outputFormats: ['jsonld' => ['application/ld+json']],
Expand Down
4 changes: 4 additions & 0 deletions src/Laravel/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/.gitattributes export-ignore
/.gitignore export-ignore
/workbench export-ignore
/Tests export-ignore
3 changes: 3 additions & 0 deletions src/Laravel/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/composer.lock
/vendor
/.phpunit.result.cache
40 changes: 40 additions & 0 deletions src/Laravel/ApiPlatformMiddleware.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ApiPlatform\Laravel;

use ApiPlatform\Metadata\Operation\Factory\OperationMetadataFactory;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class ApiPlatformMiddleware
{
public function __construct(
protected OperationMetadataFactory $operationMetadataFactory,
) {
}

/**
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, \Closure $next, ?string $operationName = null): Response
{
if ($operationName) {
$request->attributes->set('_api_operation', $this->operationMetadataFactory->create($operationName));
}

$request->attributes->set('_format', str_replace('.', '', $request->route('_format') ?? ''));

return $next($request);
}
}
Loading

0 comments on commit f3e58ed

Please sign in to comment.