This repository has been archived by the owner on Apr 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### Added - Initial implementation of ulrack/transaction - `Ulrack\Transaction\Common\RequestInterface` - `Ulrack\Transaction\Common\ResponseInterface` - `Ulrack\Transaction\Transaction\Request` - `Ulrack\Transaction\Transaction\Response` - `Ulrack\Transaction\Exception\HeaderNotFoundException` - Unit Tests
- Loading branch information
1 parent
0b60a55
commit 8acde64
Showing
11 changed files
with
663 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/tests export-ignore | ||
/.gitignore export-ignore | ||
/.travis.yml export-ignore | ||
/phpunit.xml export-ignore | ||
/phpcs.xml export-ignore | ||
/PULL_REQUEST_TEMPLATE.md export-ignore | ||
/CODE_OF_CONDUCT.md export-ignore | ||
/CONTRIBUTING.md export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Changelog | ||
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). | ||
|
||
## 1.0.0 - 2019-03-05 | ||
### Added | ||
- Initial implementation of ulrack/transaction | ||
- `Ulrack\Transaction\Common\RequestInterface` | ||
- `Ulrack\Transaction\Common\ResponseInterface` | ||
- `Ulrack\Transaction\Transaction\Request` | ||
- `Ulrack\Transaction\Transaction\Response` | ||
- `Ulrack\Transaction\Exception\HeaderNotFoundException` | ||
- Unit Tests | ||
|
||
### Changed | ||
- Nothing | ||
|
||
### Deprecated | ||
- Nothing | ||
|
||
### Removed | ||
- Nothing | ||
|
||
### Fixed | ||
- Nothing | ||
|
||
### Security | ||
- Nothing | ||
|
||
[Unreleased]: https://github.com/ulrack/transaction/compare/1.0.0...HEAD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
[![Build Status](https://travis-ci.com/ulrack/transaction.svg?branch=master)](https://travis-ci.com/ulrack/transaction) | ||
|
||
# Ulrack Transaction | ||
|
||
Ulrack Transaction offers standard objects for requests and responses. | ||
These objects can be used to standardize transactions between systems. | ||
Both the `Request` and `Response` objects are build to be immutable after construction. | ||
|
||
## Installation | ||
|
||
To install the package run the following command: | ||
|
||
``` | ||
composer require ulrack/transaction | ||
``` | ||
|
||
## Usage | ||
|
||
### Request | ||
|
||
The implementation of a `\Ulrack\Transaction\Common\RequestInterface` is provided | ||
in `\Ulrack\Transaction\Transaction\Request`. | ||
Requests expect their arguments in the constructor. | ||
|
||
The first 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 second argument expects a target for the request. | ||
In the case of a HTTP request this would the URI for the request. | ||
|
||
The third 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 fourth argument is optional and expects an associative array with headers. | ||
|
||
The fifth argument is also optional and expects a `SearchCriteriaInterface` object. | ||
In the case of a HTTP GET request this would be cause the GET parameters to be filled. | ||
|
||
### Response | ||
|
||
The implementation of a `\Ulrack\Transaction\Common\ResponseInterface` is provided | ||
in `\Ulrack\Transaction\Transaction\Response`. | ||
|
||
The first parameter of a response object expects a boolean representing whether the request was success. | ||
|
||
The second parameter expects the body of the response which was received from the request. | ||
|
||
The third parameter expects an integer representing the status code of the response. | ||
|
||
The fourth parameter is optional and expects an associative array of response headers. | ||
|
||
## Change log | ||
|
||
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. | ||
|
||
## Contributing | ||
|
||
Please see [CONTRIBUTING](CONTRIBUTING.md) and [CODE_OF_CONDUCT](CODE_OF_CONDUCT.md) for details. | ||
|
||
## MIT License | ||
|
||
Copyright (c) 2019 Jyxon | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{ | ||
"name": "ulrack/transaction", | ||
"description": "Transactions from Ulrack.", | ||
"keywords": ["transaction", "http"], | ||
"type": "library", | ||
"license": "MIT", | ||
"prefer-stable": true, | ||
"minimum-stability": "stable", | ||
"require": { | ||
"php": "^7.2", | ||
"ulrack/search": "^1.0" | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "Ulrack", | ||
"homepage": "https://www.ulrack.com/", | ||
"role": "Developer" | ||
} | ||
], | ||
"config": { | ||
"sort-packages": true | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Ulrack\\Transaction\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Ulrack\\Transaction\\Tests\\": "tests/" | ||
} | ||
}, | ||
"archive": { | ||
"exclude": [ | ||
"/tests", | ||
"/.gitignore", | ||
"/.travis.yml", | ||
"/phpunit.xml", | ||
"/phpcs.xml", | ||
"/PULL_REQUEST_TEMPLATE.md", | ||
"/CODE_OF_CONDUCT.md", | ||
"/CONTRIBUTING.md" | ||
] | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^8.0", | ||
"squizlabs/php_codesniffer": "^3.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
/** | ||
* Copyright (C) Jyxon, Inc. All rights reserved. | ||
* See LICENSE for license details. | ||
*/ | ||
|
||
namespace Ulrack\Transaction\Common; | ||
|
||
use Ulrack\Search\Common\SearchCriteriaInterface; | ||
|
||
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. | ||
* | ||
* @return string | ||
*/ | ||
public function getMethod(): string; | ||
|
||
/** | ||
* Retrieves the request headers. | ||
* | ||
* @return string[]|null | ||
*/ | ||
public function getHeaders(): ?array; | ||
|
||
/** | ||
* Retrieves a header by its' name. | ||
* | ||
* @param string $name | ||
* | ||
* @return string | ||
*/ | ||
public function getHeader(string $name): string; | ||
|
||
/** | ||
* Retrieves the target of the request. | ||
* | ||
* @return string | ||
*/ | ||
public function getTarget(): string; | ||
|
||
/** | ||
* Retrieves the payload of the request. | ||
* | ||
* @return mixed | ||
*/ | ||
public function getPayload(); | ||
|
||
/** | ||
* Retrieves the search criteria for the request. | ||
* | ||
* @return SearchCriteriaInterface|null | ||
*/ | ||
public function getSearchCriteria(): ?SearchCriteriaInterface; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
/** | ||
* Copyright (C) Jyxon, Inc. All rights reserved. | ||
* See LICENSE for license details. | ||
*/ | ||
|
||
namespace Ulrack\Transaction\Common; | ||
|
||
interface ResponseInterface | ||
{ | ||
/** | ||
* Determines if the request was a success. | ||
* | ||
* @return bool | ||
*/ | ||
public function isSuccess(): bool; | ||
|
||
/** | ||
* Retrieves the body of the response. | ||
* | ||
* @return mixed | ||
*/ | ||
public function getBody(); | ||
|
||
/** | ||
* Retrieves the status code of the response. | ||
* | ||
* @return int | ||
*/ | ||
public function getStatusCode(): int; | ||
|
||
/** | ||
* Retrieves the response headers. | ||
* | ||
* @return string[]|null | ||
*/ | ||
public function getHeaders(): ?array; | ||
|
||
/** | ||
* Retrieves a header by its' name. | ||
* | ||
* @param string $name | ||
* | ||
* @return string | ||
*/ | ||
public function getHeader(string $name): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
/** | ||
* Copyright (C) Jyxon, Inc. All rights reserved. | ||
* See LICENSE for license details. | ||
*/ | ||
|
||
namespace Ulrack\Transaction\Exception; | ||
|
||
use Exception; | ||
|
||
class HeaderNotFoundException extends Exception | ||
{ | ||
/** | ||
* Constructor | ||
* | ||
* @param string $name | ||
*/ | ||
public function __construct(string $name) | ||
{ | ||
parent::__construct( | ||
sprintf( | ||
'Header with name "%s" could not be found.', | ||
$name | ||
) | ||
); | ||
} | ||
} |
Oops, something went wrong.