Skip to content
This repository has been archived by the owner on Apr 3, 2021. It is now read-only.

Commit

Permalink
Implemented enum for request methods
Browse files Browse the repository at this point in the history
Changed the order of parameters for the request object constructor

Removed the method definitions in the request interface
  • Loading branch information
mfrankruijter committed May 16, 2019
1 parent 5d5bbfd commit 6e5ce42
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 70 deletions.
25 changes: 22 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 3.0.0 - 2019-05-16
### Added
- MethodEnum to make a more strict definition of the available methods.

### Changed
- Order of parameters for the Request object constructor.

### Deprecated
- Nothing

### Removed
- RequestInterface method definitions.

### Fixed
- Nothing

### Security
- Nothing

## 2.0.0 - 2019-03-22
### Added
- Added parameters to the Request interface and implementation.
Expand All @@ -24,7 +43,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Security
- Nothing


## 1.0.0 - 2019-03-05
### Added
- Initial implementation of ulrack/transaction
Expand All @@ -50,5 +68,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Security
- Nothing

[Unreleased]: https://github.com/ulrack/transaction/compare/2.0.0...HEAD
[1.0.0]: https://github.com/ulrack/transaction/compare/1.0.0...2.0.0
[Unreleased]: https://github.com/ulrack/transaction/compare/3.0.0...HEAD
[3.0.0]: https://github.com/ulrack/transaction/compare/2.0.0...3.0.0
[2.0.0]: https://github.com/ulrack/transaction/compare/1.0.0...2.0.0
27 changes: 13 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,23 @@ The implementation of a `\Ulrack\Transaction\Common\RequestInterface` is provide
in `\Ulrack\Transaction\Transaction\Request`.
Requests expect their arguments in the constructor.


The first argument expects a target for the request.
The first argument expects a method. This method can be picked from the
`\Ulrack\Transaction\Common\MethodEnum` and should be one of:
- `MethodEnum::GET()`
- `MethodEnum::POST()`
- `MethodEnum::PUT()`
- `MethodEnum::PATCH()`
- `MethodEnum::DELETE()`

The second argument expects a target for the request.
In the case of a HTTP request this would the URI for the request.

The second argument is the payload of the request.
The payload would be the body of a request, in the case of a HTTP POST request, this would be the form data.

The third argument expects a method. This method can be picked from the
`\Ulrack\Transaction\Common\RequestInterface` and should be one of:
- `RequestInterface::METHOD_GET`
- `RequestInterface::METHOD_POST`
- `RequestInterface::METHOD_PUT`
- `RequestInterface::METHOD_PATCH`
- `RequestInterface::METHOD_DELETE`

The fourth argument is optional and expects an associative array with parameters.
The third argument is optional and expects an associative array with parameters.
In the case of a HTTP request, this expects the GET parameters.

The fourth argument is optional and expects the payload of the request.
The payload would be the body of a request, in the case of a HTTP POST request, this would be the form data.

The fifth argument is optional and expects an associative array with headers.

### Response
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"prefer-stable": true,
"minimum-stability": "stable",
"require": {
"php": "^7.2"
"php": "^7.2",
"ulrack/enum": "^1.0"
},
"authors": [
{
Expand Down
58 changes: 58 additions & 0 deletions src/Common/MethodEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
/**
* Copyright (C) Jyxon, Inc. All rights reserved.
* See LICENSE for license details.
*/
namespace Ulrack\Transaction\Common;

use Ulrack\Enum\Enum;

/**
* @method static MethodEnum GET()
* @method static MethodEnum POST()
* @method static MethodEnum PUT()
* @method static MethodEnum DELETE()
* @method static MethodEnum PATCH()
*/
class MethodEnum extends Enum
{
/**
* The request method GET.
* Retrieves information with a request.
*
* @var string
*/
const GET = 'get';

/**
* The request method POST.
* Creates new resources with a request.
*
* @var string
*/
const POST = 'post';

/**
* The request method PUT.
* Updates resource with a request.
*
* @var string
*/
const PUT = 'put';

/**
* The request method DELETE.
* Deletes a resource with a request.
*
* @var string
*/
const DELETE = 'delete';

/**
* The request method PATCH.
* Update a resource partially with a request.
*
* @var string
*/
const PATCH = 'patch';
}
40 changes: 0 additions & 40 deletions src/Common/RequestInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,6 @@

interface RequestInterface
{
/**
* The request method GET.
* Retrieves information with a request.
*
* @var string
*/
const METHOD_GET = 'get';

/**
* The request method POST.
* Creates new resources with a request.
*
* @var string
*/
const METHOD_POST = 'post';

/**
* The request method PUT.
* Updates resource with a request.
*
* @var string
*/
const METHOD_PUT = 'put';

/**
* The request method DELETE.
* Deletes a resource with a request.
*
* @var string
*/
const METHOD_DELETE = 'delete';

/**
* The request method PATCH.
* Update a resource partially with a request.
*
* @var string
*/
const METHOD_PATCH = 'patch';

/**
* Retrieves the method of the request.
*
Expand Down
15 changes: 8 additions & 7 deletions src/Transaction/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace Ulrack\Transaction\Transaction;

use Ulrack\Transaction\Common\RequestInterface;
use Ulrack\Transaction\Common\MethodEnum;
use Ulrack\Transaction\Exception\HeaderNotFoundException;

class Request implements RequestInterface
Expand All @@ -29,22 +30,22 @@ class Request implements RequestInterface
/**
* Constructor
*
* @param MethodEnum $method
* @param string $target
* @param array|null $parameters
* @param mixed $payload
* @param array $parameters
* @param string $method
* @param array|null $headers
*/
public function __construct(
MethodEnum $method,
string $target,
$payload,
string $method = RequestInterface::METHOD_GET,
array $headers = null,
array $parameters = null
array $parameters = null,
$payload = null,
array $headers = null
) {
$this->method = (string) $method;
$this->target = $target;
$this->payload = $payload;
$this->method = $method;
$this->headers = $headers;
$this->parameters = $parameters;
}
Expand Down
10 changes: 5 additions & 5 deletions tests/Transaction/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

use PHPUnit\Framework\TestCase;
use Ulrack\Transaction\Transaction\Request;
use Ulrack\Transaction\Common\RequestInterface;
use Ulrack\Transaction\Common\MethodEnum;
use Ulrack\Transaction\Exception\HeaderNotFoundException;

/**
Expand All @@ -31,15 +31,15 @@ class RequestTest extends TestCase
public function testRequest(): void
{
$subject = new Request(
MethodEnum::GET(),
'foo',
['foo' => 'bar'],
['bar' => 'baz'],
RequestInterface::METHOD_GET,
['baz' => 'qux'],
['foo' => 'bar']
['baz' => 'qux']
);

$this->assertInstanceOf(Request::class, $subject);
$this->assertEquals(RequestInterface::METHOD_GET, $subject->getMethod());
$this->assertEquals((string) MethodEnum::GET(), $subject->getMethod());
$this->assertEquals(['baz' => 'qux'], $subject->getHeaders());
$this->assertEquals('qux', $subject->getHeader('baz'));
$this->assertEquals('foo', $subject->getTarget());
Expand Down

0 comments on commit 6e5ce42

Please sign in to comment.