Skip to content

Commit bf9d9c8

Browse files
authored
Merge pull request #4471 from alanpoulain/merge-2.6
2 parents 1d6444f + 1d3e618 commit bf9d9c8

File tree

8 files changed

+29
-20
lines changed

8 files changed

+29
-20
lines changed

src/Core/Bridge/Symfony/Bundle/Resources/config/graphql.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,15 @@
235235
<argument type="service" id="api_platform.router" />
236236
<argument>%api_platform.graphql.graphiql.enabled%</argument>
237237
<argument>%api_platform.title%</argument>
238+
<argument>%api_platform.asset_package%</argument>
238239
</service>
239240

240241
<service id="api_platform.graphql.action.graphql_playground" class="ApiPlatform\GraphQl\Action\GraphQlPlaygroundAction" public="true">
241242
<argument type="service" id="twig" />
242243
<argument type="service" id="api_platform.router" />
243244
<argument>%api_platform.graphql.graphql_playground.enabled%</argument>
244245
<argument>%api_platform.title%</argument>
246+
<argument>%api_platform.asset_package%</argument>
245247
</service>
246248

247249
<!-- Error -->

src/Core/Bridge/Symfony/Bundle/Resources/views/GraphQlPlayground/index.html.twig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
<meta name="viewport" content="user-scalable=no, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, minimal-ui">
66
<title>{% if title %}{{ title }} - {% endif %}API Platform</title>
77

8-
<link rel="stylesheet" href="{{ asset('bundles/apiplatform/graphql-playground/index.css') }}">
8+
<link rel="stylesheet" href="{{ asset('bundles/apiplatform/graphql-playground/index.css', assetPackage) }}">
99

