Skip to content

Commit a90458c

Browse files
bug #47351 [FrameworkBundle] Do not throw when describing a factory definition (MatTheCat)
This PR was squashed before being merged into the 4.4 branch. Discussion ---------- [FrameworkBundle] Do not throw when describing a factory definition | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #47309 | License | MIT | Doc PR | N/A Commits ------- c0efe1a088 [FrameworkBundle] Do not throw when describing a factory definition
2 parents bd7d15b + fa4bc98 commit a90458c

17 files changed

+136
-4
lines changed

Console/Descriptor/JsonDescriptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ private function getContainerDefinitionData(Definition $definition, bool $omitTa
219219
if ($factory[0] instanceof Reference) {
220220
$data['factory_service'] = (string) $factory[0];
221221
} elseif ($factory[0] instanceof Definition) {
222-
throw new \InvalidArgumentException('Factory is not describable.');
222+
$data['factory_class'] = $factory[0]->getClass() ?? 'not configured';
223223
} else {
224224
$data['factory_class'] = $factory[0];
225225
}

Console/Descriptor/MarkdownDescriptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ protected function describeContainerDefinition(Definition $definition, array $op
196196
if ($factory[0] instanceof Reference) {
197197
$output .= "\n".'- Factory Service: `'.$factory[0].'`';
198198
} elseif ($factory[0] instanceof Definition) {
199-
throw new \InvalidArgumentException('Factory is not describable.');
199+
$output .= "\n".'- Factory Class: `'.($factory[0]->getClass() ?? 'not configured').'`';
200200
} else {
201201
$output .= "\n".'- Factory Class: `'.$factory[0].'`';
202202
}

Console/Descriptor/TextDescriptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ protected function describeContainerDefinition(Definition $definition, array $op
309309
if ($factory[0] instanceof Reference) {
310310
$tableRows[] = ['Factory Service', $factory[0]];
311311
} elseif ($factory[0] instanceof Definition) {
312-
throw new \InvalidArgumentException('Factory is not describable.');
312+
$tableRows[] = ['Factory Class', $factory[0]->getClass() ?? 'not configured'];
313313
} else {
314314
$tableRows[] = ['Factory Class', $factory[0]];
315315
}

Console/Descriptor/XmlDescriptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ private function getContainerDefinitionDocument(Definition $definition, string $
294294
if ($factory[0] instanceof Reference) {
295295
$factoryXML->setAttribute('service', (string) $factory[0]);
296296
} elseif ($factory[0] instanceof Definition) {
297-
throw new \InvalidArgumentException('Factory is not describable.');
297+
$factoryXML->setAttribute('class', $factory[0]->getClass() ?? 'not configured');
298298
} else {
299299
$factoryXML->setAttribute('class', $factory[0]);
300300
}

Tests/Console/Descriptor/ObjectsProvider.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ public static function getContainerDefinitions()
123123
{
124124
$definition1 = new Definition('Full\\Qualified\\Class1');
125125
$definition2 = new Definition('Full\\Qualified\\Class2');
126+
$definition3 = new Definition('Full\\Qualified\\Class3');
126127

127128
return [
128129
'definition_1' => $definition1
@@ -154,6 +155,9 @@ public static function getContainerDefinitions()
154155
->addTag('tag2')
155156
->addMethodCall('setMailer', [new Reference('mailer')])
156157
->setFactory([new Reference('factory.service'), 'get']),
158+
'.definition_3' => $definition3
159+
->setFile('/path/to/file')
160+
->setFactory([new Definition('Full\\Qualified\\FactoryClass'), 'get']),
157161
'definition_without_class' => new Definition(),
158162
];
159163
}

Tests/Fixtures/Descriptor/builder_1_services.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,20 @@
3434
"parameters": []
3535
}
3636
]
37+
},
38+
".definition_3": {
39+
"class": "Full\\Qualified\\Class3",
40+
"public": false,
41+
"synthetic": false,
42+
"lazy": false,
43+
"shared": true,
44+
"abstract": false,
45+
"autowire": false,
46+
"autoconfigure": false,
47+
"file": "\/path\/to\/file",
48+
"factory_class": "Full\\Qualified\\FactoryClass",
49+
"factory_method": "get",
50+
"tags": []
3751
}
3852
},
3953
"aliases": {

Tests/Fixtures/Descriptor/builder_1_services.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ Definitions
2525
- Attr3: val3
2626
- Tag: `tag2`
2727

28+
### .definition_3
29+
30+
- Class: `Full\Qualified\Class3`
31+
- Public: no
32+
- Synthetic: no
33+
- Lazy: no
34+
- Shared: yes
35+
- Abstract: no
36+
- Autowired: no
37+
- Autoconfigured: no
38+
- File: `/path/to/file`
39+
- Factory Class: `Full\Qualified\FactoryClass`
40+
- Factory Method: `get`
41+
2842

2943
Aliases
3044
-------

Tests/Fixtures/Descriptor/builder_1_services.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
--------------- ------------------------
88
.alias_2 alias for ".service_2"
99
.definition_2 Full\Qualified\Class2
10+
.definition_3 Full\Qualified\Class3
1011
--------------- ------------------------
1112

Tests/Fixtures/Descriptor/builder_1_services.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717
<tag name="tag2"/>
1818
</tags>
1919
</definition>
20+
<definition id=".definition_3" class="Full\Qualified\Class3" public="false" synthetic="false" lazy="false" shared="true" abstract="false" autowired="false" autoconfigured="false" file="/path/to/file">
21+
<factory class="Full\Qualified\FactoryClass" method="get"/>
22+
</definition>
2023
</container>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"class": "Full\\Qualified\\Class3",
3+
"public": false,
4+
"synthetic": false,
5+
"lazy": false,
6+
"shared": true,
7+
"abstract": false,
8+
"autowire": false,
9+
"autoconfigure": false,
10+
"file": "\/path\/to\/file",
11+
"factory_class": "Full\\Qualified\\FactoryClass",
12+
"factory_method": "get",
13+
"tags": []
14+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
- Class: `Full\Qualified\Class3`
2+
- Public: no
3+
- Synthetic: no
4+
- Lazy: no
5+
- Shared: yes
6+
- Abstract: no
7+
- Autowired: no
8+
- Autoconfigured: no
9+
- File: `/path/to/file`
10+
- Factory Class: `Full\Qualified\FactoryClass`
11+
- Factory Method: `get`
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---------------- -----------------------------
2+
 Option   Value 
3+
---------------- -----------------------------
4+
Service ID -
5+
Class Full\Qualified\Class3
6+
Tags -
7+
Public no
8+
Synthetic no
9+
Lazy no
10+
Shared yes
11+
Abstract no
12+
Autowired no
13+
Autoconfigured no
14+
Required File /path/to/file
15+
Factory Class Full\Qualified\FactoryClass
16+
Factory Method get
17+
---------------- -----------------------------
18+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<definition class="Full\Qualified\Class3" public="false" synthetic="false" lazy="false" shared="true" abstract="false" autowired="false" autoconfigured="false" file="/path/to/file">
3+
<factory class="Full\Qualified\FactoryClass" method="get"/>
4+
</definition>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"class": "Full\\Qualified\\Class3",
3+
"public": false,
4+
"synthetic": false,
5+
"lazy": false,
6+
"shared": true,
7+
"abstract": false,
8+
"autowire": false,
9+
"autoconfigure": false,
10+
"arguments": [],
11+
"file": "\/path\/to\/file",
12+
"factory_class": "Full\\Qualified\\FactoryClass",
13+
"factory_method": "get",
14+
"tags": []
15+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
- Class: `Full\Qualified\Class3`
2+
- Public: no
3+
- Synthetic: no
4+
- Lazy: no
5+
- Shared: yes
6+
- Abstract: no
7+
- Autowired: no
8+
- Autoconfigured: no
9+
- Arguments: no
10+
- File: `/path/to/file`
11+
- Factory Class: `Full\Qualified\FactoryClass`
12+
- Factory Method: `get`
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---------------- -----------------------------
2+
 Option   Value 
3+
---------------- -----------------------------
4+
Service ID -
5+
Class Full\Qualified\Class3
6+
Tags -
7+
Public no
8+
Synthetic no
9+
Lazy no
10+
Shared yes
11+
Abstract no
12+
Autowired no
13+
Autoconfigured no
14+
Required File /path/to/file
15+
Factory Class Full\Qualified\FactoryClass
16+
Factory Method get
17+
---------------- -----------------------------
18+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<definition class="Full\Qualified\Class3" public="false" synthetic="false" lazy="false" shared="true" abstract="false" autowired="false" autoconfigured="false" file="/path/to/file">
3+
<factory class="Full\Qualified\FactoryClass" method="get"/>
4+
</definition>

0 commit comments

Comments
 (0)