diff --git a/README.md b/README.md index ed98d21..116e21b 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,12 @@ [![UnitTests](https://github.com/renakdup/simple-wordpress-dic/actions/workflows/phpunit.yaml/badge.svg)](https://github.com/renakdup/simple-wordpress-dic/actions/workflows/phpunit.yaml) [![Test Coverage](https://api.codeclimate.com/v1/badges/21ae6e3776b160b24e75/test_coverage)](https://codeclimate.com/github/renakdup/simple-php-dic/test_coverage) [![PHPStan](https://github.com/renakdup/simple-wordpress-dic/actions/workflows/phpstan.yaml/badge.svg)](https://github.com/renakdup/simple-wordpress-dic/actions/workflows/phpstan.yaml) -[![Latest Stable Version](http://poser.pugx.org/renakdup/simple-dic/v)](https://packagist.org/packages/renakdup/simple-dic) -[![PHP Version Require](http://poser.pugx.org/renakdup/simple-dic/require/php)](https://packagist.org/packages/renakdup/simple-dic) -[![Total Downloads](http://poser.pugx.org/renakdup/simple-dic/downloads)](https://packagist.org/packages/renakdup/simple-dic) + +[//]: # ([![Latest Stable Version](http://poser.pugx.org/renakdup/simple-dic/v)](https://packagist.org/packages/renakdup/simple-dic)) + +[//]: # ([![PHP Version Require](http://poser.pugx.org/renakdup/simple-dic/require/php)](https://packagist.org/packages/renakdup/simple-dic)) + +[//]: # ([![Total Downloads](http://poser.pugx.org/renakdup/simple-dic/downloads)](https://packagist.org/packages/renakdup/simple-dic)) Simple DI Container with **autowiring** in a single file **with NO dependencies** allows you to easily use it in your PHP applications and especially convenient for **WordPress** plugins and themes. diff --git a/src/Container.php b/src/Container.php index 0ba0255..d41e31d 100644 --- a/src/Container.php +++ b/src/Container.php @@ -8,7 +8,7 @@ * Author Email: renakdup@gmail.com * Author Site: https://wp-yoda.com/en/ * - * Version: 1.1.2 + * Version: 1.2.2 * Source Code: https://github.com/renakdup/simple-dic * * Licence: MIT License @@ -80,7 +80,6 @@ public function get( string $id ) { } $service = $this->resolve( $id ); - $this->resolved[ $id ] = $service; return $service; @@ -98,7 +97,7 @@ public function get( string $id ) { * @return bool */ public function has( string $id ): bool { - return array_key_exists( $id, $this->services ); + return array_key_exists( $id, $this->resolved ) || array_key_exists( $id, $this->services ); } /** diff --git a/tests/ContainerTest.php b/tests/ContainerTest.php index 64980f5..b63497a 100644 --- a/tests/ContainerTest.php +++ b/tests/ContainerTest.php @@ -15,7 +15,6 @@ use RenakdupTests\SimpleDIC\Assets\ClassWithConstructor; use RenakdupTests\SimpleDIC\Assets\ClassWithConstructorDepsException; use RenakdupTests\SimpleDIC\Assets\ParentClass; -use RenakdupTests\SimpleDIC\Assets\PrivateConstructor; use RenakdupTests\SimpleDIC\Assets\SomeInterface; use RenakdupTests\SimpleDIC\Assets\SimpleClass; use RenakdupTests\SimpleDIC\Assets\UseAbstractClass; @@ -124,9 +123,7 @@ public function test_get__singleton_check_changing_property(): void { } public function test_get__singleton_for_resolved_child_dependencies(): void { - /** - * @var $obj1 ClassWithConstructor - */ + /** @var ClassWithConstructor $obj1 */ $obj1 = $this->container->get( ClassWithConstructor::class ); self::assertSame( @@ -211,11 +208,9 @@ public function test_get__error_for_not_bound_supertypes(): void { } public function test_make(): void { - /** - * @var $obj1 ClassWithConstructorPrimitives - * @var $obj2 ClassWithConstructorPrimitives - */ + /** @var ClassWithConstructorPrimitives $obj1 */ $obj1 = $this->container->make( ClassWithConstructorPrimitives::class ); + /** @var ClassWithConstructorPrimitives $obj2 */ $obj2 = $this->container->make( ClassWithConstructorPrimitives::class ); self::assertNotSame( $obj1, $obj2 ); @@ -250,5 +245,9 @@ public function test_has(): void { self::assertTrue( $this->container->has( $name ) ); self::assertFalse( $this->container->has( 'not-exist' ) ); + + $this->container->get( SimpleClass::class ); + self::assertTrue( $this->container->has( SimpleClass::class ) ); } + }