Skip to content

Commit 4388ee9

Browse files
[DI] Allow autowiring by type + parameter name
1 parent 11a33d7 commit 4388ee9

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

DependencyInjection/FrameworkExtension.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Doctrine\Common\Annotations\AnnotationRegistry;
1515
use Doctrine\Common\Annotations\Reader;
16+
use Psr\Cache\CacheItemPoolInterface;
1617
use Psr\Log\LoggerAwareInterface;
1718
use Symfony\Bridge\Monolog\Processor\DebugProcessor;
1819
use Symfony\Bridge\Monolog\Processor\ProcessorInterface;
@@ -25,6 +26,7 @@
2526
use Symfony\Component\Cache\Adapter\AdapterInterface;
2627
use Symfony\Component\Cache\Adapter\ArrayAdapter;
2728
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
29+
use Symfony\Component\Cache\CacheInterface;
2830
use Symfony\Component\Cache\Marshaller\DefaultMarshaller;
2931
use Symfony\Component\Cache\Marshaller\MarshallerInterface;
3032
use Symfony\Component\Cache\ResettableInterface;
@@ -95,6 +97,7 @@
9597
use Symfony\Component\Validator\ObjectInitializerInterface;
9698
use Symfony\Component\WebLink\HttpHeaderSerializer;
9799
use Symfony\Component\Workflow;
100+
use Symfony\Component\Workflow\WorkflowInterface;
98101
use Symfony\Component\Yaml\Command\LintCommand as BaseYamlLintCommand;
99102
use Symfony\Component\Yaml\Yaml;
100103
use Symfony\Contracts\Service\ResetInterface;
@@ -581,6 +584,7 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $
581584
// Store to container
582585
$container->setDefinition($workflowId, $workflowDefinition);
583586
$container->setDefinition(sprintf('%s.definition', $workflowId), $definitionDefinition);
587+
$container->registerAliasForArgument($workflowId, WorkflowInterface::class, $name.'.'.$type);
584588

585589
// Add workflow to Registry
586590
if ($workflow['supports']) {
@@ -1452,6 +1456,10 @@ private function registerLockConfiguration(array $config, ContainerBuilder $cont
14521456
$container->setAlias(StoreInterface::class, new Alias('lock.store', false));
14531457
$container->setAlias(Factory::class, new Alias('lock.factory', false));
14541458
$container->setAlias(LockInterface::class, new Alias('lock', false));
1459+
} else {
1460+
$container->registerAliasForArgument('lock.'.$resourceName.'.store', StoreInterface::class, $resourceName.'.lock.store');
1461+
$container->registerAliasForArgument('lock.'.$resourceName.'.factory', Factory::class, $resourceName.'.lock.factory');
1462+
$container->registerAliasForArgument('lock.'.$resourceName, LockInterface::class, $resourceName.'.lock');
14551463
}
14561464
}
14571465
}
@@ -1509,6 +1517,8 @@ private function registerMessengerConfiguration(array $config, ContainerBuilder
15091517
if ($busId === $config['default_bus']) {
15101518
$container->setAlias('message_bus', $busId)->setPublic(true);
15111519
$container->setAlias(MessageBusInterface::class, $busId);
1520+
} else {
1521+
$container->registerAliasForArgument($busId, MessageBusInterface::class);
15121522
}
15131523
}
15141524

@@ -1593,6 +1603,8 @@ private function registerCacheConfiguration(array $config, ContainerBuilder $con
15931603
$pool['adapter'] = '.'.$pool['adapter'].'.inner';
15941604
}
15951605
$definition = new ChildDefinition($pool['adapter']);
1606+
$container->registerAliasForArgument($name, CacheInterface::class);
1607+
$container->registerAliasForArgument($name, CacheItemPoolInterface::class);
15961608

15971609
if ($pool['tags']) {
15981610
if ($config['pools'][$pool['tags']]['tags'] ?? false) {

0 commit comments

Comments
 (0)