-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1a9b75b
Showing
15 changed files
with
399 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,15 @@ | ||
; This file is for unifying the coding style for different editors and IDEs. | ||
; More information at http://editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
indent_size = 4 | ||
indent_style = space | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
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,9 @@ | ||
* text=auto eol=lf | ||
|
||
/tests export-ignore | ||
.editorconfig export-ignore | ||
.gitattributes export-ignore | ||
.gitignore export-ignore | ||
.travis.yml export-ignore | ||
phpunit.xml export-ignore | ||
phpcs.xml 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,2 @@ | ||
vendor | ||
composer.lock |
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,14 @@ | ||
language: php | ||
sudo: false | ||
|
||
php: | ||
- 5.6 | ||
- 7.0 | ||
- 7.1 | ||
|
||
before_script: | ||
- composer self-update | ||
- composer install -n | ||
|
||
script: | ||
- composer test |
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,11 @@ | ||
# Change Log | ||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](http://keepachangelog.com/) | ||
and this project adheres to [Semantic Versioning](http://semver.org/). | ||
|
||
## 0.1 - 2016-09-30 | ||
|
||
### Added | ||
* Response factory | ||
* Stream factory |
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 @@ | ||
# Contributing Guide | ||
|
||
This project adheres to [The Code Manifesto](http://codemanifesto.com) as its guidelines for contributor interactions. | ||
|
||
## The Code Manifesto | ||
|
||
We want to work in an ecosystem that empowers developers to reach their potential--one that encourages growth and effective collaboration. A space that is safe for all. | ||
|
||
A space such as this benefits everyone that participates in it. It encourages new developers to enter our field. It is through discussion and collaboration that we grow, and through growth that we improve. | ||
|
||
In the effort to create such a place, we hold to these values: | ||
|
||
1. **Discrimination limits us.** This includes discrimination on the basis of race, gender, sexual orientation, gender identity, age, nationality, technology and any other arbitrary exclusion of a group of people. | ||
2. **Boundaries honor us.** Your comfort levels are not everyone’s comfort levels. Remember that, and if brought to your attention, heed it. | ||
3. **We are our biggest assets.** None of us were born masters of our trade. Each of us has been helped along the way. Return that favor, when and where you can. | ||
4. **We are resources for the future.** As an extension of #3, share what you know. Make yourself a resource to help those that come after you. | ||
5. **Respect defines us.** Treat others as you wish to be treated. Make your discussions, criticisms and debates from a position of respectfulness. Ask yourself, is it true? Is it necessary? Is it constructive? Anything less is unacceptable. | ||
6. **Reactions require grace.** Angry responses are valid, but abusive language and vindictive actions are toxic. When something happens that offends you, handle it assertively, but be respectful. Escalate reasonably, and try to allow the offender an opportunity to explain themselves, and possibly correct the issue. | ||
7. **Opinions are just that: opinions.** Each and every one of us, due to our background and upbringing, have varying opinions. That is perfectly acceptable. Remember this: if you respect your own opinions, you should respect the opinions of others. | ||
8. **To err is human.** You might not intend it, but mistakes do happen and contribute to build experience. Tolerate honest mistakes, and don't hesitate to apologize if you make one yourself. | ||
|
||
## How to contribute | ||
|
||
This is a collaborative effort. We welcome all contributions submitted as pull requests. | ||
|
||
(Contributions on wording & style are also welcome.) | ||
|
||
### Bugs | ||
|
||
A bug is a demonstrable problem that is caused by the code in the repository. Good bug reports are extremely helpful – thank you! | ||
|
||
Please try to be as detailed as possible in your report. Include specific information about the environment – version of PHP, etc, and steps required to reproduce the issue. | ||
|
||
### Pull Requests | ||
|
||
Good pull requests – patches, improvements, new features – are a fantastic help. Before create a pull request, please follow these instructions: | ||
|
||
* The code must follow the [PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md). Run `composer cs-fix` to fix your code before commit. | ||
* Write tests | ||
* Document any change in `README.md` and `CHANGELOG.md` | ||
* One pull request per feature. If you want to do more than one thing, send multiple pull request | ||
|
||
### Runing tests | ||
|
||
```sh | ||
composer test | ||
``` |
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,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2016 | ||
|
||
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,29 @@ | ||
# middlewares/utils | ||
|
||
[![Latest Version on Packagist][ico-version]][link-packagist] | ||
[![Software License][ico-license]](LICENSE.md) | ||
[![Build Status][ico-travis]][link-travis] | ||
[![Quality Score][ico-scrutinizer]][link-scrutinizer] | ||
[![Total Downloads][ico-downloads]][link-downloads] | ||
[![SensioLabs Insight][ico-sensiolabs]][link-sensiolabs] | ||
|
||
Common utils used by the middlewares' packages | ||
|
||
--- | ||
|
||
Please see [CHANGELOG](CHANGELOG.md) for more information about recent changes and [CONTRIBUTING](CONTRIBUTING.md) for contributing details. | ||
|
||
The MIT License (MIT). Please see [LICENSE](LICENSE) for more information. | ||
|
||
[ico-version]: https://img.shields.io/packagist/v/middlewares/utils.svg?style=flat-square | ||
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square | ||
[ico-travis]: https://img.shields.io/travis/middlewares/utils/master.svg?style=flat-square | ||
[ico-scrutinizer]: https://img.shields.io/scrutinizer/g/middlewares/utils.svg?style=flat-square | ||
[ico-downloads]: https://img.shields.io/packagist/dt/middlewares/utils.svg?style=flat-square | ||
[ico-sensiolabs]: https://img.shields.io/sensiolabs/i/36786f5a-2a15-4399-8817-8f24fcd8c0b4.svg?style=flat-square | ||
|
||
[link-packagist]: https://packagist.org/packages/middlewares/utils | ||
[link-travis]: https://travis-ci.org/middlewares/utils | ||
[link-scrutinizer]: https://scrutinizer-ci.com/g/middlewares/utils | ||
[link-downloads]: https://packagist.org/packages/middlewares/utils | ||
[link-sensiolabs]: https://insight.sensiolabs.com/projects/36786f5a-2a15-4399-8817-8f24fcd8c0b4 |
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,44 @@ | ||
{ | ||
"name": "middlewares/utils", | ||
"type": "library", | ||
"description": "Common utils to create PSR-15 middleware packages", | ||
"license": "MIT", | ||
"keywords": [ | ||
"psr-7", | ||
"psr-15", | ||
"middleware", | ||
"http" | ||
], | ||
"homepage": "https://github.com/middlewares/utils", | ||
"support": { | ||
"issues": "https://github.com/middlewares/utils/issues" | ||
}, | ||
"require": { | ||
"php": "^5.6 || ^7.0", | ||
"psr/http-message": "~1.0", | ||
"http-interop/http-factory": "^0.1.0" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^5.5", | ||
"zendframework/zend-diactoros": "^1.3", | ||
"friendsofphp/php-cs-fixer": "^1.12", | ||
"squizlabs/php_codesniffer": "^2.7" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Middlewares\\Utils\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Middlewares\\Tests\\": "tests/" | ||
} | ||
}, | ||
"scripts": { | ||
"test": [ | ||
"phpunit", | ||
"phpcs" | ||
], | ||
"cs-fix": "php-cs-fixer fix . --fixers=-psr0" | ||
} | ||
} |
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,15 @@ | ||
<?xml version="1.0"?> | ||
<ruleset name="Middlewares coding standard"> | ||
<description>Middlewares coding standard</description> | ||
|
||
<!-- display progress --> | ||
<arg value="p"/> | ||
<arg name="colors"/> | ||
|
||
<!-- coding standard --> | ||
<rule ref="PSR2"/> | ||
|
||
<!-- Paths to check --> | ||
<file>src</file> | ||
<file>tests</file> | ||
</ruleset> |
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,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit bootstrap="vendor/autoload.php" | ||
backupGlobals="false" | ||
backupStaticAttributes="false" | ||
colors="true" | ||
verbose="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false"> | ||
<testsuites> | ||
<testsuite name="All tests"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
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,79 @@ | ||
<?php | ||
|
||
namespace Middlewares\Utils; | ||
|
||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Factory\ResponseFactoryInterface; | ||
use Psr\Http\Factory\StreamFactoryInterface; | ||
|
||
/** | ||
* Simple class to create instances of PSR-7 classes. | ||
*/ | ||
abstract class Factory | ||
{ | ||
/** | ||
* @var ResponseFactoryInterface | ||
*/ | ||
private static $responseFactory; | ||
|
||
/** | ||
* @var StreamFactoryInterface | ||
*/ | ||
private static $streamFactory; | ||
|
||
/** | ||
* Set a custom responseFactory. | ||
* | ||
* @param ResponseFactoryInterface $responseFactory | ||
*/ | ||
public static function setResponseFactory(ResponseFactoryInterface $responseFactory) | ||
{ | ||
self::$responseFactory = $responseFactory; | ||
} | ||
|
||
/** | ||
* Set a custom streamFactory. | ||
* | ||
* @param StreamFactoryInterface $streamFactory | ||
*/ | ||
public static function setStreamFactory(StreamFactoryInterface $streamFactory) | ||
{ | ||
self::$streamFactory = $streamFactory; | ||
} | ||
|
||
/** | ||
* Creates a Response instance. | ||
* | ||
* @param int $code The status code | ||
* | ||
* @return ResponseInterface | ||
*/ | ||
public static function createResponse($code = 200) | ||
{ | ||
if (self::$responseFactory === null) { | ||
self::$responseFactory = new ResponseFactory(); | ||
} | ||
|
||
return self::$responseFactory->createResponse($code); | ||
} | ||
|
||
/** | ||
* Creates a Stream instance. | ||
* | ||
* @param resource $resource A resource returned by fopen | ||
* | ||
* @return StreamInterface | ||
*/ | ||
public static function createStream($resource = null) | ||
{ | ||
if (self::$streamFactory === null) { | ||
self::$streamFactory = new StreamFactory(); | ||
} | ||
|
||
if ($resource === null) { | ||
$resource = fopen('php://temp', 'r+'); | ||
} | ||
|
||
return self::$streamFactory->createStream($resource); | ||
} | ||
} |
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,36 @@ | ||
<?php | ||
|
||
namespace Middlewares\Utils; | ||
|
||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Factory\ResponseFactoryInterface; | ||
|
||
/** | ||
* Simple class to create response instances of PSR-7 classes. | ||
*/ | ||
class ResponseFactory implements ResponseFactoryInterface | ||
{ | ||
/** | ||
* Creates a Response instance. | ||
* | ||
* @param int $code The status code | ||
* | ||
* @return ResponseInterface | ||
*/ | ||
public function createResponse($code = 200) | ||
{ | ||
if (class_exists('Zend\\Diactoros\\Response')) { | ||
return new \Zend\Diactoros\Response('php://memory', $code); | ||
} | ||
|
||
if (class_exists('GuzzleHttp\\Psr7\\Response')) { | ||
return new \GuzzleHttp\Psr7\Response($code); | ||
} | ||
|
||
if (class_exists('Slim\\Http\\Response')) { | ||
return new \Slim\Http\Response($code); | ||
} | ||
|
||
throw new \RuntimeException('Unable to create a response. No PSR-7 stream library detected'); | ||
} | ||
} |
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,36 @@ | ||
<?php | ||
|
||
namespace Middlewares\Utils; | ||
|
||
use Psr\Http\Message\StreamInterface; | ||
use Psr\Http\Factory\StreamFactoryInterface; | ||
|
||
/** | ||
* Simple class to create instances of PSR-7 streams. | ||
*/ | ||
class StreamFactory implements StreamFactoryInterface | ||
{ | ||
/** | ||
* Creates a Stream instance. | ||
* | ||
* @param resource $resource A resource returned by fopen | ||
* | ||
* @return StreamInterface | ||
*/ | ||
public function createStream($resource) | ||
{ | ||
if (class_exists('Zend\\Diactoros\\Stream')) { | ||
return new \Zend\Diactoros\Stream($resource); | ||
} | ||
|
||
if (class_exists('GuzzleHttp\\Psr7\\Stream')) { | ||
return new \GuzzleHttp\Psr7\Stream($resource); | ||
} | ||
|
||
if (class_exists('Slim\\Http\\Stream')) { | ||
return new \Slim\Http\Stream($resource); | ||
} | ||
|
||
throw new \RuntimeException('Unable to create a stream. No PSR-7 stream library detected'); | ||
} | ||
} |
Oops, something went wrong.