mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-22 12:56:05 +03:00
Adds support for the multipart/form-data content type
(cherry picked from commit 750ce38
)
This commit is contained in:
parent
47bcabfd7b
commit
c5b78c66e9
@ -71,6 +71,8 @@ class Helper
|
|||||||
}
|
}
|
||||||
} else if (stripos($contentType, 'application/x-www-form-urlencoded') !== false) {
|
} else if (stripos($contentType, 'application/x-www-form-urlencoded') !== false) {
|
||||||
$bodyParams = $_POST;
|
$bodyParams = $_POST;
|
||||||
|
} else if (stripos($contentType, 'multipart/form-data') !== false) {
|
||||||
|
$bodyParams = $_POST;
|
||||||
} else if (null === $contentType) {
|
} else if (null === $contentType) {
|
||||||
throw new RequestError('Missing "Content-Type" header');
|
throw new RequestError('Missing "Content-Type" header');
|
||||||
} else {
|
} else {
|
||||||
|
@ -69,6 +69,28 @@ class RequestParsingTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testParsesMultipartFormdataRequest()
|
||||||
|
{
|
||||||
|
$query = '{my query}';
|
||||||
|
$variables = ['test' => 1, 'test2' => 2];
|
||||||
|
$operation = 'op';
|
||||||
|
|
||||||
|
$post = [
|
||||||
|
'query' => $query,
|
||||||
|
'variables' => $variables,
|
||||||
|
'operationName' => $operation
|
||||||
|
];
|
||||||
|
$parsed = [
|
||||||
|
'raw' => $this->parseRawMultipartFormdataRequest($post),
|
||||||
|
'psr' => $this->parsePsrMultipartFormdataRequest($post)
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($parsed as $method => $parsedBody) {
|
||||||
|
$this->assertValidOperationParams($parsedBody, $query, null, $variables, $operation, $method);
|
||||||
|
$this->assertFalse($parsedBody->isReadOnly(), $method);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function testParsesJSONRequest()
|
public function testParsesJSONRequest()
|
||||||
{
|
{
|
||||||
$query = '{my query}';
|
$query = '{my query}';
|
||||||
@ -327,6 +349,37 @@ class RequestParsingTest extends \PHPUnit_Framework_TestCase
|
|||||||
return $helper->parsePsrRequest($psrRequest);
|
return $helper->parsePsrRequest($psrRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $postValue
|
||||||
|
* @return OperationParams|OperationParams[]
|
||||||
|
*/
|
||||||
|
private function parseRawMultipartFormDataRequest($postValue)
|
||||||
|
{
|
||||||
|
$_SERVER['CONTENT_TYPE'] = 'multipart/form-data; boundary=----FormBoundary';
|
||||||
|
$_SERVER['REQUEST_METHOD'] = 'POST';
|
||||||
|
$_POST = $postValue;
|
||||||
|
|
||||||
|
$helper = new Helper();
|
||||||
|
return $helper->parseHttpRequest(function() {
|
||||||
|
throw new InvariantViolation("Shouldn't read from php://input for multipart/form-data request");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $postValue
|
||||||
|
* @return array|Helper
|
||||||
|
*/
|
||||||
|
private function parsePsrMultipartFormDataRequest($postValue)
|
||||||
|
{
|
||||||
|
$psrRequest = new PsrRequestStub();
|
||||||
|
$psrRequest->headers['content-type'] = ['multipart/form-data; boundary=----FormBoundary'];
|
||||||
|
$psrRequest->method = 'POST';
|
||||||
|
$psrRequest->parsedBody = $postValue;
|
||||||
|
|
||||||
|
$helper = new Helper();
|
||||||
|
return $helper->parsePsrRequest($psrRequest);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $getValue
|
* @param $getValue
|
||||||
* @return OperationParams
|
* @return OperationParams
|
||||||
|
Loading…
Reference in New Issue
Block a user