From 62886349e5abb74faefceabfd06cc2796046ee65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mariano=20Ben=C3=ADtez=20Mulet?= Date: Sat, 10 Feb 2018 11:39:40 +0100 Subject: [PATCH] Updated PHP requirements to >= 7.0; (#4) Updated PHP requirements to >= 7.0; --- .travis.yml | 6 ----- README.md | 2 +- composer.json | 4 +-- src/Bridge/RequestTransformer.php | 29 ++++++++++------------ src/Bridge/RequestTransformerInterface.php | 3 +-- src/Bridge/ResponseMerger.php | 7 +++--- src/Bridge/ResponseMergerInterface.php | 6 +++-- src/BridgeManager.php | 12 ++++----- src/BridgeManagerInterface.php | 6 +++-- 9 files changed, 35 insertions(+), 40 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9871d05..9ce2607 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,6 @@ dist: trusty language: php php: - - 5.6 - 7.0 - 7.1 - 7.2 @@ -16,11 +15,6 @@ cache: directories: - $HOME/.composer/cache -matrix: - include: - - php: 5.6 - env: 'COMPOSER_FLAGS="--prefer-stable --prefer-lowest"' - before_script: - pecl install swoole - echo "extension=swoole.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini diff --git a/README.md b/README.md index 4546dec..9e895c1 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ $bridgeManager->process($swooleRequest, $swooleResponse)->end(); ## Requirements -* PHP-CLI >= 5.6 +* PHP-CLI >= 7.0 (Required by Swoole) * Swoole framework (this has been tested with version 1.10.1) ## Install diff --git a/composer.json b/composer.json index f96181d..76395b5 100644 --- a/composer.json +++ b/composer.json @@ -17,11 +17,11 @@ } ], "require": { - "php" : "~5.6|~7.0" + "php" : "^7.0" }, "require-dev": { - "phpunit/phpunit": ">=5.4.3", "slim/slim": "^3.9", + "phpunit/phpunit": "6.5.6", "squizlabs/php_codesniffer": "^3.2" }, "autoload": { diff --git a/src/Bridge/RequestTransformer.php b/src/Bridge/RequestTransformer.php index 72c8559..dec0ea0 100644 --- a/src/Bridge/RequestTransformer.php +++ b/src/Bridge/RequestTransformer.php @@ -6,7 +6,6 @@ class RequestTransformer implements RequestTransformerInterface { - const DEFAULT_SCHEMA = 'http'; /** @@ -14,9 +13,9 @@ class RequestTransformer implements RequestTransformerInterface * * @return Http\Request * - * @todo Handle https requests + * @todo Handle HTTPS requests */ - public function toSlim(\swoole_http_request $request) + public function toSlim(\swoole_http_request $request): Http\Request { $slimRequest = Http\Request::createFromEnvironment( @@ -43,9 +42,7 @@ public function toSlim(\swoole_http_request $request) $slimRequest = $this->handleUploadedFiles($request, $slimRequest); } - $slimRequest = $this->copyBody($request, $slimRequest); - - return $slimRequest; + return $this->copyBody($request, $slimRequest); } /** @@ -54,7 +51,7 @@ public function toSlim(\swoole_http_request $request) * * @return Http\Request */ - private function copyBody(\swoole_http_request $request, Http\Request $slimRequest) + private function copyBody(\swoole_http_request $request, Http\Request $slimRequest): Http\Request { if (empty($request->rawContent())) { return $slimRequest; @@ -73,7 +70,7 @@ private function copyBody(\swoole_http_request $request, Http\Request $slimReque * * @return Http\Request */ - private function copyHeaders(\swoole_http_request $request, Http\Request $slimRequest) + private function copyHeaders(\swoole_http_request $request, Http\Request $slimRequest): Http\Request { foreach ($request->header as $key => $val) { @@ -88,7 +85,7 @@ private function copyHeaders(\swoole_http_request $request, Http\Request $slimRe * * @return boolean */ - private function isMultiPartFormData(\swoole_http_request $request) + private function isMultiPartFormData(\swoole_http_request $request): bool { if (!isset($request->header['content-type']) @@ -104,7 +101,7 @@ private function isMultiPartFormData(\swoole_http_request $request) * * @return boolean */ - private function isXWwwFormUrlEncoded(\swoole_http_request $request) + private function isXWwwFormUrlEncoded(\swoole_http_request $request): bool { if (!isset($request->header['content-type']) @@ -118,11 +115,11 @@ private function isXWwwFormUrlEncoded(\swoole_http_request $request) /** * @param \swoole_http_request $request - * @param \Slim\Http\Request $slimRequest + * @param Http\Request $slimRequest * - * @return \Slim\Http\Request + * @return Http\Request */ - private function handleUploadedFiles(\swoole_http_request $request, Http\Request $slimRequest) + private function handleUploadedFiles(\swoole_http_request $request, Http\Request $slimRequest): Http\Request { if (empty($request->files) || !is_array($request->files)) { return $slimRequest; @@ -145,11 +142,11 @@ private function handleUploadedFiles(\swoole_http_request $request, Http\Request /** * @param \swoole_http_request $swooleRequest - * @param \Slim\Http\Request $slimRequest + * @param Http\Request $slimRequest * - * @return \Slim\Http\Request + * @return Http\Request */ - private function handlePostData(\swoole_http_request $swooleRequest, Http\Request $slimRequest) + private function handlePostData(\swoole_http_request $swooleRequest, Http\Request $slimRequest): Http\Request { if (empty($swooleRequest->post) || !is_array($swooleRequest->post)) { return $slimRequest; diff --git a/src/Bridge/RequestTransformerInterface.php b/src/Bridge/RequestTransformerInterface.php index 98cd568..b46d29e 100644 --- a/src/Bridge/RequestTransformerInterface.php +++ b/src/Bridge/RequestTransformerInterface.php @@ -6,12 +6,11 @@ interface RequestTransformerInterface { - /** * @param \swoole_http_request $request * * @return Http\Request * */ - public function toSlim(\swoole_http_request $request); + public function toSlim(\swoole_http_request $request): Http\Request; } diff --git a/src/Bridge/ResponseMerger.php b/src/Bridge/ResponseMerger.php index b49ee72..68cccd2 100644 --- a/src/Bridge/ResponseMerger.php +++ b/src/Bridge/ResponseMerger.php @@ -7,7 +7,6 @@ class ResponseMerger implements ResponseMergerInterface { - /** * @var App */ @@ -27,8 +26,10 @@ public function __construct(App $app) * * @return \swoole_http_response */ - public function mergeToSwoole(Http\Response $slimResponse, \swoole_http_response $swooleResponse) - { + public function mergeToSwoole( + Http\Response $slimResponse, + \swoole_http_response $swooleResponse + ): \swoole_http_response { $container = $this->app->getContainer(); $settings = $container->get('settings'); diff --git a/src/Bridge/ResponseMergerInterface.php b/src/Bridge/ResponseMergerInterface.php index 243c79c..9c6e314 100644 --- a/src/Bridge/ResponseMergerInterface.php +++ b/src/Bridge/ResponseMergerInterface.php @@ -6,12 +6,14 @@ interface ResponseMergerInterface { - /** * @param Http\Response $slimResponse * @param \swoole_http_response $swooleResponse * * @return \swoole_http_response */ - public function mergeToSwoole(Http\Response $slimResponse, \swoole_http_response $swooleResponse); + public function mergeToSwoole( + Http\Response $slimResponse, + \swoole_http_response $swooleResponse + ): \swoole_http_response; } diff --git a/src/BridgeManager.php b/src/BridgeManager.php index a2c24c0..dfe25c2 100644 --- a/src/BridgeManager.php +++ b/src/BridgeManager.php @@ -8,7 +8,6 @@ class BridgeManager implements BridgeManagerInterface { - /** * @var App */ @@ -45,12 +44,13 @@ public function __construct( * * @return \swoole_http_response */ - public function process(\swoole_http_request $swooleRequest, \swoole_http_response $swooleResponse) - { + public function process( + \swoole_http_request $swooleRequest, + \swoole_http_response $swooleResponse + ): \swoole_http_response { $slimRequest = $this->requestTransformer->toSlim($swooleRequest); $slimResponse = $this->app->process($slimRequest, new Http\Response()); - $swooleResponse = $this->responseMerger->mergeToSwoole($slimResponse, $swooleResponse); - - return $swooleResponse; + + return $this->responseMerger->mergeToSwoole($slimResponse, $swooleResponse); } } diff --git a/src/BridgeManagerInterface.php b/src/BridgeManagerInterface.php index 0c464d1..2eb1701 100644 --- a/src/BridgeManagerInterface.php +++ b/src/BridgeManagerInterface.php @@ -4,12 +4,14 @@ interface BridgeManagerInterface { - /** * @param \swoole_http_request $swooleRequest * @param \swoole_http_response $swooleResponse * * @return \swoole_http_response */ - public function process(\swoole_http_request $swooleRequest, \swoole_http_response $swooleResponse); + public function process( + \swoole_http_request $swooleRequest, + \swoole_http_response $swooleResponse + ): \swoole_http_response; }