Skip to content

Commit e1edf53

Browse files
authored
Merge pull request #19 from renakdup/fix-has-method-issue
#16 has() method doesn't look at $resolved values
2 parents 28f56ca + 91c284f commit e1edf53

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
[![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)
33
[![Test Coverage](https://api.codeclimate.com/v1/badges/21ae6e3776b160b24e75/test_coverage)](https://codeclimate.com/github/renakdup/simple-php-dic/test_coverage)
44
[![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)
5-
[![Latest Stable Version](http://poser.pugx.org/renakdup/simple-dic/v)](https://packagist.org/packages/renakdup/simple-dic)
6-
[![PHP Version Require](http://poser.pugx.org/renakdup/simple-dic/require/php)](https://packagist.org/packages/renakdup/simple-dic)
7-
[![Total Downloads](http://poser.pugx.org/renakdup/simple-dic/downloads)](https://packagist.org/packages/renakdup/simple-dic)
5+
6+
[//]: # ([![Latest Stable Version](http://poser.pugx.org/renakdup/simple-dic/v)](https://packagist.org/packages/renakdup/simple-dic))
7+
8+
[//]: # ([![PHP Version Require](http://poser.pugx.org/renakdup/simple-dic/require/php)](https://packagist.org/packages/renakdup/simple-dic))
9+
10+
[//]: # ([![Total Downloads](http://poser.pugx.org/renakdup/simple-dic/downloads)](https://packagist.org/packages/renakdup/simple-dic))
811

912
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.
1013

src/Container.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Author Email: [email protected]
99
* Author Site: https://wp-yoda.com/en/
1010
*
11-
* Version: 1.1.2
11+
* Version: 1.2.2
1212
* Source Code: https://github.com/renakdup/simple-dic
1313
*
1414
* Licence: MIT License
@@ -80,7 +80,6 @@ public function get( string $id ) {
8080
}
8181

8282
$service = $this->resolve( $id );
83-
8483
$this->resolved[ $id ] = $service;
8584

8685
return $service;
@@ -98,7 +97,7 @@ public function get( string $id ) {
9897
* @return bool
9998
*/
10099
public function has( string $id ): bool {
101-
return array_key_exists( $id, $this->services );
100+
return array_key_exists( $id, $this->resolved ) || array_key_exists( $id, $this->services );
102101
}
103102

104103
/**

tests/ContainerTest.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use RenakdupTests\SimpleDIC\Assets\ClassWithConstructor;
1616
use RenakdupTests\SimpleDIC\Assets\ClassWithConstructorDepsException;
1717
use RenakdupTests\SimpleDIC\Assets\ParentClass;
18-
use RenakdupTests\SimpleDIC\Assets\PrivateConstructor;
1918
use RenakdupTests\SimpleDIC\Assets\SomeInterface;
2019
use RenakdupTests\SimpleDIC\Assets\SimpleClass;
2120
use RenakdupTests\SimpleDIC\Assets\UseAbstractClass;
@@ -124,9 +123,7 @@ public function test_get__singleton_check_changing_property(): void {
124123
}
125124

126125
public function test_get__singleton_for_resolved_child_dependencies(): void {
127-
/**
128-
* @var $obj1 ClassWithConstructor
129-
*/
126+
/** @var ClassWithConstructor $obj1 */
130127
$obj1 = $this->container->get( ClassWithConstructor::class );
131128

132129
self::assertSame(
@@ -211,11 +208,9 @@ public function test_get__error_for_not_bound_supertypes(): void {
211208
}
212209

213210
public function test_make(): void {
214-
/**
215-
* @var $obj1 ClassWithConstructorPrimitives
216-
* @var $obj2 ClassWithConstructorPrimitives
217-
*/
211+
/** @var ClassWithConstructorPrimitives $obj1 */
218212
$obj1 = $this->container->make( ClassWithConstructorPrimitives::class );
213+
/** @var ClassWithConstructorPrimitives $obj2 */
219214
$obj2 = $this->container->make( ClassWithConstructorPrimitives::class );
220215

221216
self::assertNotSame( $obj1, $obj2 );
@@ -250,5 +245,9 @@ public function test_has(): void {
250245

251246
self::assertTrue( $this->container->has( $name ) );
252247
self::assertFalse( $this->container->has( 'not-exist' ) );
248+
249+
$this->container->get( SimpleClass::class );
250+
self::assertTrue( $this->container->has( SimpleClass::class ) );
253251
}
252+
254253
}

0 commit comments

Comments
 (0)