mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-29 00:25:17 +03:00
Adds support for the multipart/form-data content type
This commit is contained in:
parent
ddc3a01f09
commit
750ce383ec
@ -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