Skip to content

Commit

Permalink
Merge pull request #811 from PHP-DI/fix/php-81-serializable
Browse files Browse the repository at this point in the history
PHP 8.1 support by requiring PHP 7.4 or up
  • Loading branch information
mnapoli committed Apr 9, 2022
2 parents 6fb2268 + 3275bff commit ae0f1b3
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 34 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:
timeout-minutes: 15
strategy:
matrix:
php: [ '7.2', '7.3', '7.4', '8.0' ]
php: [ '7.4', '8.0', '8.1' ]
dependency-version: [ '' ]
include:
- php: '7.2'
- php: '7.4'
dependency-version: '--prefer-lowest'
steps:
- name: Checkout
Expand All @@ -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
Expand All @@ -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.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'
- name: 'Install PHP dependencies on PHP 8.1 (TODO: remove that)'
if: matrix.php == '8.1'
run: |
# Install Composer 2
composer self-update --snapshot
Expand Down
4 changes: 4 additions & 0 deletions change-log.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@
"phpstan": "phpstan analyse -l 5 -c phpstan.neon src"
},
"require": {
"php": ">=7.2.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.0.2",
"doctrine/annotations": "~1.10",
"ocramius/proxy-manager": "^2.11.2",
"friendsofphp/php-cs-fixer": "^2.4",
"phpstan/phpstan": "^0.12"
},
Expand Down
5 changes: 2 additions & 3 deletions src/Compiler/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use function dirname;
use function file_put_contents;
use InvalidArgumentException;
use Opis\Closure\SerializableClosure;
use Laravel\SerializableClosure\Support\ReflectionClosure;
use function rename;
use function sprintf;
use function tempnam;
Expand Down Expand Up @@ -401,8 +401,7 @@ private function isCompilable($value)
*/
private function compileClosure(\Closure $closure) : string
{
$wrapper = new SerializableClosure($closure);
$reflector = $wrapper->getReflector();
$reflector = new ReflectionClosure($closure);

if ($reflector->getUseVariables()) {
throw new InvalidDefinition('Cannot compile closures which import variables using the `use` keyword');
Expand Down
2 changes: 1 addition & 1 deletion src/Definition/Resolver/ArrayResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
14 changes: 7 additions & 7 deletions tests/IntegrationTest/ContainerDebugTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
5 changes: 1 addition & 4 deletions tests/IntegrationTest/Definitions/FactoryDefinitionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit ae0f1b3

Please sign in to comment.