Skip to content
This repository has been archived by the owner on Jun 14, 2023. It is now read-only.

Commit

Permalink
Updated PHP requirements to >= 7.0; (#4)
Browse files Browse the repository at this point in the history
Updated PHP requirements to >= 7.0;
  • Loading branch information
pachico authored Feb 10, 2018
1 parent 4355be5 commit 6288634
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 40 deletions.
6 changes: 0 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ dist: trusty
language: php

php:
- 5.6
- 7.0
- 7.1
- 7.2
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
29 changes: 13 additions & 16 deletions src/Bridge/RequestTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@

class RequestTransformer implements RequestTransformerInterface
{

const DEFAULT_SCHEMA = 'http';

/**
* @param \swoole_http_request $request
*
* @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(
Expand All @@ -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);
}

/**
Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -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'])
Expand All @@ -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'])
Expand All @@ -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;
Expand All @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions src/Bridge/RequestTransformerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
7 changes: 4 additions & 3 deletions src/Bridge/ResponseMerger.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

class ResponseMerger implements ResponseMergerInterface
{

/**
* @var App
*/
Expand All @@ -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');
Expand Down
6 changes: 4 additions & 2 deletions src/Bridge/ResponseMergerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
12 changes: 6 additions & 6 deletions src/BridgeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

class BridgeManager implements BridgeManagerInterface
{

/**
* @var App
*/
Expand Down Expand Up @@ -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);
}
}
6 changes: 4 additions & 2 deletions src/BridgeManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 6288634

Please sign in to comment.