From 6518f1a25cf292921177f249944a2330728ceaeb Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Wed, 13 Oct 2021 12:02:52 +0100 Subject: [PATCH] Adds partial PHP 8.1 support --- .github/workflows/tests.yml | 2 +- composer.json | 3 +-- src/RequestContext.php | 4 ++++ .../ConvertSwooleRequestToIlluminateRequest.php | 2 +- tests/BinaryBootstrapTest.php | 12 +++++++++++- 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c58e1f240..ce749c14c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -13,7 +13,7 @@ jobs: strategy: fail-fast: true matrix: - php: [8.0] + php: [8.0, 8.1] laravel: [^8.35] name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} diff --git a/composer.json b/composer.json index 5d6dd242b..81f593083 100644 --- a/composer.json +++ b/composer.json @@ -27,8 +27,7 @@ "orchestra/testbench": "^6.16", "phpunit/phpunit": "^9.3", "spatie/laravel-ray": "^1.14", - "spiral/roadrunner": "^2.0", - "swoole/ide-helper": "^4.6" + "spiral/roadrunner": "^2.0" }, "bin": [ "bin/roadrunner-worker", diff --git a/src/RequestContext.php b/src/RequestContext.php index e85082a29..f81258f7a 100644 --- a/src/RequestContext.php +++ b/src/RequestContext.php @@ -10,21 +10,25 @@ public function __construct(public array $data = []) { } + #[\ReturnTypeWillChange] public function offsetExists($offset) { return isset($this->data[$offset]); } + #[\ReturnTypeWillChange] public function offsetGet($offset) { return $this->data[$offset]; } + #[\ReturnTypeWillChange] public function offsetSet($offset, $value) { $this->data[$offset] = $value; } + #[\ReturnTypeWillChange] public function offsetUnset($offset) { unset($this->data[$offset]); diff --git a/src/Swoole/Actions/ConvertSwooleRequestToIlluminateRequest.php b/src/Swoole/Actions/ConvertSwooleRequestToIlluminateRequest.php index 4986aaf5f..c2c823ac1 100644 --- a/src/Swoole/Actions/ConvertSwooleRequestToIlluminateRequest.php +++ b/src/Swoole/Actions/ConvertSwooleRequestToIlluminateRequest.php @@ -33,7 +33,7 @@ public function __invoke($swooleRequest, string $phpSapi): Request $swooleRequest->rawContent(), ); - if (str_starts_with($request->headers->get('CONTENT_TYPE'), 'application/x-www-form-urlencoded') && + if (str_starts_with((string) $request->headers->get('CONTENT_TYPE'), 'application/x-www-form-urlencoded') && in_array(strtoupper($request->server->get('REQUEST_METHOD', 'GET')), ['PUT', 'PATCH', 'DELETE'])) { parse_str($request->getContent(), $data); diff --git a/tests/BinaryBootstrapTest.php b/tests/BinaryBootstrapTest.php index f0a6974fe..406ebd5ca 100644 --- a/tests/BinaryBootstrapTest.php +++ b/tests/BinaryBootstrapTest.php @@ -17,7 +17,17 @@ public function test_it_can_retrieve_base_path_from_environment_variable() $process->mustRun(); - $this->assertSame($basePath, $process->getOutput()); + $output = $process->getOutput(); + + if (\PHP_VERSION_ID >= 80100) { + $output = array_filter(explode("\n", $output), function ($output) { + return ! empty($output) && ! str_starts_with($output, 'Deprecated:'); + }); + + $output = implode('', $output); + } + + $this->assertSame($basePath, $output); } /**