diff --git a/.github/workflows/qa.yaml b/.github/workflows/qa.yaml index 7810fd7..cced6ee 100644 --- a/.github/workflows/qa.yaml +++ b/.github/workflows/qa.yaml @@ -7,38 +7,38 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v3 - - name: Setup PHP 7.1 + - name: Setup PHP 7.0 uses: shivammathur/setup-php@v2 with: - php-version: 7.1 + php-version: 7.0 - name: Install dependencies uses: "ramsey/composer-install@v2" - name: Run phpcs run: make phpcs phpstan: - name: phpstan on PHP 7.1 + name: phpstan on PHP 7.0 runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v3 - - name: Setup PHP 7.1 + - name: Setup PHP 7.0 uses: shivammathur/setup-php@v2 with: - php-version: 7.1 + php-version: 7.0 - name: Install dependencies uses: "ramsey/composer-install@v2" - name: Run phpstan run: make phpstan phan: - name: phan on PHP 7.1 + name: phan on PHP 7.0 runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v3 - - name: Setup PHP 7.1 + - name: Setup PHP 7.0 uses: shivammathur/setup-php@v2 with: - php-version: 7.1 + php-version: 7.0 - name: Install dependencies uses: "ramsey/composer-install@v2" - name: Run phan diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7ae7002..3d70941 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,7 +6,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php: [ '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4' ] + php: [ '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4' ] steps: - name: Checkout code uses: actions/checkout@v3 diff --git a/README.md b/README.md index 51e8fb8..5c7d307 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ -A PHP 5.6+ compatible dependency injection container inspired +> Note: This is a fork by WP Staging as they need to support PHP 7.0 + +A PHP 7.0+ compatible dependency injection container inspired by [Laravel IOC](https://laravel.com/docs/5.0/container "Service Container - Laravel - The PHP Framework For Web Artisans") and [Pimple](http://pimple.sensiolabs.org/ "Pimple - A simple PHP Dependency Injection Container") that works even better on newer version of PHP. diff --git a/composer.json b/composer.json index 21f9da5..5804095 100644 --- a/composer.json +++ b/composer.json @@ -1,11 +1,18 @@ { - "name": "lucatume/di52", + "name": "wp-staging/di52", "description": "A PHP 5.6 compatible dependency injection container.", "license": "GPL-3.0", "authors": [ { "name": "Luca Tumedei", - "email": "luca@theaveragedev.com" + "email": "luca@theaveragedev.com", + "role": "Founder" + }, + { + "name": "WP STAGING", + "email": "support@wp-staging.com", + "role": "Maintainer", + "homepage": "https://wp-staging.com" } ], "autoload": { @@ -14,7 +21,7 @@ } }, "require": { - "php": ">=7.1", + "php": ">=7.0", "psr/container": "^1.0", "ext-json": "*" }, diff --git a/config/phan-config.php b/config/phan-config.php index 41c8fda..8459e92 100644 --- a/config/phan-config.php +++ b/config/phan-config.php @@ -43,7 +43,7 @@ // Note that the **only** effect of choosing `'5.6'` is to infer that functions removed in php 7.0 exist. // (See `backward_compatibility_checks` for additional options) // Automatically inferred from composer.json requirement for "php" of ">=5.6" - 'target_php_version' => '7.1', + 'target_php_version' => '7.0', // If enabled, missing properties will be created when // they are first seen. If false, we'll report an diff --git a/makefile b/makefile index 0faf70a..5350cef 100644 --- a/makefile +++ b/makefile @@ -19,7 +19,7 @@ define xdebug_src fi endef -php_versions :=5.6 7.0 7.1 7.2 7.3 7.4 8.0 8.1 8.2 8.3 +php_versions :=5.6 7.0 7.1 7.2 7.3 7.4 8.0 8.1 8.2 8.3 8.4 build: $(build_php_versions) ## Builds the project PHP images. mkdir -p var/cache/composer mkdir -p var/log diff --git a/src/App.php b/src/App.php index e72b2b9..b438ad0 100644 --- a/src/App.php +++ b/src/App.php @@ -99,7 +99,7 @@ public static function offsetSet($offset, $value) * * @throws ContainerException If there's any issue reflecting on the class, interface or the implementation. */ - public static function singleton($id, $implementation = null, ?array $afterBuildMethods = null) + public static function singleton($id, $implementation = null, $afterBuildMethods = null) { static::container()->singleton($id, $implementation, $afterBuildMethods); } @@ -311,7 +311,7 @@ public static function register($serviceProviderClass, ...$alias) * * @throws ContainerException If there's an issue while trying to bind the implementation. */ - public static function bind($id, $implementation = null, ?array $afterBuildMethods = null) + public static function bind($id, $implementation = null, $afterBuildMethods = null) { static::container()->bind($id, $implementation, $afterBuildMethods); } @@ -346,7 +346,7 @@ public static function boot() * @return void This method does not return any value. * @throws ContainerException */ - public static function singletonDecorators($id, $decorators, ?array $afterBuildMethods = null) + public static function singletonDecorators($id, $decorators, $afterBuildMethods = null) { static::container()->singletonDecorators($id, $decorators, $afterBuildMethods); } @@ -367,7 +367,7 @@ public static function singletonDecorators($id, $decorators, ?array $afterBuildM * @return void This method does not return any value. * @throws ContainerException If there's any issue binding the decorators. */ - public static function bindDecorators($id, array $decorators, ?array $afterBuildMethods = null) + public static function bindDecorators($id, array $decorators, $afterBuildMethods = null) { static::container()->bindDecorators($id, $decorators, $afterBuildMethods); } @@ -480,7 +480,7 @@ public static function callback($id, $method) * @return callable A callable function that will return an instance of the specified class when * called. */ - public static function instance($id, ?array $buildArgs = [], ?array $afterBuildMethods = null) + public static function instance($id, $buildArgs = [], $afterBuildMethods = null) { return static::container()->instance($id, $buildArgs ?? [], $afterBuildMethods); } diff --git a/src/Builders/CallableBuilder.php b/src/Builders/CallableBuilder.php index cce82c9..985e507 100644 --- a/src/Builders/CallableBuilder.php +++ b/src/Builders/CallableBuilder.php @@ -53,7 +53,7 @@ class CallableBuilder implements BuilderInterface, ReinitializableBuilderInterfa public function __construct( Container $container, callable $callable, - ?array $afterBuildMethods = null, + $afterBuildMethods = null, ...$buildArgs ) { $this->container = $container; @@ -86,7 +86,7 @@ public function build() * * @return void This method does not return any value. */ - public function reinit(?array $afterBuildMethods = null, ...$buildArgs) + public function reinit($afterBuildMethods = null, ...$buildArgs) { $this->afterBuildMethods = $afterBuildMethods ?: []; $this->buildArgs = $buildArgs; diff --git a/src/Builders/ClassBuilder.php b/src/Builders/ClassBuilder.php index 851f9d5..62d0ad4 100644 --- a/src/Builders/ClassBuilder.php +++ b/src/Builders/ClassBuilder.php @@ -75,7 +75,7 @@ class ClassBuilder implements BuilderInterface, ReinitializableBuilderInterface * * @throws NotFoundException If the class does not exist. */ - public function __construct($id, Resolver $resolver, $className, ?array $afterBuildMethods = null, ...$buildArgs) + public function __construct($id, Resolver $resolver, $className, $afterBuildMethods = null, ...$buildArgs) { if (!class_exists($className)) { throw new NotFoundException( @@ -236,7 +236,7 @@ protected function resolveParameter(Parameter $parameter) /** * {@inheritdoc} */ - public function reinit(?array $afterBuildMethods = null, ...$buildArgs) + public function reinit($afterBuildMethods = null, ...$buildArgs) { $this->afterBuildMethods = $afterBuildMethods; $this->buildArgs = $buildArgs; diff --git a/src/Builders/Factory.php b/src/Builders/Factory.php index dd4f576..9cb356b 100644 --- a/src/Builders/Factory.php +++ b/src/Builders/Factory.php @@ -56,7 +56,7 @@ public function __construct(Container $container, Resolver $resolver) * * @throws NotFoundException If a builder cannot find its implementation target. */ - public function getBuilder($id, $implementation = null, ?array $afterBuildMethods = null, ...$buildArgs) + public function getBuilder($id, $implementation = null, $afterBuildMethods = null, ...$buildArgs) { if ($implementation === null) { $implementation = $id; diff --git a/src/Builders/ReinitializableBuilderInterface.php b/src/Builders/ReinitializableBuilderInterface.php index 782d80e..73f2c18 100644 --- a/src/Builders/ReinitializableBuilderInterface.php +++ b/src/Builders/ReinitializableBuilderInterface.php @@ -22,5 +22,5 @@ interface ReinitializableBuilderInterface * * @return void This method does not return any value. */ - public function reinit(?array $afterBuildMethods = null, ...$buildArgs); + public function reinit($afterBuildMethods = null, ...$buildArgs); } diff --git a/src/Builders/Resolver.php b/src/Builders/Resolver.php index c771945..f4ef512 100644 --- a/src/Builders/Resolver.php +++ b/src/Builders/Resolver.php @@ -170,7 +170,7 @@ public function setWhenNeedsGive($whenClass, $needsClass, BuilderInterface $buil * build arguments. * @throws NotFoundException If the id is a string that does not resolve to an existing, concrete, class. */ - public function resolveWithArgs($id, ?array $afterBuildMethods = null, ...$buildArgs) + public function resolveWithArgs($id, $afterBuildMethods = null, ...$buildArgs) { if (! is_string($id)) { return $id; @@ -197,7 +197,7 @@ public function resolveWithArgs($id, ?array $afterBuildMethods = null, ...$build * * @throws NotFoundException If the id is a string that is not bound and is not an existing, concrete, class. */ - public function resolve($id, ?array $buildLine = null) + public function resolve($id, $buildLine = null) { if ($buildLine !== null) { $this->buildLine = $buildLine; @@ -271,7 +271,7 @@ private function resolveBound($id) * @throws NotFoundException If trying to clone the builder for a non existing id or an id that does not map to a * concrete class name. */ - private function cloneBuilder($id, ?array $afterBuildMethods = null, ...$buildArgs) + private function cloneBuilder($id, $afterBuildMethods = null, ...$buildArgs) { if (isset($this->bindings[$id]) && $this->bindings[$id] instanceof BuilderInterface) { $builder = clone $this->bindings[$id]; diff --git a/src/Container.php b/src/Container.php index 9cc84e6..5dc5ea5 100644 --- a/src/Container.php +++ b/src/Container.php @@ -148,7 +148,7 @@ public function offsetSet($offset, $value) * @return void This method does not return any value. * @throws ContainerException If there's any issue reflecting on the class, interface or the implementation. */ - public function singleton($id, $implementation = null, ?array $afterBuildMethods = null) + public function singleton($id, $implementation = null, $afterBuildMethods = null) { if ($implementation === null) { $implementation = $id; @@ -527,7 +527,7 @@ private function getDeferredProviderMakeClosure(ServiceProvider $provider, $id) * * @throws ContainerException If there's an issue while trying to bind the implementation. */ - public function bind($id, $implementation = null, ?array $afterBuildMethods = null) + public function bind($id, $implementation = null, $afterBuildMethods = null) { if ($implementation === null) { $implementation = $id; @@ -575,7 +575,7 @@ public function boot() * @return void This method does not return any value. * @throws ContainerException */ - public function singletonDecorators($id, $decorators, ?array $afterBuildMethods = null, $afterBuildAll = false) + public function singletonDecorators($id, $decorators, $afterBuildMethods = null, $afterBuildAll = false) { $this->resolver->singleton( $id, @@ -601,7 +601,7 @@ public function singletonDecorators($id, $decorators, ?array $afterBuildMethods private function getDecoratorBuilder( array $decorators, $id, - ?array $afterBuildMethods = null, + $afterBuildMethods = null, $afterBuildAll = false ) { $decorator = array_pop($decorators); @@ -640,7 +640,7 @@ private function getDecoratorBuilder( * @return void This method does not return any value. * @throws ContainerException If there's any issue binding the decorators. */ - public function bindDecorators($id, array $decorators, ?array $afterBuildMethods = null, $afterBuildAll = false) + public function bindDecorators($id, array $decorators, $afterBuildMethods = null, $afterBuildAll = false) { $this->resolver->bind($id, $this->getDecoratorBuilder($decorators, $id, $afterBuildMethods, $afterBuildAll)); } @@ -822,7 +822,7 @@ protected function isStaticMethod($object, $method) * @return callable|Closure A callable function that will return an instance of the specified class when * called. */ - public function instance($id, array $buildArgs = [], ?array $afterBuildMethods = null) + public function instance($id, array $buildArgs = [], $afterBuildMethods = null) { return function () use ($id, $afterBuildMethods, $buildArgs) { if (is_string($id)) { diff --git a/src/ContainerException.php b/src/ContainerException.php index d60b2b0..84ce041 100644 --- a/src/ContainerException.php +++ b/src/ContainerException.php @@ -34,7 +34,10 @@ private static function getPropertyValue($object, $property) do { if ($reflectionClass->hasProperty($property)) { $traceProperty = $reflectionClass->getProperty($property); - $traceProperty->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $traceProperty->setAccessible(true); + } + return $traceProperty->getValue($object); } @@ -60,7 +63,10 @@ private static function setPropertyValue($object, $property, $value) do { if ($reflectionClass->hasProperty($property)) { $traceProperty = $reflectionClass->getProperty($property); - $traceProperty->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $traceProperty->setAccessible(true); + } + $traceProperty->setValue($object, $value); return true; } diff --git a/src/NestedParseError.php b/src/NestedParseError.php index d9deae8..cbf9288 100644 --- a/src/NestedParseError.php +++ b/src/NestedParseError.php @@ -40,7 +40,7 @@ class NestedParseError extends \Exception * @param string $type The type of the entity being loaded. * @param string $name The name of the entity being loaded. */ - public function __construct($message = "", $code = 0, ?Throwable $previous = null, $type = '', $name = '') + public function __construct($message = "", $code = 0, $previous = null, $type = '', $name = '') { parent::__construct($message, $code, $previous); $this->type = $type; diff --git a/tests/unit/UnsetTest.php b/tests/unit/UnsetTest.php index 14f43c9..24d7d99 100644 --- a/tests/unit/UnsetTest.php +++ b/tests/unit/UnsetTest.php @@ -13,7 +13,7 @@ class UnsetTest extends TestCase { - public function test_unset_binding_with_bind_default():void + public function test_unset_binding_with_bind_default() { $container = new Container(false); @@ -30,7 +30,7 @@ public function test_unset_binding_with_bind_default():void $this->assertNotSame($previousInstance, $container->get(MySingletonClass::class)); } - public function test_unset_binding_with_singleton_default():void + public function test_unset_binding_with_singleton_default() { $container = new Container(true); @@ -47,7 +47,7 @@ public function test_unset_binding_with_singleton_default():void $this->assertNotSame($previousInstance, $container->get(MySingletonClass::class)); } - public function test_unset_singleton_with_bind_default(): void + public function test_unset_singleton_with_bind_default() { $container = new Container(false); @@ -64,7 +64,7 @@ public function test_unset_singleton_with_bind_default(): void $this->assertNotSame($previousInstance, $container->get(MySingletonClass::class)); } - public function test_unset_singleton_with_singleton_default(): void + public function test_unset_singleton_with_singleton_default() { $container = new Container(true); @@ -80,7 +80,7 @@ public function test_unset_singleton_with_singleton_default(): void $this->assertNotSame($previousInstance, $container->get(MySingletonClass::class)); } - public function test_unset_given_when_then_with_bind_default(): void + public function test_unset_given_when_then_with_bind_default() { $container = new Container(false); @@ -98,7 +98,7 @@ public function test_unset_given_when_then_with_bind_default(): void $container->get(MySingletonClassTwo::class); } - public function test_unset_given_when_then_with_singleton_default(): void + public function test_unset_given_when_then_with_singleton_default() { $container = new Container(true); diff --git "a/tests/unit/__snapshots__/ThrowableTraceTest-test_error_casting with data set \"mask message\".7-snapshot-1" "b/tests/unit/__snapshots__/ThrowableTraceTest-test_error_casting with data set \"mask message\".7-snapshot-1" index c3b3eca..b73cf07 100644 --- "a/tests/unit/__snapshots__/ThrowableTraceTest-test_error_casting with data set \"mask message\".7-snapshot-1" +++ "b/tests/unit/__snapshots__/ThrowableTraceTest-test_error_casting with data set \"mask message\".7-snapshot-1" @@ -3,5 +3,5 @@ Array [classFQN] => lucatume\DI52\ContainerException [message] => Error while making unit\data\ThrowErrorOnConstructClass: !!! Error while building class unit\data\ThrowErrorOnConstructClass. [file] => /src/ContainerException.php - [line] => 122 + [line] => 128 ) diff --git "a/tests/unit/__snapshots__/ThrowableTraceTest-test_error_casting with data set \"mask message\".8-snapshot-1" "b/tests/unit/__snapshots__/ThrowableTraceTest-test_error_casting with data set \"mask message\".8-snapshot-1" index c3b3eca..b73cf07 100644 --- "a/tests/unit/__snapshots__/ThrowableTraceTest-test_error_casting with data set \"mask message\".8-snapshot-1" +++ "b/tests/unit/__snapshots__/ThrowableTraceTest-test_error_casting with data set \"mask message\".8-snapshot-1" @@ -3,5 +3,5 @@ Array [classFQN] => lucatume\DI52\ContainerException [message] => Error while making unit\data\ThrowErrorOnConstructClass: !!! Error while building class unit\data\ThrowErrorOnConstructClass. [file] => /src/ContainerException.php - [line] => 122 + [line] => 128 ) diff --git "a/tests/unit/__snapshots__/ThrowableTraceTest-test_exception_casting with data set \"mask message\".5-snapshot-1" "b/tests/unit/__snapshots__/ThrowableTraceTest-test_exception_casting with data set \"mask message\".5-snapshot-1" index 4e5b479..d917b8d 100644 --- "a/tests/unit/__snapshots__/ThrowableTraceTest-test_exception_casting with data set \"mask message\".5-snapshot-1" +++ "b/tests/unit/__snapshots__/ThrowableTraceTest-test_exception_casting with data set \"mask message\".5-snapshot-1" @@ -3,5 +3,5 @@ Array [classFQN] => lucatume\DI52\ContainerException [message] => Error while making unit\data\ThrowExceptionOnConstructClass: !!! Exception while building class unit\data\ThrowExceptionOnConstructClass. [file] => /src/ContainerException.php - [line] => 122 + [line] => 128 ) diff --git "a/tests/unit/__snapshots__/ThrowableTraceTest-test_exception_casting with data set \"mask message\".7-snapshot-1" "b/tests/unit/__snapshots__/ThrowableTraceTest-test_exception_casting with data set \"mask message\".7-snapshot-1" index 4e5b479..d917b8d 100644 --- "a/tests/unit/__snapshots__/ThrowableTraceTest-test_exception_casting with data set \"mask message\".7-snapshot-1" +++ "b/tests/unit/__snapshots__/ThrowableTraceTest-test_exception_casting with data set \"mask message\".7-snapshot-1" @@ -3,5 +3,5 @@ Array [classFQN] => lucatume\DI52\ContainerException [message] => Error while making unit\data\ThrowExceptionOnConstructClass: !!! Exception while building class unit\data\ThrowExceptionOnConstructClass. [file] => /src/ContainerException.php - [line] => 122 + [line] => 128 ) diff --git "a/tests/unit/__snapshots__/ThrowableTraceTest-test_exception_casting with data set \"mask message\".8-snapshot-1" "b/tests/unit/__snapshots__/ThrowableTraceTest-test_exception_casting with data set \"mask message\".8-snapshot-1" index 4e5b479..d917b8d 100644 --- "a/tests/unit/__snapshots__/ThrowableTraceTest-test_exception_casting with data set \"mask message\".8-snapshot-1" +++ "b/tests/unit/__snapshots__/ThrowableTraceTest-test_exception_casting with data set \"mask message\".8-snapshot-1" @@ -3,5 +3,5 @@ Array [classFQN] => lucatume\DI52\ContainerException [message] => Error while making unit\data\ThrowExceptionOnConstructClass: !!! Exception while building class unit\data\ThrowExceptionOnConstructClass. [file] => /src/ContainerException.php - [line] => 122 + [line] => 128 ) diff --git "a/tests/unit/__snapshots__/ThrowableTraceTest-test_parse_error_casting with data set \"mask message\".7-snapshot-1" "b/tests/unit/__snapshots__/ThrowableTraceTest-test_parse_error_casting with data set \"mask message\".7-snapshot-1" index e2572c4..701e773 100644 --- "a/tests/unit/__snapshots__/ThrowableTraceTest-test_parse_error_casting with data set \"mask message\".7-snapshot-1" +++ "b/tests/unit/__snapshots__/ThrowableTraceTest-test_parse_error_casting with data set \"mask message\".7-snapshot-1" @@ -3,5 +3,5 @@ Array [classFQN] => lucatume\DI52\ContainerException [message] => Error while making unit\data\ThrowParseErrorOnConstructClass: !!! Parse error while building class unit\data\ThrowParseErrorOnConstructClass. [file] => /src/ContainerException.php - [line] => 122 + [line] => 128 ) diff --git "a/tests/unit/__snapshots__/ThrowableTraceTest-test_parse_error_casting with data set \"mask message\".8-snapshot-1" "b/tests/unit/__snapshots__/ThrowableTraceTest-test_parse_error_casting with data set \"mask message\".8-snapshot-1" index e2572c4..701e773 100644 --- "a/tests/unit/__snapshots__/ThrowableTraceTest-test_parse_error_casting with data set \"mask message\".8-snapshot-1" +++ "b/tests/unit/__snapshots__/ThrowableTraceTest-test_parse_error_casting with data set \"mask message\".8-snapshot-1" @@ -3,5 +3,5 @@ Array [classFQN] => lucatume\DI52\ContainerException [message] => Error while making unit\data\ThrowParseErrorOnConstructClass: !!! Parse error while building class unit\data\ThrowParseErrorOnConstructClass. [file] => /src/ContainerException.php - [line] => 122 + [line] => 128 )