Skip to content

Commit 18627bf

Browse files
weaverryanfabpot
authored andcommitted
[DI] Introducing autoconfigure: automatic _instanceof configuration
1 parent 4f0daa7 commit 18627bf

File tree

57 files changed

+410
-25
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+410
-25
lines changed

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ private function getContainerDefinitionData(Definition $definition, $omitTags =
222222
'shared' => $definition->isShared(),
223223
'abstract' => $definition->isAbstract(),
224224
'autowire' => $definition->isAutowired(),
225+
'autoconfigure' => $definition->isAutoconfigured(),
225226
);
226227

227228
foreach ($definition->getAutowiringTypes(false) as $autowiringType) {

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ protected function describeContainerDefinition(Definition $definition, array $op
183183
."\n".'- Shared: '.($definition->isShared() ? 'yes' : 'no')
184184
."\n".'- Abstract: '.($definition->isAbstract() ? 'yes' : 'no')
185185
."\n".'- Autowired: '.($definition->isAutowired() ? 'yes' : 'no')
186+
."\n".'- Autoconfigured: '.($definition->isAutoconfigured() ? 'yes' : 'no')
186187
;
187188

188189
foreach ($definition->getAutowiringTypes(false) as $autowiringType) {

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ private function getContainerDefinitionDocument(Definition $definition, $id = nu
372372
$serviceXML->setAttribute('shared', $definition->isShared() ? 'true' : 'false');
373373
$serviceXML->setAttribute('abstract', $definition->isAbstract() ? 'true' : 'false');
374374
$serviceXML->setAttribute('autowired', $definition->isAutowired() ? 'true' : 'false');
375+
$serviceXML->setAttribute('autoconfigured', $definition->isAutoconfigured() ? 'true' : 'false');
375376
$serviceXML->setAttribute('file', $definition->getFile());
376377

377378
$calls = $definition->getMethodCalls();

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,49 @@
1313

1414
use Doctrine\Common\Annotations\Reader;
1515
use Symfony\Bridge\Monolog\Processor\DebugProcessor;
16+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
17+
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
1618
use Symfony\Component\Cache\Adapter\AdapterInterface;
1719
use Symfony\Component\Cache\Adapter\ArrayAdapter;
1820
use Symfony\Component\Config\FileLocator;
1921
use Symfony\Component\Config\Loader\LoaderInterface;
2022
use Symfony\Component\Config\Resource\DirectoryResource;
23+
use Symfony\Component\Config\ResourceCheckerInterface;
2124
use Symfony\Component\Console\Application;
25+
use Symfony\Component\Console\Command\Command;
2226
use Symfony\Component\DependencyInjection\Alias;
2327
use Symfony\Component\DependencyInjection\ChildDefinition;
2428
use Symfony\Component\DependencyInjection\ContainerBuilder;
2529
use Symfony\Component\DependencyInjection\ContainerInterface;
2630
use Symfony\Component\DependencyInjection\Definition;
2731
use Symfony\Component\DependencyInjection\Exception\LogicException;
28-
use Symfony\Component\DependencyInjection\Reference;
2932
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
33+
use Symfony\Component\DependencyInjection\Reference;
34+
use Symfony\Component\DependencyInjection\ServiceSubscriberInterface;
35+
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
3036
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
3137
use Symfony\Component\Finder\Finder;
38+
use Symfony\Component\Form\FormTypeGuesserInterface;
39+
use Symfony\Component\Form\FormTypeInterface;
40+
use Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface;
41+
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
42+
use Symfony\Component\HttpKernel\DataCollector\DataCollectorInterface;
3243
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
3344
use Symfony\Component\PropertyAccess\PropertyAccessor;
34-
use Symfony\Component\Serializer\Encoder\YamlEncoder;
45+
use Symfony\Component\PropertyInfo\PropertyAccessExtractorInterface;
46+
use Symfony\Component\PropertyInfo\PropertyDescriptionExtractorInterface;
47+
use Symfony\Component\PropertyInfo\PropertyListExtractorInterface;
48+
use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface;
3549
use Symfony\Component\Serializer\Encoder\CsvEncoder;
50+
use Symfony\Component\Serializer\Encoder\EncoderInterface;
51+
use Symfony\Component\Serializer\Encoder\YamlEncoder;
3652
use Symfony\Component\Serializer\Mapping\Factory\CacheClassMetadataFactory;
3753
use Symfony\Component\Serializer\Normalizer\DataUriNormalizer;
3854
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
3955
use Symfony\Component\Serializer\Normalizer\JsonSerializableNormalizer;
56+
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
57+
use Symfony\Component\Validator\ConstraintValidatorInterface;
58+
use Symfony\Component\Validator\ObjectInitializerInterface;
4059
use Symfony\Component\WebLink\HttpHeaderSerializer;
4160
use Symfony\Component\Workflow;
4261

@@ -225,6 +244,45 @@ public function load(array $configs, ContainerBuilder $container)
225244
'Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller',
226245
));
227246

247+
$container->registerForAutoconfiguration(Command::class)
248+
->addTag('console.command');
249+
$container->registerForAutoconfiguration(ResourceCheckerInterface::class)
250+
->addTag('config_cache.resource_checker');
251+
$container->registerForAutoconfiguration(ServiceSubscriberInterface::class)
252+
->addTag('container.service_subscriber');
253+
$container->registerForAutoconfiguration(AbstractController::class)
254+
->addTag('controller.service_arguments');
255+
$container->registerForAutoconfiguration(Controller::class)
256+
->addTag('controller.service_arguments');
257+
$container->registerForAutoconfiguration(DataCollectorInterface::class)
258+
->addTag('data_collector');
259+
$container->registerForAutoconfiguration(FormTypeInterface::class)
260+
->addTag('form.type');
261+
$container->registerForAutoconfiguration(FormTypeGuesserInterface::class)
262+
->addTag('form.type_guesser');
263+
$container->registerForAutoconfiguration(CacheClearerInterface::class)
264+
->addTag('kernel.cache_clearer');
265+
$container->registerForAutoconfiguration(CacheWarmerInterface::class)
266+
->addTag('kernel.cache_warmer');
267+
$container->registerForAutoconfiguration(EventSubscriberInterface::class)
268+
->addTag('kernel.event_subscriber');
269+
$container->registerForAutoconfiguration(PropertyListExtractorInterface::class)
270+
->addTag('property_info.list_extractor');
271+
$container->registerForAutoconfiguration(PropertyTypeExtractorInterface::class)
272+
->addTag('property_info.type_extractor');
273+
$container->registerForAutoconfiguration(PropertyDescriptionExtractorInterface::class)
274+
->addTag('property_info.description_extractor');
275+
$container->registerForAutoconfiguration(PropertyAccessExtractorInterface::class)
276+
->addTag('property_info.access_extractor');
277+
$container->registerForAutoconfiguration(EncoderInterface::class)
278+
->addTag('serializer.encoder');
279+
$container->registerForAutoconfiguration(NormalizerInterface::class)
280+
->addTag('serializer.normalizer');
281+
$container->registerForAutoconfiguration(ConstraintValidatorInterface::class)
282+
->addTag('validator.constraint_validator');
283+
$container->registerForAutoconfiguration(ObjectInitializerInterface::class)
284+
->addTag('validator.initializer');
285+
228286
if (PHP_VERSION_ID < 70000) {
229287
$this->addClassesToCompile(array(
230288
'Symfony\\Component\\Config\\ConfigCache',

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_with_definition_1.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"shared": true,
1212
"abstract": true,
1313
"autowire": false,
14+
"autoconfigure": false,
1415
"file": null,
1516
"factory_class": "Full\\Qualified\\FactoryClass",
1617
"factory_method": "get",

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_with_definition_1.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
- Shared: yes
1313
- Abstract: yes
1414
- Autowired: no
15+
- Autoconfigured: no
1516
- Factory Class: `Full\Qualified\FactoryClass`
1617
- Factory Method: `get`
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<alias id="alias_1" service="service_1" public="true"/>
3-
<definition id="service_1" class="Full\Qualified\Class1" public="true" synthetic="false" lazy="true" shared="true" abstract="true" autowired="false" file="">
3+
<definition id="service_1" class="Full\Qualified\Class1" public="true" synthetic="false" lazy="true" shared="true" abstract="true" autowired="false" autoconfigured="false" file="">
44
<factory class="Full\Qualified\FactoryClass" method="get"/>
55
</definition>

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_with_definition_2.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"shared": true,
1212
"abstract": false,
1313
"autowire": false,
14+
"autoconfigure": false,
1415
"file": "\/path\/to\/file",
1516
"factory_service": "factory.service",
1617
"factory_method": "get",

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_with_definition_2.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- Shared: yes
1313
- Abstract: no
1414
- Autowired: no
15+
- Autoconfigured: no
1516
- File: `/path/to/file`
1617
- Factory Service: `factory.service`
1718
- Factory Method: `get`

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_with_definition_2.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<alias id="alias_2" service="service_2" public="false"/>
3-
<definition id="service_2" class="Full\Qualified\Class2" public="false" synthetic="true" lazy="false" shared="true" abstract="false" autowired="false" file="/path/to/file">
3+
<definition id="service_2" class="Full\Qualified\Class2" public="false" synthetic="true" lazy="false" shared="true" abstract="false" autowired="false" autoconfigured="false" file="/path/to/file">
44
<factory service="factory.service" method="get"/>
55
<calls>
66
<call method="setMailer"/>

0 commit comments

Comments
 (0)