Skip to content

Commit

Permalink
allow body in DELETE requests
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianheuer committed Jan 19, 2017
1 parent a5eb40e commit fc96a9a
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 6 deletions.
18 changes: 14 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

All notable changes are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles.

## [1.0.0] - 2016-12-22
## [2.1.0] - 2017-01-19

Initial Release
### Changed

## [Unreleased]
* Allow body in `DELETE` requests

## [2.0.0] - 2017-01-17

### Changed

Expand All @@ -16,5 +18,13 @@ Initial Release

* `PhpObjectContent` has been added to allow sending a response containing a serialised PHP object

[Unreleased]: https://github.com/kartenmacherei/rest-framework/compare/1.0.0...HEAD
## [1.0.0] - 2016-12-22

Initial Release

## [Unreleased]

[Unreleased]: https://github.com/kartenmacherei/rest-framework/compare/2.1.0...HEAD
[1.0.0]: https://github.com/kartenmacherei/rest-framework/releases/tag/1.0.0
[2.0.0]: https://github.com/kartenmacherei/rest-framework/releases/tag/2.0.0
[2.1.0]: https://github.com/kartenmacherei/rest-framework/releases/tag/2.1.0
57 changes: 56 additions & 1 deletion src/Request/DeleteRequest.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,66 @@
<?php
namespace Kartenmacherei\RestFramework\Request;

use Kartenmacherei\RestFramework\Request\Body\Body;
use Kartenmacherei\RestFramework\Request\Header\HeaderCollection;
use Kartenmacherei\RestFramework\Request\Method\DeleteRequestMethod;
use Kartenmacherei\RestFramework\Request\Method\RequestMethod;

class DeleteRequest extends GetRequest
class DeleteRequest extends Request
{
/**
* @var array
*/
private $parameters;

/**
* @var Body
*/
private $body;

/**
* @param Uri $uri
* @param HeaderCollection $headers
* @param array $parameters
* @param Body $body
*/
public function __construct(Uri $uri, HeaderCollection $headers, array $parameters, Body $body)
{
parent::__construct($uri, $headers);
$this->parameters = $parameters;
$this->body = $body;
}

/**
* @param $name
* @return bool
*/
public function hasParameter($name): bool
{
return array_key_exists($name, $this->parameters);
}

/**
* @param $name
* @return mixed
* @throws RequestParameterException
*/
public function getParameter($name)
{
if (!$this->hasParameter($name)) {
throw new RequestParameterException(sprintf('Parameter %s not found'));
}
return $this->parameters[$name];
}

/**
* @return Body
*/
public function getBody(): Body
{
return $this->body;
}

/**
* @return RequestMethod
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Request/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static function fromSuperGlobals(): Request
case RequestMethod::OPTIONS:
return new OptionsRequest($uri, $headers);
case RequestMethod::DELETE:
return new DeleteRequest($uri, $headers, $_GET);
return new DeleteRequest($uri, $headers, $_GET, $body);
case RequestMethod::GET:
return new GetRequest($uri, $headers, $_GET);
case RequestMethod::PATCH:
Expand Down
1 change: 1 addition & 0 deletions tests/Unit/Request/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

/**
* @covers \Kartenmacherei\RestFramework\Request\Request
* @covers \Kartenmacherei\RestFramework\Request\DeleteRequest
* @covers \Kartenmacherei\RestFramework\Request\GetRequest
* @covers \Kartenmacherei\RestFramework\Request\PostRequest
* @covers \Kartenmacherei\RestFramework\Request\Uri
Expand Down

0 comments on commit fc96a9a

Please sign in to comment.