Skip to content

Commit 16b26b7

Browse files
authored
Revert "chore: remove 3.4 deprecation (#7204)"
This reverts commit 4949b4e.
1 parent fe921cd commit 16b26b7

File tree

33 files changed

+1632
-26
lines changed

33 files changed

+1632
-26
lines changed

src/Doctrine/Odm/State/LinksHandlerTrait.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,12 @@ private function handleLinks(Builder $aggregationBuilder, array $identifiers, ar
5959
/**
6060
* @throws RuntimeException
6161
*/
62-
private function buildAggregation(string $toClass, array $links, array $identifiers, array $context, array $executeOptions, string $previousAggregationClass, Builder $previousAggregationBuilder, Operation $operation): Builder
62+
private function buildAggregation(string $toClass, array $links, array $identifiers, array $context, array $executeOptions, string $previousAggregationClass, Builder $previousAggregationBuilder, ?Operation $operation = null): Builder
6363
{
64+
if (!$operation) {
65+
trigger_deprecation('api-platform/core', '3.2', 'In API Platform 4 the last argument "operation" will be required and this trait will be internal. Use the "handleLinks" feature instead.');
66+
}
67+
6468
if (\count($links) <= 0) {
6569
return $previousAggregationBuilder;
6670
}
@@ -84,8 +88,10 @@ private function buildAggregation(string $toClass, array $links, array $identifi
8488

8589
$manager = $this->managerRegistry->getManagerForClass($aggregationClass);
8690
if (!$manager instanceof DocumentManager) {
87-
$aggregationClass = $this->getLinkFromClass($link, $operation);
88-
$manager = $this->managerRegistry->getManagerForClass($aggregationClass);
91+
if ($operation) {
92+
$aggregationClass = $this->getLinkFromClass($link, $operation);
93+
$manager = $this->managerRegistry->getManagerForClass($aggregationClass);
94+
}
8995

9096
if (!$manager instanceof DocumentManager) {
9197
throw new RuntimeException(\sprintf('The manager for "%s" must be an instance of "%s".', $aggregationClass, DocumentManager::class));

src/GraphQl/Action/EntrypointAction.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@ public function __construct(
4141
private readonly SchemaBuilderInterface $schemaBuilder,
4242
private readonly ExecutorInterface $executor,
4343
private readonly ?GraphiQlAction $graphiQlAction,
44+
private readonly ?GraphQlPlaygroundAction $graphQlPlaygroundAction,
4445
private readonly NormalizerInterface $normalizer,
4546
private readonly ErrorHandlerInterface $errorHandler,
4647
bool $debug = false,
4748
private readonly bool $graphiqlEnabled = false,
49+
private readonly bool $graphQlPlaygroundEnabled = false,
4850
private readonly ?string $defaultIde = null,
4951
?Negotiator $negotiator = null,
5052
) {
@@ -62,6 +64,10 @@ public function __invoke(Request $request): Response
6264
if ('graphiql' === $this->defaultIde && $this->graphiqlEnabled && $this->graphiQlAction) {
6365
return ($this->graphiQlAction)($request);
6466
}
67+
68+
if ('graphql-playground' === $this->defaultIde && $this->graphQlPlaygroundEnabled && $this->graphQlPlaygroundAction) {
69+
return ($this->graphQlPlaygroundAction)($request);
70+
}
6571
}
6672

6773
[$query, $operationName, $variables] = $this->parseRequest($request);
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
namespace ApiPlatform\GraphQl\Action;
15+
16+
use Symfony\Component\HttpFoundation\Request;
17+
use Symfony\Component\HttpFoundation\Response;
18+
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
19+
use Symfony\Component\Routing\RouterInterface;
20+
use Twig\Environment as TwigEnvironment;
21+
22+
/**
23+
* GraphQL Playground entrypoint.
24+
*
25+
* @author Alan Poulain <[email protected]>
26+
*/
27+
final class GraphQlPlaygroundAction
28+
{
29+
public function __construct(private readonly TwigEnvironment $twig, private readonly RouterInterface $router, private readonly bool $graphQlPlaygroundEnabled = false, private readonly string $title = '', private $assetPackage = null)
30+
{
31+
}
32+
33+
public function __invoke(Request $request): Response
34+
{
35+
if ($this->graphQlPlaygroundEnabled) {
36+
return new Response($this->twig->render('@ApiPlatform/GraphQlPlayground/index.html.twig', [
37+
'title' => $this->title,
38+
'graphql_playground_data' => ['entrypoint' => $this->router->generate('api_graphql_entrypoint')],
39+
'assetPackage' => $this->assetPackage,
40+
]), 200, ['content-type' => 'text/html']);
41+
}
42+
43+
throw new BadRequestHttpException('GraphQL Playground is not enabled.');
44+
}
45+
}

src/GraphQl/Tests/Action/EntrypointActionTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use ApiPlatform\GraphQl\Action\EntrypointAction;
1717
use ApiPlatform\GraphQl\Action\GraphiQlAction;
18+
use ApiPlatform\GraphQl\Action\GraphQlPlaygroundAction;
1819
use ApiPlatform\GraphQl\Error\ErrorHandler;
1920
use ApiPlatform\GraphQl\ExecutorInterface;
2021
use ApiPlatform\GraphQl\Serializer\Exception\ErrorNormalizer;
@@ -269,7 +270,8 @@ private function getEntrypointAction(array $variables = ['graphqlVariable']): En
269270
$routerProphecy->generate('api_graphql_entrypoint')->willReturn('/graphiql');
270271

271272
$graphiQlAction = new GraphiQlAction($twigProphecy->reveal(), $routerProphecy->reveal(), true);
273+
$graphQlPlaygroundAction = new GraphQlPlaygroundAction($twigProphecy->reveal(), $routerProphecy->reveal(), true);
272274

273-
return new EntrypointAction($schemaBuilderProphecy->reveal(), $executorProphecy->reveal(), $graphiQlAction, $normalizer, $errorHandler, false, true, 'graphiql');
275+
return new EntrypointAction($schemaBuilderProphecy->reveal(), $executorProphecy->reveal(), $graphiQlAction, $graphQlPlaygroundAction, $normalizer, $errorHandler, false, true, true, 'graphiql');
274276
}
275277
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
namespace ApiPlatform\GraphQl\Tests\Action;
15+
16+
use ApiPlatform\GraphQl\Action\GraphQlPlaygroundAction;
17+
use PHPUnit\Framework\TestCase;
18+
use Prophecy\Argument;
19+
use Prophecy\PhpUnit\ProphecyTrait;
20+
use Symfony\Component\HttpFoundation\Request;
21+
use Symfony\Component\HttpFoundation\Response;
22+
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
23+
use Symfony\Component\Routing\RouterInterface;
24+
use Twig\Environment as TwigEnvironment;
25+
26+
/**
27+
* @author Alan Poulain <[email protected]>
28+
*/
29+
class GraphQlPlaygroundActionTest extends TestCase
30+
{
31+
use ProphecyTrait;
32+
33+
public function testEnabledAction(): void
34+
{
35+
$request = new Request();
36+
$mockedAction = $this->getGraphQlPlaygroundAction(true);
37+
38+
$this->assertInstanceOf(Response::class, $mockedAction($request));
39+
}
40+
41+
public function testDisabledAction(): void
42+
{
43+
$request = new Request();
44+
$mockedAction = $this->getGraphQlPlaygroundAction(false);
45+
46+
$this->expectExceptionObject(new BadRequestHttpException('GraphQL Playground is not enabled.'));
47+
48+
$mockedAction($request);
49+
}
50+
51+
private function getGraphQlPlaygroundAction(bool $enabled): GraphQlPlaygroundAction
52+
{
53+
$twigProphecy = $this->prophesize(TwigEnvironment::class);
54+
$twigProphecy->render(Argument::cetera())->willReturn('');
55+
$routerProphecy = $this->prophesize(RouterInterface::class);
56+
$routerProphecy->generate('api_graphql_entrypoint')->willReturn('/graphql');
57+
58+
return new GraphQlPlaygroundAction($twigProphecy->reveal(), $routerProphecy->reveal(), $enabled, '');
59+
}
60+
}

src/Laravel/ApiPlatformProvider.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,10 @@
158158
use Illuminate\Routing\Router;
159159
use Illuminate\Support\ServiceProvider;
160160
use Negotiation\Negotiator;
161-
use PHPStan\PhpDocParser\Parser\PhpDocParser;
161+
use phpDocumentor\Reflection\DocBlockFactory;
162162
use Psr\Log\LoggerInterface;
163163
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
164-
use Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor;
164+
use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
165165
use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
166166
use Symfony\Component\PropertyInfo\PropertyInfoExtractor;
167167
use Symfony\Component\PropertyInfo\PropertyInfoExtractorInterface;
@@ -196,13 +196,13 @@ public function register(): void
196196
$this->mergeConfigFrom(__DIR__.'/config/api-platform.php', 'api-platform');
197197

198198
$this->app->singleton(PropertyInfoExtractorInterface::class, function () {
199-
$phpstanExtractor = class_exists(PhpDocParser::class) ? new PhpStanExtractor() : null;
199+
$phpDocExtractor = class_exists(DocBlockFactory::class) ? new PhpDocExtractor() : null;
200200
$reflectionExtractor = new ReflectionExtractor();
201201

202202
return new PropertyInfoExtractor(
203203
[$reflectionExtractor],
204-
$phpstanExtractor ? [$phpstanExtractor, $reflectionExtractor] : [$reflectionExtractor],
205-
[],
204+
$phpDocExtractor ? [$phpDocExtractor, $reflectionExtractor] : [$reflectionExtractor],
205+
$phpDocExtractor ? [$phpDocExtractor] : [],
206206
[$reflectionExtractor],
207207
[$reflectionExtractor]
208208
);

src/Laravel/composer.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,17 @@
4848
"illuminate/support": "^11.0 || ^12.0",
4949
"illuminate/container": "^11.0 || ^12.0",
5050
"symfony/web-link": "^6.4 || ^7.1",
51-
"willdurand/negotiation": "^3.1"
51+
"willdurand/negotiation": "^3.1",
52+
"phpstan/phpdoc-parser": "^1.29 || ^2.0",
53+
"phpdocumentor/reflection-docblock": "^5.1"
5254
},
5355
"require-dev": {
54-
"api-platform/graphql": "^4.1",
5556
"doctrine/dbal": "^4.0",
5657
"larastan/larastan": "^2.0 || ^3.0",
57-
"laravel/sanctum": "^4.0",
5858
"orchestra/testbench": "^9.1",
59-
"phpdocumentor/type-resolver": "^1.7",
60-
"phpstan/phpdoc-parser": "^1.29 || ^2.0",
61-
"phpunit/phpunit": "11.5.x-dev"
59+
"phpunit/phpunit": "11.5.x-dev",
60+
"api-platform/graphql": "^4.1",
61+
"laravel/sanctum": "^4.0"
6262
},
6363
"autoload": {
6464
"psr-4": {
@@ -74,7 +74,7 @@
7474
},
7575
"suggest": {
7676
"api-platform/graphql": "Enable GraphQl support.",
77-
"phpstan/phpdoc-parser": "To support extracting metadata from PHPDoc."
77+
"phpdocumentor/reflection-docblock": ""
7878
},
7979
"extra": {
8080
"laravel": {

0 commit comments

Comments
 (0)