Skip to content

Commit 62377f8

Browse files
committed
Merge 4.0
2 parents 771d940 + 8981672 commit 62377f8

File tree

23 files changed

+276
-140
lines changed

23 files changed

+276
-140
lines changed

.php-cs-fixer.dist.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
]);
3030

3131
return (new PhpCsFixer\Config())
32-
->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect())
3332
->setRiskyAllowed(true)
3433
->setRules([
3534
'@DoctrineAnnotation' => true,

docs/pdg.config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pdg:
55
src: './guides'
66
references:
77
base_url: '/docs/reference'
8-
exclude: ['*Factory.php', '*.tpl.php', 'deprecation.php']
8+
exclude: ['*Factory.php', '*.php.tpl', 'deprecation.php']
99
exclude_path: ['OpenApi/Tests', 'JsonSchema/Tests', 'RamseyUuid/Tests', 'Metadata/Tests', 'HttpCache/Tests', 'Elasticsearch/Tests', 'Doctrine/Common/Tests', 'GraphQl/Tests', 'Serializer/Tests']
1010
namespace: 'ApiPlatform'
1111
output: 'dist/reference'

src/Laravel/ApiPlatformProvider.php

Lines changed: 2 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
use ApiPlatform\JsonApi\Serializer\ItemNormalizer as JsonApiItemNormalizer;
6767
use ApiPlatform\JsonApi\Serializer\ObjectNormalizer as JsonApiObjectNormalizer;
6868
use ApiPlatform\JsonApi\Serializer\ReservedAttributeNameConverter;
69-
use ApiPlatform\JsonLd\Action\ContextAction;
7069
use ApiPlatform\JsonLd\AnonymousContextBuilderInterface;
7170
use ApiPlatform\JsonLd\ContextBuilder as JsonLdContextBuilder;
7271
use ApiPlatform\JsonLd\ContextBuilderInterface;
@@ -125,7 +124,6 @@
125124
use ApiPlatform\Laravel\State\SwaggerUiProcessor;
126125
use ApiPlatform\Laravel\State\SwaggerUiProvider;
127126
use ApiPlatform\Laravel\State\ValidateProvider;
128-
use ApiPlatform\Metadata\Exception\NotExposedHttpException;
129127
use ApiPlatform\Metadata\IdentifiersExtractor;
130128
use ApiPlatform\Metadata\IdentifiersExtractorInterface;
131129
use ApiPlatform\Metadata\InflectorInterface;
@@ -197,10 +195,6 @@
197195
use Illuminate\Config\Repository as ConfigRepository;
198196
use Illuminate\Contracts\Debug\ExceptionHandler as ExceptionHandlerInterface;
199197
use Illuminate\Contracts\Foundation\Application;
200-
use Illuminate\Contracts\Foundation\CachesRoutes;
201-
use Illuminate\Http\Request;
202-
use Illuminate\Routing\Route;
203-
use Illuminate\Routing\RouteCollection;
204198
use Illuminate\Routing\Router;
205199
use Illuminate\Support\ServiceProvider;
206200
use Negotiation\Negotiator;
@@ -1351,7 +1345,7 @@ private function registerGraphQl(Application $app): void
13511345
/**
13521346
* Bootstrap services.
13531347
*/
1354-
public function boot(ResourceNameCollectionFactoryInterface $resourceNameCollectionFactory, ResourceMetadataCollectionFactoryInterface $resourceMetadataFactory, Router $router): void
1348+
public function boot(): void
13551349
{
13561350
if ($this->app->runningInConsole()) {
13571351
$this->publishes([
@@ -1373,94 +1367,6 @@ public function boot(ResourceNameCollectionFactoryInterface $resourceNameCollect
13731367
$typeBuilder->setFieldsBuilderLocator(new ServiceLocator(['api_platform.graphql.fields_builder' => $fieldsBuilder]));
13741368
}
13751369

1376-
if (!$this->shouldRegisterRoutes()) {
1377-
return;
1378-
}
1379-
1380-
$globalMiddlewares = $config->get('api-platform.routes.middleware');
1381-
$routeCollection = new RouteCollection();
1382-
foreach ($resourceNameCollectionFactory->create() as $resourceClass) {
1383-
foreach ($resourceMetadataFactory->create($resourceClass) as $resourceMetadata) {
1384-
foreach ($resourceMetadata->getOperations() as $operation) {
1385-
$uriTemplate = $operation->getUriTemplate();
1386-
// _format is read by the middleware
1387-
$uriTemplate = $operation->getRoutePrefix().str_replace('{._format}', '{_format?}', $uriTemplate);
1388-
$route = (new Route([$operation->getMethod()], $uriTemplate, [ApiPlatformController::class, '__invoke']))
1389-
->where('_format', '^\.[a-zA-Z]+')
1390-
->name($operation->getName())
1391-
->setDefaults(['_api_operation_name' => $operation->getName(), '_api_resource_class' => $operation->getClass()]);
1392-
1393-
$route->middleware(ApiPlatformMiddleware::class.':'.$operation->getName());
1394-
$route->middleware($globalMiddlewares);
1395-
$route->middleware($operation->getMiddleware());
1396-
1397-
$routeCollection->add($route);
1398-
}
1399-
}
1400-
}
1401-
1402-
$prefix = $config->get('api-platform.defaults.route_prefix') ?? '';
1403-
$route = new Route(['GET'], $prefix.'/contexts/{shortName?}{_format?}', [ContextAction::class, '__invoke']);
1404-
$route->name('api_jsonld_context');
1405-
$route->middleware(ApiPlatformMiddleware::class);
1406-
$route->middleware($globalMiddlewares);
1407-
$routeCollection->add($route);
1408-
$route = new Route(['GET'], $prefix.'/docs{_format?}', function (Request $request, Application $app) {
1409-
$documentationAction = $app->make(DocumentationController::class);
1410-
1411-
return $documentationAction->__invoke($request);
1412-
});
1413-
$route->name('api_doc');
1414-
$route->middleware(ApiPlatformMiddleware::class);
1415-
$route->middleware($globalMiddlewares);
1416-
$routeCollection->add($route);
1417-
1418-
$route = new Route(['GET'], $prefix.'/.well-known/genid/{id}', function (): void {
1419-
throw new NotExposedHttpException('This route is not exposed on purpose. It generates an IRI for a collection resource without identifier nor item operation.');
1420-
});
1421-
$route->name('api_genid');
1422-
$route->middleware(ApiPlatformMiddleware::class);
1423-
$route->middleware($globalMiddlewares);
1424-
$routeCollection->add($route);
1425-
1426-
if ($config->get('api-platform.graphql.enabled')) {
1427-
$route = new Route(['POST', 'GET'], $prefix.'/graphql', function (Application $app, Request $request) {
1428-
$entrypointAction = $app->make(GraphQlEntrypointController::class);
1429-
1430-
return $entrypointAction->__invoke($request);
1431-
});
1432-
$route->middleware($globalMiddlewares);
1433-
$routeCollection->add($route);
1434-
1435-
$route = new Route(['GET'], $prefix.'/graphiql', function (Application $app) {
1436-
$controller = $app->make(GraphiQlController::class);
1437-
1438-
return $controller->__invoke();
1439-
});
1440-
$route->middleware($globalMiddlewares);
1441-
$routeCollection->add($route);
1442-
}
1443-
1444-
$route = new Route(['GET'], $prefix.'/{index?}{_format?}', function (Request $request, Application $app) {
1445-
$entrypointAction = $app->make(EntrypointController::class);
1446-
1447-
return $entrypointAction->__invoke($request);
1448-
});
1449-
$route->where('index', 'index');
1450-
$route->name('api_entrypoint');
1451-
$route->middleware(ApiPlatformMiddleware::class);
1452-
$route->middleware($globalMiddlewares);
1453-
$routeCollection->add($route);
1454-
1455-
$router->setRoutes($routeCollection);
1456-
}
1457-
1458-
private function shouldRegisterRoutes(): bool
1459-
{
1460-
if ($this->app instanceof CachesRoutes && $this->app->routesAreCached()) {
1461-
return false;
1462-
}
1463-
1464-
return true;
1370+
$this->loadRoutesFrom(__DIR__.'/routes/api.php');
14651371
}
14661372
}

src/Laravel/ApiResource/Error.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#[ErrorResource(
2929
types: ['hydra:Error'],
3030
openapi: false,
31+
uriVariables: ['status'],
3132
operations: [
3233
new Operation(
3334
name: '_api_errors_problem',

src/Laravel/Console/Maker/Utils/StateTemplateGenerator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ public function generate(string $pathLink, string $stateClassName, StateTypeEnum
4949
private function loadTemplate(StateTypeEnum $stateTypeEnum): string
5050
{
5151
$templateFile = match ($stateTypeEnum) {
52-
StateTypeEnum::Provider => 'StateProvider.tpl.php',
53-
StateTypeEnum::Processor => 'StateProcessor.tpl.php',
52+
StateTypeEnum::Provider => 'StateProvider.php.tpl',
53+
StateTypeEnum::Processor => 'StateProcessor.php.tpl',
5454
};
5555

5656
$templatePath = \dirname(__DIR__).'/Resources/skeleton/'.$templateFile;

src/Laravel/Tests/ApiTest.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
use ApiPlatform\Laravel\Test\ApiTestAssertionsTrait;
15+
use Illuminate\Contracts\Config\Repository;
16+
use Illuminate\Foundation\Application;
17+
use Illuminate\Foundation\Testing\RefreshDatabase;
18+
use Orchestra\Testbench\Concerns\WithWorkbench;
19+
use Orchestra\Testbench\TestCase;
20+
21+
class ApiTest extends TestCase
22+
{
23+
use ApiTestAssertionsTrait;
24+
use RefreshDatabase;
25+
use WithWorkbench;
26+
27+
/**
28+
* @param Application $app
29+
*/
30+
protected function defineEnvironment($app): void
31+
{
32+
tap($app['config'], function (Repository $config): void {
33+
$config->set('api-platform.routes.domain', 'http://test.com');
34+
$config->set('app.debug', true);
35+
$config->set('api-platform.formats', ['jsonld' => ['application/ld+json']]);
36+
$config->set('api-platform.docs_formats', ['jsonld' => ['application/ld+json']]);
37+
});
38+
}
39+
40+
public function testDomainCanBeSet(): void
41+
{
42+
$response = $this->get('http://foobar.com/api/', ['accept' => ['application/ld+json']]);
43+
$response->assertNotFound();
44+
45+
$response = $this->get('http://test.com/api/', ['accept' => ['application/ld+json']]);
46+
$response->assertSuccessful();
47+
}
48+
}

src/Laravel/Tests/Console/Maker/Utils/AppServiceFileGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function __construct(private Filesystem $filesystem)
2727
*/
2828
public function regenerateProviderFile(): void
2929
{
30-
$templatePath = \dirname(__DIR__).'/Resources/skeleton/AppServiceProvider.tpl.php';
30+
$templatePath = \dirname(__DIR__).'/Resources/skeleton/AppServiceProvider.php.tpl';
3131
$targetPath = base_path('app/Providers/AppServiceProvider.php');
3232

3333
$this->regenerateFileFromTemplate($templatePath, $targetPath);

0 commit comments

Comments
 (0)