1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license GPLv3, http://www.gnu.org/copyleft/gpl.html |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2022 |
6
|
|
|
* @package TYPO3 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
namespace Aimeos\Aimeos\Controller; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
use Nyholm\Psr7\Factory\Psr17Factory; |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Controller for the GraphQL API |
18
|
|
|
* |
19
|
|
|
* @package TYPO3 |
20
|
|
|
*/ |
21
|
|
|
class GraphqlController extends AbstractController |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* Creates a new resource object or a list of resource objects |
25
|
|
|
* |
26
|
|
|
* @return \Psr\Http\Message\ResponseInterface Response object containing the generated output |
27
|
|
|
*/ |
28
|
|
|
public function indexAction() |
29
|
|
|
{ |
30
|
|
|
return \Aimeos\Admin\Graphql::execute($this->contextBackend(''), $this->getPsrRequest()); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Returns a PSR-7 request object for the current request |
36
|
|
|
* |
37
|
|
|
* @return \Psr\Http\Message\RequestInterface PSR-7 request object |
38
|
|
|
*/ |
39
|
|
|
protected function getPsrRequest() : \Psr\Http\Message\RequestInterface |
40
|
|
|
{ |
41
|
|
|
$psr17Factory = new \Nyholm\Psr7\Factory\Psr17Factory(); |
42
|
|
|
|
43
|
|
|
$creator = new \Nyholm\Psr7Server\ServerRequestCreator( |
44
|
|
|
$psr17Factory, // ServerRequestFactory |
45
|
|
|
$psr17Factory, // UriFactory |
46
|
|
|
$psr17Factory, // UploadedFileFactory |
47
|
|
|
$psr17Factory // StreamFactory |
48
|
|
|
); |
49
|
|
|
|
50
|
|
|
return $creator->fromGlobals(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Set the response data from a PSR-7 response object and returns the message content |
56
|
|
|
* |
57
|
|
|
* @param \Psr\Http\Message\ResponseInterface $response PSR-7 response object |
58
|
|
|
* @return string Generated output |
59
|
|
|
*/ |
60
|
|
|
protected function setPsrResponse(\Psr\Http\Message\ResponseInterface $response) |
61
|
|
|
{ |
62
|
|
|
if (!isset($this->responseFactory)) // TYPO3 10 |
63
|
|
|
{ |
64
|
|
|
$this->response->setStatus($response->getStatusCode()); |
|
|
|
|
65
|
|
|
|
66
|
|
|
foreach ($response->getHeaders() as $key => $value) { |
67
|
|
|
foreach ((array) $value as $val) { |
68
|
|
|
$this->response->setHeader($key, $val); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return (string) $response->getBody(); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
return $response; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|