Merge pull request #620 from KnifeLemon/patch-1

Added PUT, PATCH, DELETE methods for data
pull/625/head
n0nag0n 1 week ago committed by GitHub
commit 62bf542d12
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -211,6 +211,14 @@ class Request
$this->data->setData($data);
}
}
// Check PUT, PATCH, DELETE for application/x-www-form-urlencoded data
} else if (in_array($this->method, [ 'PUT', 'DELETE', 'PATCH' ], true) === true) {
$body = $this->getBody();
if ($body !== '') {
$data = [];
parse_str($body, $data);
$this->data->setData($data);
}
}
return $this;

@ -162,7 +162,8 @@ class RequestTest extends TestCase
'url' => '/vagrant/public/flightphp',
'base' => '/vagrant/public',
'query' => new Collection(),
'type' => ''
'type' => '',
'method' => 'GET'
]);
$this->assertEquals('/flightphp', $request->url);
}
@ -172,7 +173,8 @@ class RequestTest extends TestCase
$request = new Request([
'url' => '',
'base' => '/vagrant/public',
'type' => ''
'type' => '',
'method' => 'GET'
]);
$this->assertEquals('/', $request->url);
}
@ -183,7 +185,6 @@ class RequestTest extends TestCase
$tmpfile = tmpfile();
$stream_path = stream_get_meta_data($tmpfile)['uri'];
file_put_contents($stream_path, '{"foo":"bar"}');
$_SERVER['REQUEST_METHOD'] = 'POST';
$request = new Request([
'url' => '/something/fancy',
'base' => '/vagrant/public',
@ -191,12 +192,36 @@ class RequestTest extends TestCase
'length' => 13,
'data' => new Collection(),
'query' => new Collection(),
'stream_path' => $stream_path
'stream_path' => $stream_path,
'method' => 'POST'
]);
$this->assertEquals([ 'foo' => 'bar' ], $request->data->getData());
$this->assertEquals('{"foo":"bar"}', $request->getBody());
}
public function testInitWithFormBody()
{
// create dummy file to pull request body from
$tmpfile = tmpfile();
$stream_path = stream_get_meta_data($tmpfile)['uri'];
file_put_contents($stream_path, 'foo=bar&baz=qux');
$request = new Request([
'url' => '/something/fancy',
'base' => '/vagrant/public',
'type' => 'application/x-www-form-urlencoded',
'length' => 15,
'data' => new Collection(),
'query' => new Collection(),
'stream_path' => $stream_path,
'method' => 'PATCH'
]);
$this->assertEquals([
'foo' => 'bar',
'baz' => 'qux'
], $request->data->getData());
$this->assertEquals('foo=bar&baz=qux', $request->getBody());
}
public function testGetHeader()
{
$_SERVER['HTTP_X_CUSTOM_HEADER'] = 'custom header value';

Loading…
Cancel
Save