Skip to content

Commit b64fd76

Browse files
committed
Add providers self reference factory
1 parent 26c77ce commit b64fd76

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/ServiceProvider/AggregateServiceProvider.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
use Interop\Container\ServiceProviderInterface;
2222
use Psr\Container\ContainerInterface;
2323

24+
use function DI\string;
25+
2426
/**
2527
* Aggregates multiple service providers into a single provider.
2628
*
@@ -58,10 +60,18 @@ public function __construct(ServiceProviderInterface ...$serviceProviders)
5860
*/
5961
public function getFactories(): array
6062
{
63+
$serviceProviders = array_reduce(
64+
$this->serviceProviders,
65+
static fn (array $carry, ServiceProviderInterface $provider) => $carry + [
66+
$provider::class => new ServiceFactory($provider),
67+
],
68+
[static::class => new ServiceFactory($this)],
69+
);
70+
6171
return array_reduce(
6272
$this->serviceProviders,
6373
static fn ($factories, $serviceProvider) => array_merge($factories, $serviceProvider->getFactories()),
64-
[static::class => new ServiceFactory($this)]
74+
$serviceProviders,
6575
);
6676
}
6777

0 commit comments

Comments
 (0)