10-
<script src="{{ asset('bundles/apiplatform/graphql-playground/middleware.js') }}"></script>
10+
<script src="{{ asset('bundles/apiplatform/graphql-playground/middleware.js', assetPackage) }}"></script>
1111
{# json_encode(65) is for JSON_UNESCAPED_SLASHES|JSON_HEX_TAG to avoid JS XSS #}
1212
<script id="graphql-playground-data" type="application/json">{{ graphql_playground_data|json_encode(65)|raw }}</script>
1313
</head>
@@ -522,7 +522,7 @@
522522

523523
<div id="graphql-playground" />
524524

525-
<script src="{{ asset('bundles/apiplatform/init-graphql-playground.js') }}"></script>
525+
<script src="{{ asset('bundles/apiplatform/init-graphql-playground.js', assetPackage) }}"></script>
526526

527527
</body>
528528
</html>

src/Core/Bridge/Symfony/Bundle/Resources/views/Graphiql/index.html.twig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
<meta charset="UTF-8">
55
<title>{% if title %}{{ title }} - {% endif %}API Platform</title>
66

7-
<link rel="stylesheet" href="{{ asset('bundles/apiplatform/graphiql/graphiql.css') }}">
8-
<link rel="stylesheet" href="{{ asset('bundles/apiplatform/graphiql-style.css') }}">
7+
<link rel="stylesheet" href="{{ asset('bundles/apiplatform/graphiql/graphiql.css', assetPackage) }}">
8+
<link rel="stylesheet" href="{{ asset('bundles/apiplatform/graphiql-style.css', assetPackage) }}">
99

1010
{# json_encode(65) is for JSON_UNESCAPED_SLASHES|JSON_HEX_TAG to avoid JS XSS #}
1111
<script id="graphiql-data" type="application/json">{{ graphiql_data|json_encode(65)|raw }}</script>
@@ -14,10 +14,10 @@
1414
<body>
1515
<div id="graphiql">Loading...</div>
1616

17-
<script src="{{ asset('bundles/apiplatform/react/react.production.min.js') }}"></script>
18-
<script src="{{ asset('bundles/apiplatform/react/react-dom.production.min.js') }}"></script>
19-
<script src="{{ asset('bundles/apiplatform/graphiql/graphiql.min.js') }}"></script>
20-
<script src="{{ asset('bundles/apiplatform/init-graphiql.js') }}"></script>
17+
<script src="{{ asset('bundles/apiplatform/react/react.production.min.js', assetPackage) }}"></script>
18+
<script src="{{ asset('bundles/apiplatform/react/react-dom.production.min.js', assetPackage) }}"></script>
19+
<script src="{{ asset('bundles/apiplatform/graphiql/graphiql.min.js', assetPackage) }}"></script>
20+
<script src="{{ asset('bundles/apiplatform/init-graphiql.js', assetPackage) }}"></script>
2121

2222
</body>
2323
</html>

src/Core/Bridge/Symfony/Bundle/Resources/views/SwaggerUi/index.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
<title>{% if title %}{{ title }} - {% endif %}API Platform</title>
66

77
{% block stylesheet %}
8-
<link rel="stylesheet" href="{{ asset('bundles/apiplatform/fonts/open-sans/400.css') }}">
9-
<link rel="stylesheet" href="{{ asset('bundles/apiplatform/fonts/open-sans/700.css') }}">
8+
<link rel="stylesheet" href="{{ asset('bundles/apiplatform/fonts/open-sans/400.css', assetPackage) }}">
9+
<link rel="stylesheet" href="{{ asset('bundles/apiplatform/fonts/open-sans/700.css', assetPackage) }}">
1010
<link rel="stylesheet" href="{{ asset('bundles/apiplatform/swagger-ui/swagger-ui.css', assetPackage) }}">
1111
<link rel="stylesheet" href="{{ asset('bundles/apiplatform/style.css', assetPackage) }}">
1212
{% endblock %}

src/Core/Bridge/Symfony/Bundle/Test/Client.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,10 @@ public function request(string $method, string $url, array $options = []): Respo
9393

9494
// Convert headers to a $_SERVER-like array
9595
foreach (self::extractHeaders($options) as $key => $value) {
96-
if ('content-type' === $key) {
97-
$server['CONTENT_TYPE'] = $value[0] ?? '';
98-
99-
continue;
100-
}
101-
96+
$normalizedHeaderName = strtoupper(str_replace('-', '_', $key));
97+
$header = \in_array($normalizedHeaderName, ['CONTENT_TYPE', 'REMOTE_ADDR'], true) ? $normalizedHeaderName : sprintf('HTTP_%s', $normalizedHeaderName);
10298
// BrowserKit doesn't support setting several headers with the same name
103-
$server['HTTP_'.strtoupper(str_replace('-', '_', $key))] = $value[0] ?? '';
99+
$server[$header] = $value[0] ?? '';
104100
}
105101

106102
if ($basic) {

src/GraphQl/Action/GraphQlPlaygroundAction.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@ final class GraphQlPlaygroundAction
3232
private $router;
3333
private $graphQlPlaygroundEnabled;
3434
private $title;
35+
private $assetPackage;
3536

36-
public function __construct(TwigEnvironment $twig, RouterInterface $router, bool $graphQlPlaygroundEnabled = false, string $title = '')
37+
public function __construct(TwigEnvironment $twig, RouterInterface $router, bool $graphQlPlaygroundEnabled = false, string $title = '', $assetPackage = null)
3738
{
3839
$this->twig = $twig;
3940
$this->router = $router;
4041
$this->graphQlPlaygroundEnabled = $graphQlPlaygroundEnabled;
4142
$this->title = $title;
43+
$this->assetPackage = $assetPackage;
4244
}
4345

4446
public function __invoke(Request $request): Response
@@ -47,6 +49,7 @@ public function __invoke(Request $request): Response
4749
return new Response($this->twig->render('@ApiPlatform/GraphQlPlayground/index.html.twig', [
4850
'title' => $this->title,
4951
'graphql_playground_data' => ['entrypoint' => $this->router->generate('api_graphql_entrypoint')],
52+
'assetPackage' => $this->assetPackage,
5053
]));
5154
}
5255

src/GraphQl/Action/GraphiQlAction.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@ final class GraphiQlAction
3232
private $router;
3333
private $graphiqlEnabled;
3434
private $title;
35+
private $assetPackage;
3536

36-
public function __construct(TwigEnvironment $twig, RouterInterface $router, bool $graphiqlEnabled = false, string $title = '')
37+
public function __construct(TwigEnvironment $twig, RouterInterface $router, bool $graphiqlEnabled = false, string $title = '', $assetPackage = null)
3738
{
3839
$this->twig = $twig;
3940
$this->router = $router;
4041
$this->graphiqlEnabled = $graphiqlEnabled;
4142
$this->title = $title;
43+
$this->assetPackage = $assetPackage;
4244
}
4345

4446
public function __invoke(Request $request): Response
@@ -47,6 +49,7 @@ public function __invoke(Request $request): Response
4749
return new Response($this->twig->render('@ApiPlatform/Graphiql/index.html.twig', [
4850
'title' => $this->title,
4951
'graphiql_data' => ['entrypoint' => $this->router->generate('api_graphql_entrypoint')],
52+
'assetPackage' => $this->assetPackage,
5053
]));
5154
}
5255

tests/Core/Bridge/Symfony/Bundle/Test/ClientTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,15 @@ public function testCustomHeader(): void
6161
$response = $client->request('POST', '/dummies', [
6262
'headers' => [
6363
'content-type' => 'application/json',
64+
'remote-addr' => '10.10.10.10',
6465
'accept' => 'text/xml',
6566
],
6667
'body' => '{"name": "Kevin"}',
6768
]);
69+
$server = $client->getKernelBrowser()->getInternalRequest()->getServer();
70+
$this->assertSame('application/json', $server['CONTENT_TYPE']);
71+
$this->assertSame('10.10.10.10', $server['REMOTE_ADDR']);
72+
$this->assertSame('text/xml', $server['HTTP_ACCEPT']);
6873
$this->assertSame('application/xml; charset=utf-8', $response->getHeaders()['content-type'][0]);
6974
$this->assertResponseHeaderSame('content-type', 'application/xml; charset=utf-8');
7075
$this->assertStringContainsString('<name>Kevin</name>', $response->getContent());

0 commit comments

Comments
 (0)