Skip to content

Commit f1974e4

Browse files
committed
Fix container dependencies
1 parent 9ad766d commit f1974e4

File tree

2 files changed

+4
-12
lines changed

2 files changed

+4
-12
lines changed

src/Container.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,9 @@ class Container implements ContainerInterface, ContainerRegistryInterface, Conta
2727
*/
2828
private array $decorators = [];
2929

30-
/**
31-
* @var AutowireHelperFactoryInterface
32-
*/
33-
private AutowireHelperFactoryInterface $autowireHelperFactory;
34-
3530
public function __construct(
3631
)
3732
{
38-
$this->autowireHelperFactory = new AutowireHelperFactory($this);
3933
$this->services = [];
4034
$this->servicesRaw = [];
4135
}
@@ -107,9 +101,7 @@ protected function initializeService(string $serviceId): void
107101
}
108102

109103
$raw = $this->servicesRaw[$serviceId];
110-
111104
$service = $raw($this);
112-
113105
$this->services[$serviceId] = $service;
114106

115107
if(!array_key_exists($serviceId, $this->decorators)) {
@@ -122,10 +114,9 @@ protected function initializeService(string $serviceId): void
122114
return $left[1] > $right[1];
123115
});
124116

125-
$helper = $this->autowireHelperFactory->create();
126-
117+
/** @var array<Closure, int> $decorator */
127118
foreach ($decorators as $decorator) {
128-
$this->services[$serviceId] = $helper->autowire($decorator[0])();
119+
$this->services[$serviceId] = $decorator[0]();
129120
}
130121
}
131122
}

tests/unit/ContainerTest.php

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

33
namespace Micro\Component\DependencyInjection\Tests;
44

5+
use Micro\Component\DependencyInjection\Autowire\ContainerAutowire;
56
use Micro\Component\DependencyInjection\Container;
67
use Micro\Component\DependencyInjection\Exception\ServiceNotRegisteredException;
78
use Micro\Component\DependencyInjection\Exception\ServiceRegistrationException;
@@ -63,7 +64,7 @@ public function testContainerUnresolvedException(): void
6364

6465
public function testDecorateService(): void
6566
{
66-
$container = new Container();
67+
$container = new ContainerAutowire(new Container());
6768

6869
$container->register('test', function ($container) {
6970
return new class {

0 commit comments

Comments
 (0)