Skip to content

Commit 600e1c9

Browse files
author
danielRConsid
committed
fix: bind multiple instances (singletons) to interface classes
1 parent db202d4 commit 600e1c9

7 files changed

Lines changed: 13 additions & 19 deletions

File tree

composer.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "maplephp/container",
33
"type": "library",
4-
"version": "v1.1.4",
4+
"version": "v2.0.0",
55
"description": "Container, Factories and dependency injectors with full PSR-11 support.",
66
"keywords": [
77
"container",
@@ -27,11 +27,7 @@
2727
"maplephp/dto": "^3.0"
2828
},
2929
"autoload": {
30-
"files": [
31-
"src/Setup/aliases.php"
32-
],
3330
"psr-4": {
34-
"Psr\\Container\\": "src/Interfaces/",
3531
"MaplePHP\\Container\\": "src"
3632
}
3733
},

src/Autowire.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace MaplePHP\Container;
46

57
use MaplePHP\Container\Interfaces\AutowireInterface;
68

79
class Autowire implements AutowireInterface
810
{
9-
1011
private Reflection $reflect;
1112
/**
1213
* @var mixed|object|null
@@ -52,7 +53,7 @@ public function disableDI(): self
5253
*/
5354
public function addArgs(array $args): self
5455
{
55-
if(count($args) <= 0) {
56+
if (count($args) <= 0) {
5657
throw new \InvalidArgumentException("You must provide at least one argument.");
5758
}
5859
$inst = $this->disableDI();
@@ -73,4 +74,4 @@ public function run(): mixed
7374
}
7475
return $this->class;
7576
}
76-
}
77+
}

src/Container.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use Closure;
88
use MaplePHP\Container\Interfaces\AutowireInterface;
9-
use Psr\Container\ContainerInterface;
9+
use MaplePHP\Container\Interfaces\ContainerInterface;
1010
use MaplePHP\Container\Interfaces\FactoryInterface;
1111
use MaplePHP\DTO\Format\Arr;
1212
//use MaplePHP\Container\Reflection;

src/Interfaces/AutowireInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ public function addArgs(array $args): self;
3131
* @throws \ReflectionException
3232
*/
3333
public function run(): mixed;
34-
}
34+
}

src/Interfaces/ContainerInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Psr\Container;
5+
namespace MaplePHP\Container\Interfaces;
66

77
/**
88
* Describes the interface of a container that exposes methods to read its entries.

src/Reflection.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,13 @@ private function insertInterfaceClasses(ReflectionClass $inst, string $className
241241
if ($this->allowInterfaces) {
242242
if (self::$interfaceFactory !== null) {
243243
foreach (self::$interfaceFactory as $call) {
244-
self::$class[$classNameA] = $call($inst->getShortName(), $classNameA, $inst);
244+
$getter = $call($inst->getShortName(), $classNameA, $inst);
245+
if($getter !== null) {
246+
self::$class[$classNameA] = $call($inst->getShortName(), $classNameA, $inst);
247+
}
245248
}
246249
}
250+
247251
} else {
248252
self::$class[$classNameA] = null;
249253
}

src/Setup/aliases.php

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)