1 | <?php |
||
11 | class GraphQLMiddleware implements \Interop\Http\ServerMiddleware\MiddlewareInterface |
||
12 | { |
||
13 | /** |
||
14 | * @var string The graphql uri path to match against |
||
15 | */ |
||
16 | private $graphqlUri; |
||
17 | |||
18 | /** |
||
19 | * @var array The graphql headers |
||
20 | */ |
||
21 | private $graphql_headers = [ |
||
22 | "application/graphql" |
||
23 | ]; |
||
24 | |||
25 | /** |
||
26 | * @var array Allowed method for a graphql request, default GET, POST |
||
27 | */ |
||
28 | private $allowed_methods = [ |
||
29 | "GET", "POST" |
||
30 | ]; |
||
31 | |||
32 | /** |
||
33 | * @var Processor |
||
34 | */ |
||
35 | private $schema; |
||
36 | /** |
||
37 | * @var null |
||
38 | */ |
||
39 | private $rootUrl; |
||
40 | |||
41 | /** |
||
42 | * GraphQLMiddleware constructor. |
||
43 | * |
||
44 | * @param Schema $schema |
||
45 | * @param string $graphqlUri |
||
46 | */ |
||
47 | public function __construct(Schema $schema, $graphqlUri = '/graphql', $rootUrl = null) |
||
52 | |||
53 | /** |
||
54 | * Process an incoming server request and return a response, optionally delegating |
||
55 | * to the next middleware component to create the response. |
||
56 | * |
||
57 | * @param \Psr\Http\Message\ServerRequestInterface $request |
||
58 | * @param \Interop\Http\ServerMiddleware\DelegateInterface $delegate |
||
59 | * |
||
60 | * @return \Psr\Http\Message\ResponseInterface |
||
61 | */ |
||
62 | public function process(\Psr\Http\Message\ServerRequestInterface $request, \Interop\Http\ServerMiddleware\DelegateInterface $delegate) |
||
86 | |||
87 | private function isGraphQLRequest(ServerRequestInterface $request) |
||
91 | |||
92 | private function hasUri(ServerRequestInterface $request) |
||
96 | |||
97 | private function hasGraphQLHeader(ServerRequestInterface $request) |
||
115 | |||
116 | private function getPayload(ServerRequestInterface $request) |
||
130 | |||
131 | private function fromGet(ServerRequestInterface $request) |
||
143 | |||
144 | private function fromPost(ServerRequestInterface $request) |
||
176 | } |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: