diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..cd8eb86 --- /dev/null +++ b/.editorconfig @@ -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 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..48a95b6 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,16 @@ +# Path-based git attributes +# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html + +# Ignore all test and documentation with "export-ignore". +/.editorconfig export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore +/.scrutinizer.yml export-ignore +/.styleci.yml export-ignore +/.travis.yml export-ignore +/PULL_REQUEST_TEMPLATE.md export-ignore +/ISSUE_TEMPLATE.md export-ignore +/phpcs.xml.dist export-ignore +/phpunit.xml.dist export-ignore +/tests export-ignore +/docs export-ignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..610db13 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +build +composer.lock +vendor +phpcs.xml +phpunit.xml +.phpunit.result.cache +.php_cs.cache diff --git a/.php_cs.dist b/.php_cs.dist new file mode 100644 index 0000000..76e1b8b --- /dev/null +++ b/.php_cs.dist @@ -0,0 +1,23 @@ +in([__DIR__ . '/src']); + +return PhpCsFixer\Config::create() + ->setRiskyAllowed(true) + ->setRules( + [ + '@Symfony' => true, + 'binary_operator_spaces' => ['align_double_arrow' => true, 'align_equals' => true], + 'ordered_imports' => true, + 'array_syntax' => ['syntax' => 'short'], + 'void_return' => true, + 'declare_strict_types' => true, + 'yoda_style' => true, + 'increment_style' => ['style' => 'post'], + 'concat_space' => ['spacing' => 'one'], + ] + ) + ->setFinder($finder) + ->setUsingCache(true); + diff --git a/.scrutinizer.yml b/.scrutinizer.yml new file mode 100644 index 0000000..27497c2 --- /dev/null +++ b/.scrutinizer.yml @@ -0,0 +1,31 @@ +build: + nodes: + analysis: + project_setup: + override: true + tests: + override: [php-scrutinizer-run] + +filter: + excluded_paths: [tests/*] + +checks: + php: + remove_extra_empty_lines: true + remove_php_closing_tag: true + remove_trailing_whitespace: true + fix_use_statements: + remove_unused: true + preserve_multiple: false + preserve_blanklines: true + order_alphabetically: true + fix_php_opening_tag: true + fix_linefeed: true + fix_line_ending: true + fix_identation_4spaces: true + fix_doc_comments: true + +tools: + external_code_coverage: + timeout: 600 + runs: 3 diff --git a/.styleci.yml b/.styleci.yml new file mode 100644 index 0000000..247a09c --- /dev/null +++ b/.styleci.yml @@ -0,0 +1 @@ +preset: psr2 diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..d2f9463 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,25 @@ +language: php + +cache: + directories: + - $HOME/.composer/cache + +php: + - 7.3 + +# This triggers builds to run on the new TravisCI infrastructure. +# See: http://docs.travis-ci.com/user/workers/container-based-infrastructure/ +sudo: false + +before_install: + - travis_retry composer self-update --no-interaction + +install: + - travis_retry composer update --no-interaction --prefer-dist + +script: + - composer check-style + +after_success: + - wget https://scrutinizer-ci.com/ocular.phar + - php ocular.phar code-coverage:upload --format=php-clover coverage.clover diff --git a/CONDUCT.md b/CONDUCT.md new file mode 100644 index 0000000..cf33a53 --- /dev/null +++ b/CONDUCT.md @@ -0,0 +1,51 @@ +# Contributor Code of Conduct + +As contributors and maintainers of this project, and in the interest of +fostering an open and welcoming community, we pledge to respect all people who +contribute through reporting issues, posting feature requests, updating +documentation, submitting pull requests or patches, and other activities. + +We are committed to making participation in this project a harassment-free +experience for everyone, regardless of level of experience, gender, gender +identity and expression, sexual orientation, disability, personal appearance, +body size, race, ethnicity, age, religion, or nationality. + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery +* Personal attacks +* Trolling or insulting/derogatory comments +* Public or private harassment +* Publishing other's private information, such as physical or electronic + addresses, without explicit permission +* Other unethical or unprofessional conduct + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +By adopting this Code of Conduct, project maintainers commit themselves to +fairly and consistently applying these principles to every aspect of managing +this project. Project maintainers who do not follow or enforce the Code of +Conduct may be permanently removed from the project team. + +This code of conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting a project maintainer at [Aurimas Niekis][email]. All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. Maintainers are +obligated to maintain confidentiality with regard to the reporter of an +incident. + + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 1.3.0, available at +[http://contributor-covenant.org/version/1/3/0/][version] + +[homepage]: http://contributor-covenant.org +[version]: http://contributor-covenant.org/version/1/3/0/ +[email]: mailto:aurimas@niekis.lt diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..027c762 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,93 @@ +# Contributing + +If you're here, you would like to contribute to this repository and you're really welcome! + + +## Bug reports + +If you find a bug or a documentation issue, please report it or even better: fix it :). If you report it, +please be as precise as possible. Here is a little list of required information: + + - Precise description of the bug + - Details of your environment (for example: OS, PHP version, installed extensions) + - Backtrace which might help identifing the bug + + +## Feature requests + +If you think a feature is missing, please report it or even better: implement it :). If you report it, describe the more +precisely what you would like to see implemented and we will discuss what is the best approach for it. If you can do +some research before submitting it and link the resources to your description, you're awesome! It will allow us to more +easily understood/implement it. + + +## Sending a Pull Request + +If you're here, you are going to fix a bug or implement a feature and you're the best! +To do it, first fork the repository, clone it and create a new branch with the following commands: + +``` bash +$ git clone git@github.com:your-name/sapi-bridge.git +$ git checkout -b feature-or-bug-fix-description +``` + +Then install the dependencies through [Composer](https://getcomposer.org/): + +``` bash +$ composer install +``` + +Write code and tests. When you are ready, run the tests. +(This is usually [PHPUnit](http://phpunit.de/)) + +``` bash +$ composer test +``` + +When you are ready with the code, tested it and documented it, you can commit and push it with the following commands: + +``` bash +$ git commit -m "Feature or bug fix description" +$ git push origin feature-or-bug-fix-description +``` + +**Note:** Please write your commit messages in the imperative and follow the +[guidelines](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html) for clear and concise messages. + +Then [create a pull request](https://help.github.com/articles/creating-a-pull-request/) on GitHub. + +Please make sure that each individual commit in your pull request is meaningful. +If you had to make multiple intermediate commits while developing, +please squash them before submitting with the following commands +(here, we assume you would like to squash 3 commits in a single one): + +``` bash +$ git rebase -i HEAD~3 +``` + +If your branch conflicts with the master branch, you will need to rebase and repush it with the following commands: + +``` bash +$ git remote add upstream git@github.com:ThrusterIO/sapi-bridge.git +$ git pull --rebase upstream master +$ git push -f origin feature-or-bug-fix-description +``` + + +## Coding standard + +This repository follows the [PSR-2 standard](http://www.php-fig.org/psr/psr-2/) and so, if you want to contribute, +you must follow these rules. + + +## Semver + +We are trying to follow [semver](http://semver.org/). When you are making BC breaking changes, +please let us know why you think it is important. +In this case, your patch can only be included in the next major version. + + +## Code of Conduct + +This project is released with a [Contributor Code of Conduct](CONDUCT.md). +By participating in this project you agree to abide by its terms. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ad2e3a6 --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2019 Aurimas Niekis + +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. + diff --git a/README.md b/README.md new file mode 100644 index 0000000..3a9a821 --- /dev/null +++ b/README.md @@ -0,0 +1,97 @@ +# SapiBridge + +[![Latest Version on Packagist][ico-version]][link-packagist] +[![Software License][ico-license]](LICENSE) +[![Build Status][ico-travis]][link-travis] +[![Coverage Status][ico-scrutinizer]][link-scrutinizer] +[![Quality Score][ico-code-quality]][link-code-quality] +[![Total Downloads][ico-downloads]][link-downloads] + +[![Email][ico-email]][link-email] + +The Thruster SapiBridge Bridge. + + +## Install + +Via Composer + +```bash +$ composer require thruster/sapi-bridge +``` + +## Usage + +Any class which implements PSR-15 `RequestHandlerInterface`. + +```php +attach($kernel) + ->run(); + +``` + +## Testing + +Run test cases + +```bash +$ composer test +``` + +Run test cases with coverage (HTML format) + + +```bash +$ composer test-coverage +``` + +Run PHP style checker + +```bash +$ composer check-style +``` + +Run PHP style fixer + +```bash +$ composer fix-style +``` + +## Contributing + +Please see [CONTRIBUTING](CONTRIBUTING.md) and [CONDUCT](CONDUCT.md) for details. + + +## License + +Please see [License File](LICENSE) for more information. + +[ico-version]: https://img.shields.io/packagist/v/ThrusterIO/sapi-bridge.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/ThrusterIO/sapi-bridge/master.svg?style=flat-square +[ico-scrutinizer]: https://img.shields.io/scrutinizer/coverage/g/ThrusterIO/sapi-bridge.svg?style=flat-square +[ico-code-quality]: https://img.shields.io/scrutinizer/g/ThrusterIO/sapi-bridge.svg?style=flat-square +[ico-downloads]: https://img.shields.io/packagist/dt/thruster/sapi-bridge.svg?style=flat-square +[ico-email]: https://img.shields.io/badge/email-team@thruster.io-blue.svg?style=flat-square + +[link-packagist]: https://packagist.org/packages/thruster/sapi-bridge +[link-travis]: https://travis-ci.org/ThrusterIO/sapi-bridge +[link-scrutinizer]: https://scrutinizer-ci.com/g/ThrusterIO/sapi-bridge/code-structure +[link-code-quality]: https://scrutinizer-ci.com/g/ThrusterIO/sapi-bridge +[link-downloads]: https://packagist.org/packages/thruster/sapi-bridge +[link-email]: mailto:team@thruster.io diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..86c8bfd --- /dev/null +++ b/composer.json @@ -0,0 +1,56 @@ +{ + "name": "thruster/sapi-bridge", + "type": "library", + "description": "Thruster SapiBridge Bridge", + "keywords": [ + "sapi-bridge", + "thruster" + ], + "homepage": "https://thruster.io", + "license": "MIT", + "authors": [ + { + "name": "Aurimas Niekis", + "email": "aurimas@niekis.lt" + } + ], + "require": { + "php": ">=7.3", + "ext-curl": "*", + "zendframework/zend-diactoros": "^2.1", + "zendframework/zend-httphandlerrunner": "^1.0" + }, + "require-dev": { + "phpunit/phpunit": "^8", + "friendsofphp/php-cs-fixer": "^2" + }, + "autoload": { + "psr-4": { + "Thruster\\SapiBridge\\": "src" + }, + "classmap": [ + "src/" + ] + }, + "autoload-dev": { + "psr-4": { + "Thruster\\SapiBridge\\Tests\\": "tests" + } + }, + "scripts": { + "test": "phpunit", + "test-coverage": "phpunit --coverage-html build/html/", + "check-style": "php-cs-fixer fix --dry-run --diff --diff-format udiff", + "fix-style": "php-cs-fixer fix", + "phpcs-ci": "phpcs --standard=psr2 src/", + "test-ci": "phpunit --coverage-text --coverage-clover=coverage.clover" + }, + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "config": { + "sort-packages": true + } +} diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..bc77f61 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,24 @@ + + + + + + + + + + ./tests/ + + + + + + ./src + + + diff --git a/src/SapiBridge.php b/src/SapiBridge.php new file mode 100644 index 0000000..b8c1686 --- /dev/null +++ b/src/SapiBridge.php @@ -0,0 +1,48 @@ + + */ +class SapiBridge +{ + /** @var ServerRequestInterface */ + private $serverRequest; + + /** @var RequestHandlerInterface */ + private $handler; + + public function __construct(ServerRequestInterface $request) + { + $this->serverRequest = $request; + } + + public static function createFromGlobals(): self + { + return new static(ServerRequestFactory::fromGlobals()); + } + + public function attach(RequestHandlerInterface $handler): self + { + $this->handler = $handler; + + return $this; + } + + public function run(): void + { + $emitter = new SapiEmitter(); + + $emitter->emit($this->handler->handle($this->serverRequest)); + } +}