• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

api-platform / core / 15775135891

20 Jun 2025 08:42AM UTC coverage: 22.065% (+0.2%) from 21.876%
15775135891

push

github

soyuka
Merge 4.1

13 of 103 new or added lines in 10 files covered. (12.62%)

868 existing lines in 35 files now uncovered.

11487 of 52060 relevant lines covered (22.06%)

21.72 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Laravel/routes/api.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@gmail.com>
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\JsonLd\Action\ContextAction;
15
use ApiPlatform\Laravel\ApiPlatformMiddleware;
16
use ApiPlatform\Laravel\Controller\ApiPlatformController;
17
use ApiPlatform\Laravel\Controller\DocumentationController;
18
use ApiPlatform\Laravel\Controller\EntrypointController;
19
use ApiPlatform\Laravel\GraphQl\Controller\EntrypointController as GraphQlEntrypointController;
20
use ApiPlatform\Laravel\GraphQl\Controller\GraphiQlController;
21
use ApiPlatform\Metadata\Exception\NotExposedHttpException;
22
use ApiPlatform\Metadata\HttpOperation;
23
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
24
use ApiPlatform\Metadata\Resource\Factory\ResourceNameCollectionFactoryInterface;
25
use ApiPlatform\OpenApi\Attributes\Webhook;
26
use Illuminate\Support\Facades\Route;
27

28
$globalMiddlewares = config()->get('api-platform.routes.middleware', []);
×
UNCOV
29
$domain = config()->get('api-platform.routes.domain', '');
×
30

31
Route::domain($domain)->middleware($globalMiddlewares)->group(function (): void {
×
32
    $resourceNameCollectionFactory = app()->make(ResourceNameCollectionFactoryInterface::class);
×
UNCOV
33
    $resourceMetadataFactory = app()->make(ResourceMetadataCollectionFactoryInterface::class);
×
34

35
    foreach ($resourceNameCollectionFactory->create() as $resourceClass) {
×
36
        foreach ($resourceMetadataFactory->create($resourceClass) as $resourceMetadata) {
×
37
            foreach ($resourceMetadata->getOperations() as $operation) {
×
38
                if ($operation->getOpenapi() instanceof Webhook) {
×
UNCOV
39
                    continue;
×
40
                }
41

UNCOV
42
                if ($operation->getRouteName()) {
×
UNCOV
43
                    continue;
×
44
                }
45

46
                $uriTemplate = str_replace('{._format}', '{_format?}', $operation->getUriTemplate());
×
47

48
                /* @var HttpOperation $operation */
49
                $route = Route::addRoute($operation->getMethod(), $uriTemplate, ['uses' => ApiPlatformController::class, 'prefix' => $operation->getRoutePrefix() ?? ''])
×
UNCOV
50
                    ->where([
×
51
                        '_format' => '^\.[a-zA-Z]+',
×
52
                    ] + ($operation->getRequirements() ?? []))
×
UNCOV
53
                    ->name($operation->getName())
×
UNCOV
54
                    ->setDefaults(['_api_operation_name' => $operation->getName(), '_api_resource_class' => $operation->getClass()]);
×
55

UNCOV
56
                $route->middleware(ApiPlatformMiddleware::class.':'.$operation->getName());
×
57

58
                if ($operation->getMiddleware()) {
×
UNCOV
59
                    $route->middleware($operation->getMiddleware());
×
60
                }
61
            }
62
        }
63
    }
64

65
    $prefix = config()->get('api-platform.defaults.route_prefix', '');
×
66

67
    Route::group(['prefix' => $prefix], function (): void {
×
UNCOV
68
        Route::group(['middleware' => ApiPlatformMiddleware::class], function (): void {
×
69
            Route::get('/contexts/{shortName?}{_format?}', ContextAction::class)
×
70
                ->name('api_jsonld_context');
×
71

72
            Route::get('/validation_errors/{id}', fn () => throw new NotExposedHttpException('Not exposed.'))
×
73
                ->name('api_validation_errors')
×
UNCOV
74
                ->middleware(ApiPlatformMiddleware::class);
×
75

76
            Route::get('/docs{_format?}', DocumentationController::class)
×
77
                ->name('api_doc');
×
78

UNCOV
79
            Route::get('/.well-known/genid/{id}', fn () => throw new NotExposedHttpException('This route is not exposed on purpose. It generates an IRI for a collection resource without identifier nor item operation.'))
×
80
                ->name('api_genid');
×
81

82
            Route::get('/{index?}{_format?}', EntrypointController::class)
×
83
                ->where('index', 'index')
×
84
                ->name('api_entrypoint');
×
85
        });
×
86

UNCOV
87
        if (config()->get('api-platform.graphql.enabled')) {
×
88
            Route::group([
×
89
                'middleware' => config()->get('api-platform.graphql.middleware', []),
×
90
            ], function (): void {
×
91
                Route::addRoute(['POST', 'GET'], '/graphql', GraphQlEntrypointController::class)
×
92
                    ->name('api_graphql');
×
93
            });
×
94

95
            if (config()->get('api-platform.graphiql.enabled', true)) {
×
UNCOV
96
                Route::group([
×
UNCOV
97
                    'middleware' => config()->get('api-platform.graphiql.middleware', []),
×
98
                    'domain' => config()->get('api-platform.graphiql.domain', ''),
×
99
                ], function (): void {
×
UNCOV
100
                    Route::get('/graphiql', GraphiQlController::class)
×
UNCOV
101
                        ->name('api_graphiql');
×
UNCOV
102
                });
×
103
            }
104
        }
UNCOV
105
    });
×
UNCOV
106
});
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc