From d1996d948ec8e26a80fde55936374aa1368a5f3b Mon Sep 17 00:00:00 2001 From: Woody Gilk Date: Thu, 17 Mar 2022 13:40:07 -0500 Subject: [PATCH 1/5] Support PHP 8.1, drop 7.2 Fixes #791 --- .github/workflows/ci.yml | 8 ++++---- change-log.md | 4 ++++ composer.json | 7 ++++--- src/Compiler/Compiler.php | 13 ++++++++++--- src/Definition/Resolver/ArrayResolver.php | 2 +- 5 files changed, 23 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d12150199..dd1a83d7b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,10 +16,10 @@ jobs: timeout-minutes: 15 strategy: matrix: - php: [ '7.2', '7.3', '7.4', '8.0' ] + php: [ '7.3', '7.4', '8.0', '8.1' ] dependency-version: [ '' ] include: - - php: '7.2' + - php: '7.3' dependency-version: '--prefer-lowest' steps: - name: Checkout @@ -37,10 +37,10 @@ jobs: key: php-${{ matrix.php }}-composer-locked-${{ hashFiles('composer.lock') }} restore-keys: php-${{ matrix.php }}-composer-locked- - name: Install PHP dependencies - if: matrix.php != '8.0' + if: matrix.php != '8.0' && matrix.php != '8.1' run: composer update ${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-progress --no-suggest - name: 'Install PHP dependencies on PHP 8 (TODO: remove that)' - if: matrix.php == '8.0' + if: matrix.php == '8.0' || matrix.php == '8.1' run: | # Install Composer 2 composer self-update --snapshot diff --git a/change-log.md b/change-log.md index 94fe4e66d..572f284ea 100644 --- a/change-log.md +++ b/change-log.md @@ -1,5 +1,9 @@ # Change log +## 6.1.0 + +- [#791](https://github.com/PHP-DI/PHP-DI/issues/791) Support PHP 8.1, remove support for PHP 7.2 + ## 6.0.2 - Fix potential regression introduced when fixing [#582](https://github.com/PHP-DI/PHP-DI/issues/582) diff --git a/composer.json b/composer.json index 0874f2d80..5f0c9dbfe 100644 --- a/composer.json +++ b/composer.json @@ -25,17 +25,18 @@ "phpstan": "phpstan analyse -l 5 -c phpstan.neon src" }, "require": { - "php": ">=7.2.0", + "php": ">=7.3.0", "psr/container": "^1.0", "php-di/invoker": "^2.0", "php-di/phpdoc-reader": "^2.0.1", - "opis/closure": "^3.5.5" + "opis/closure": "^3.5.5", + "laravel/serializable-closure": "^1.0" }, "require-dev": { "phpunit/phpunit": "^8.5|^9.0", "mnapoli/phpunit-easymock": "^1.2", "doctrine/annotations": "~1.2", - "ocramius/proxy-manager": "^2.0.2", + "ocramius/proxy-manager": "^2.2", "friendsofphp/php-cs-fixer": "^2.4", "phpstan/phpstan": "^0.12" }, diff --git a/src/Compiler/Compiler.php b/src/Compiler/Compiler.php index 8abc32d69..b2483a45c 100644 --- a/src/Compiler/Compiler.php +++ b/src/Compiler/Compiler.php @@ -21,7 +21,9 @@ use function dirname; use function file_put_contents; use InvalidArgumentException; -use Opis\Closure\SerializableClosure; +use Laravel\SerializableClosure\SerializableClosure; +use Laravel\SerializableClosure\Support\ReflectionClosure; +use Opis\Closure\SerializableClosure as OpisSerializableClosure; use function rename; use function sprintf; use function tempnam; @@ -401,8 +403,13 @@ private function isCompilable($value) */ private function compileClosure(\Closure $closure) : string { - $wrapper = new SerializableClosure($closure); - $reflector = $wrapper->getReflector(); + if (\PHP_VERSION_ID < 70400) { + $wrapper = new OpisSerializableClosure($closure); + $reflector = $wrapper->getReflector(); + } else { + $wrapper = new SerializableClosure($closure); + $reflector = new ReflectionClosure($closure); + } if ($reflector->getUseVariables()) { throw new InvalidDefinition('Cannot compile closures which import variables using the `use` keyword'); diff --git a/src/Definition/Resolver/ArrayResolver.php b/src/Definition/Resolver/ArrayResolver.php index 72d5ed4c0..30a715b70 100644 --- a/src/Definition/Resolver/ArrayResolver.php +++ b/src/Definition/Resolver/ArrayResolver.php @@ -42,7 +42,7 @@ public function resolve(Definition $definition, array $parameters = []) : array $values = $definition->getValues(); // Resolve nested definitions - array_walk_recursive($values, function (&$value, $key) use ($definition) { + array_walk_recursive($values, function (& $value, $key) use ($definition) { if ($value instanceof Definition) { $value = $this->resolveDefinition($value, $definition, $key); } From 05aacc90750ec2552d072a988e84d1d723d8be2e Mon Sep 17 00:00:00 2001 From: Matthieu Napoli Date: Sat, 9 Apr 2022 17:00:03 +0200 Subject: [PATCH 2/5] Require PHP 7.4 to support PHP 8.1 --- .github/workflows/ci.yml | 6 +++--- composer.json | 9 ++++----- src/Compiler/Compiler.php | 10 ++-------- tests/IntegrationTest/ContainerDebugTest.php | 14 +++++++------- .../Definitions/FactoryDefinitionTest.php | 5 +---- .../Source/AnnotationBasedAutowiringTest.php | 8 -------- 6 files changed, 17 insertions(+), 35 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dd1a83d7b..002973b14 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,10 +16,10 @@ jobs: timeout-minutes: 15 strategy: matrix: - php: [ '7.3', '7.4', '8.0', '8.1' ] + php: [ '7.4', '8.0', '8.1' ] dependency-version: [ '' ] include: - - php: '7.3' + - php: '7.4' dependency-version: '--prefer-lowest' steps: - name: Checkout @@ -28,7 +28,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} - tools: composer:v1 + tools: composer:v2 coverage: none - name: Cache Composer dependencies uses: actions/cache@v2 diff --git a/composer.json b/composer.json index 5f0c9dbfe..16b5f265e 100644 --- a/composer.json +++ b/composer.json @@ -25,18 +25,17 @@ "phpstan": "phpstan analyse -l 5 -c phpstan.neon src" }, "require": { - "php": ">=7.3.0", + "php": ">=7.4.0", "psr/container": "^1.0", "php-di/invoker": "^2.0", "php-di/phpdoc-reader": "^2.0.1", - "opis/closure": "^3.5.5", "laravel/serializable-closure": "^1.0" }, "require-dev": { - "phpunit/phpunit": "^8.5|^9.0", + "phpunit/phpunit": "^9.5", "mnapoli/phpunit-easymock": "^1.2", - "doctrine/annotations": "~1.2", - "ocramius/proxy-manager": "^2.2", + "doctrine/annotations": "~1.10", + "ocramius/proxy-manager": "^2.11.2", "friendsofphp/php-cs-fixer": "^2.4", "phpstan/phpstan": "^0.12" }, diff --git a/src/Compiler/Compiler.php b/src/Compiler/Compiler.php index b2483a45c..55051c58d 100644 --- a/src/Compiler/Compiler.php +++ b/src/Compiler/Compiler.php @@ -23,7 +23,6 @@ use InvalidArgumentException; use Laravel\SerializableClosure\SerializableClosure; use Laravel\SerializableClosure\Support\ReflectionClosure; -use Opis\Closure\SerializableClosure as OpisSerializableClosure; use function rename; use function sprintf; use function tempnam; @@ -403,13 +402,8 @@ private function isCompilable($value) */ private function compileClosure(\Closure $closure) : string { - if (\PHP_VERSION_ID < 70400) { - $wrapper = new OpisSerializableClosure($closure); - $reflector = $wrapper->getReflector(); - } else { - $wrapper = new SerializableClosure($closure); - $reflector = new ReflectionClosure($closure); - } + $wrapper = new SerializableClosure($closure); + $reflector = new ReflectionClosure($closure); if ($reflector->getUseVariables()) { throw new InvalidDefinition('Cannot compile closures which import variables using the `use` keyword'); diff --git a/tests/IntegrationTest/ContainerDebugTest.php b/tests/IntegrationTest/ContainerDebugTest.php index a0a183360..eca1f3b02 100644 --- a/tests/IntegrationTest/ContainerDebugTest.php +++ b/tests/IntegrationTest/ContainerDebugTest.php @@ -74,28 +74,28 @@ public function testEntriesDefinitions() }); // Default definitions - $this->assertRegExp('/^Object \(\n {4}class = DI\\\Container\n/', $container->debugEntry('DI\Container')); - $this->assertRegExp( + $this->assertMatchesRegularExpression('/^Object \(\n {4}class = DI\\\Container\n/', $container->debugEntry('DI\Container')); + $this->assertMatchesRegularExpression( '/^Object \(\n {4}class = #NOT INSTANTIABLE# DI\\\FactoryInterface\n/', $container->debugEntry('DI\FactoryInterface') ); - $this->assertRegExp( + $this->assertMatchesRegularExpression( '/^Object \(\n {4}class = #NOT INSTANTIABLE# Invoker\\\InvokerInterface\n/', $container->debugEntry('Invoker\InvokerInterface') ); - $this->assertRegExp( + $this->assertMatchesRegularExpression( '/^Object \(\n {4}class = #NOT INSTANTIABLE# Psr\\\Container\\\ContainerInterface\n/', $container->debugEntry('Psr\Container\ContainerInterface') ); // Container definitions - $this->assertRegExp('/^Object \(\n {4}class = DI\\\Container\n/', $container->debugEntry('create')); - $this->assertRegExp('/^Object \(\n {4}class = DI\\\Container\n/', $container->debugEntry('autowire')); + $this->assertMatchesRegularExpression('/^Object \(\n {4}class = DI\\\Container\n/', $container->debugEntry('create')); + $this->assertMatchesRegularExpression('/^Object \(\n {4}class = DI\\\Container\n/', $container->debugEntry('autowire')); $this->assertEquals('Factory', $container->debugEntry('factory')); $this->assertEquals('Factory', $container->debugEntry('callback')); $this->assertEquals('Decorate(decorator)', $container->debugEntry('decorator')); $this->assertEquals('get(value)', $container->debugEntry('alias')); - $this->assertRegExp('/^Environment variable \(\n {4}variable = foo\n/', $container->debugEntry('environment')); + $this->assertMatchesRegularExpression('/^Environment variable \(\n {4}variable = foo\n/', $container->debugEntry('environment')); $this->assertEquals("[\n 0 => 'foo',\n 1 => 'bar',\n]", $container->debugEntry('array')); $this->assertEquals('foo', $container->debugEntry('string')); $this->assertEquals('Value (1.5)', $container->debugEntry('float')); diff --git a/tests/IntegrationTest/Definitions/FactoryDefinitionTest.php b/tests/IntegrationTest/Definitions/FactoryDefinitionTest.php index cac73c8dc..6bbe8ce24 100644 --- a/tests/IntegrationTest/Definitions/FactoryDefinitionTest.php +++ b/tests/IntegrationTest/Definitions/FactoryDefinitionTest.php @@ -590,7 +590,7 @@ public function test_closure_with_static_variables_are_supported(ContainerBuilde public function test_multiple_closures_on_the_same_line_cannot_be_compiled() { - $this->markTestSkipped('Opis/closure doesn\'t throw on multiple closures on the same line'); + $this->markTestSkipped('laravel/serializable-closure doesn\'t throw on multiple closures on the same line'); $this->expectException(InvalidDefinition::class); $this->expectExceptionMessage('Cannot compile closures when two closures are defined on the same line'); @@ -614,9 +614,6 @@ public function test_optional_parameters_can_be_omitted(ContainerBuilder $builde self::assertEquals('foo', $container->get('factory')); } - /** - * @requires PHP 7.4 - */ public function test_fn_closures_compilation_is_supported() { $builder = (new ContainerBuilder)->enableCompilation(self::COMPILATION_DIR, self::generateCompiledClassName()); diff --git a/tests/UnitTest/Definition/Source/AnnotationBasedAutowiringTest.php b/tests/UnitTest/Definition/Source/AnnotationBasedAutowiringTest.php index f42fe98a1..3187e91d2 100644 --- a/tests/UnitTest/Definition/Source/AnnotationBasedAutowiringTest.php +++ b/tests/UnitTest/Definition/Source/AnnotationBasedAutowiringTest.php @@ -65,10 +65,6 @@ public function testUnguessableProperty() (new AnnotationBasedAutowiring)->autowire(AnnotationFixture4::class); } - /** - * Typed properties support requires PHP 7.4 - * @requires PHP 7.4 - */ public function testTypedProperty() { $definition = (new AnnotationBasedAutowiring)->autowire(AnnotationFixtureTypedProperties::class); @@ -79,10 +75,6 @@ public function testTypedProperty() $this->assertHasPropertyInjection($definition, 'typedAndNamed', 'name'); } - /** - * Typed properties support requires PHP 7.4 - * @requires PHP 7.4 - */ public function testScalarTypedPropertiesFail() { $this->expectException(\DI\Definition\Exception\InvalidAnnotation::class); From a6a7d9e7823a181bd5c625636912fb610119223a Mon Sep 17 00:00:00 2001 From: Matthieu Napoli Date: Sat, 9 Apr 2022 18:42:10 +0200 Subject: [PATCH 3/5] Remove useless variable --- src/Compiler/Compiler.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Compiler/Compiler.php b/src/Compiler/Compiler.php index 55051c58d..0f76a6302 100644 --- a/src/Compiler/Compiler.php +++ b/src/Compiler/Compiler.php @@ -402,7 +402,6 @@ private function isCompilable($value) */ private function compileClosure(\Closure $closure) : string { - $wrapper = new SerializableClosure($closure); $reflector = new ReflectionClosure($closure); if ($reflector->getUseVariables()) { From bf04f2f43cf6d5ce5d0d8fbb3e890bd41ded71d5 Mon Sep 17 00:00:00 2001 From: Matthieu Napoli Date: Sat, 9 Apr 2022 18:42:54 +0200 Subject: [PATCH 4/5] Simplify CI config --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 002973b14..2423187dc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,10 +37,10 @@ jobs: key: php-${{ matrix.php }}-composer-locked-${{ hashFiles('composer.lock') }} restore-keys: php-${{ matrix.php }}-composer-locked- - name: Install PHP dependencies - if: matrix.php != '8.0' && matrix.php != '8.1' + if: matrix.php != '8.1' run: composer update ${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-progress --no-suggest - - name: 'Install PHP dependencies on PHP 8 (TODO: remove that)' - if: matrix.php == '8.0' || matrix.php == '8.1' + - name: 'Install PHP dependencies on PHP 8.1 (TODO: remove that)' + if: matrix.php == '8.1' run: | # Install Composer 2 composer self-update --snapshot From 3275bff873c7e46820a3d16bd4cf22bff6f32553 Mon Sep 17 00:00:00 2001 From: Matthieu Napoli Date: Sat, 9 Apr 2022 18:46:00 +0200 Subject: [PATCH 5/5] Remove unused import --- src/Compiler/Compiler.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Compiler/Compiler.php b/src/Compiler/Compiler.php index 0f76a6302..ca5d49467 100644 --- a/src/Compiler/Compiler.php +++ b/src/Compiler/Compiler.php @@ -21,7 +21,6 @@ use function dirname; use function file_put_contents; use InvalidArgumentException; -use Laravel\SerializableClosure\SerializableClosure; use Laravel\SerializableClosure\Support\ReflectionClosure; use function rename; use function sprintf;