Skip to content

Commit 447d05b

Browse files
committed
Add "shared" flag and deprecate scopes concept
1 parent 014104e commit 447d05b

33 files changed

+56
-18
lines changed

Console/Descriptor/JsonDescriptor.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,16 @@ private function getContainerDefinitionData(Definition $definition, $omitTags =
213213
{
214214
$data = array(
215215
'class' => (string) $definition->getClass(),
216-
'scope' => $definition->getScope(),
216+
'scope' => $definition->getScope(false),
217217
'public' => $definition->isPublic(),
218218
'synthetic' => $definition->isSynthetic(),
219219
'lazy' => $definition->isLazy(),
220220
);
221221

222+
if (method_exists($definition, 'isShared')) {
223+
$data['shared'] = $definition->isShared();
224+
}
225+
222226
if (method_exists($definition, 'isSynchronized')) {
223227
$data['synchronized'] = $definition->isSynchronized(false);
224228
}

Console/Descriptor/MarkdownDescriptor.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,16 @@ protected function describeContainerServices(ContainerBuilder $builder, array $o
179179
protected function describeContainerDefinition(Definition $definition, array $options = array())
180180
{
181181
$output = '- Class: `'.$definition->getClass().'`'
182-
."\n".'- Scope: `'.$definition->getScope().'`'
182+
."\n".'- Scope: `'.$definition->getScope(false).'`'
183183
."\n".'- Public: '.($definition->isPublic() ? 'yes' : 'no')
184184
."\n".'- Synthetic: '.($definition->isSynthetic() ? 'yes' : 'no')
185185
."\n".'- Lazy: '.($definition->isLazy() ? 'yes' : 'no')
186186
;
187187

188+
if (method_exists($definition, 'isShared')) {
189+
$output .= "\n".'- Shared: '.($definition->isShared() ? 'yes' : 'no');
190+
}
191+
188192
if (method_exists($definition, 'isSynchronized')) {
189193
$output .= "\n".'- Synchronized: '.($definition->isSynchronized(false) ? 'yes' : 'no');
190194
}

Console/Descriptor/TextDescriptor.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ protected function describeContainerServices(ContainerBuilder $builder, array $o
174174
$serviceIds = isset($options['tag']) && $options['tag'] ? array_keys($builder->findTaggedServiceIds($options['tag'])) : $builder->getServiceIds();
175175
$maxTags = array();
176176

177-
foreach ($serviceIds as $key => $serviceId) {
177+
foreach ($serviceIds as $key => $serviceId) {
178178
$definition = $this->resolveServiceDefinition($builder, $serviceId);
179179
if ($definition instanceof Definition) {
180180
// filter out private services unless shown explicitly
@@ -261,10 +261,13 @@ protected function describeContainerDefinition(Definition $definition, array $op
261261
$description[] = '<comment>Tags</comment> -';
262262
}
263263

264-
$description[] = sprintf('<comment>Scope</comment> %s', $definition->getScope());
264+
$description[] = sprintf('<comment>Scope</comment> %s', $definition->getScope(false));
265265
$description[] = sprintf('<comment>Public</comment> %s', $definition->isPublic() ? 'yes' : 'no');
266266
$description[] = sprintf('<comment>Synthetic</comment> %s', $definition->isSynthetic() ? 'yes' : 'no');
267267
$description[] = sprintf('<comment>Lazy</comment> %s', $definition->isLazy() ? 'yes' : 'no');
268+
if (method_exists($definition, 'isShared')) {
269+
$description[] = sprintf('<comment>Shared</comment> %s', $definition->isShared() ? 'yes' : 'no');
270+
}
268271
if (method_exists($definition, 'isSynchronized')) {
269272
$description[] = sprintf('<comment>Synchronized</comment> %s', $definition->isSynchronized(false) ? 'yes' : 'no');
270273
}

Console/Descriptor/XmlDescriptor.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,10 +362,13 @@ private function getContainerDefinitionDocument(Definition $definition, $id = nu
362362
}
363363
}
364364

365-
$serviceXML->setAttribute('scope', $definition->getScope());
365+
$serviceXML->setAttribute('scope', $definition->getScope(false));
366366
$serviceXML->setAttribute('public', $definition->isPublic() ? 'true' : 'false');
367367
$serviceXML->setAttribute('synthetic', $definition->isSynthetic() ? 'true' : 'false');
368368
$serviceXML->setAttribute('lazy', $definition->isLazy() ? 'true' : 'false');
369+
if (method_exists($definition, 'isShared')) {
370+
$serviceXML->setAttribute('shared', $definition->isShared() ? 'true' : 'false');
371+
}
369372
if (method_exists($definition, 'isSynchronized')) {
370373
$serviceXML->setAttribute('synchronized', $definition->isSynchronized(false) ? 'true' : 'false');
371374
}

Resources/config/test.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313
</parameters>
1414

1515
<services>
16-
<service id="test.client" class="%test.client.class%" scope="prototype">
16+
<service id="test.client" class="%test.client.class%" shared="false">
1717
<argument type="service" id="kernel" />
1818
<argument>%test.client.parameters%</argument>
1919
<argument type="service" id="test.client.history" />
2020
<argument type="service" id="test.client.cookiejar" />
2121
</service>
2222

23-
<service id="test.client.history" class="%test.client.history.class%" scope="prototype" />
23+
<service id="test.client.history" class="%test.client.history.class%" shared="false" />
2424

25-
<service id="test.client.cookiejar" class="%test.client.cookiejar.class%" scope="prototype" />
25+
<service id="test.client.cookiejar" class="%test.client.cookiejar.class%" shared="false" />
2626

2727
<service id="test.session.listener" class="%test.session.listener.class%">
2828
<argument type="service" id="service_container" />

Tests/Fixtures/Descriptor/builder_1_public.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"public": true,
77
"synthetic": false,
88
"lazy": true,
9+
"shared": true,
910
"synchronized": false,
1011
"abstract": true,
1112
"file": null,

Tests/Fixtures/Descriptor/builder_1_public.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ definition_1
1212
- Public: yes
1313
- Synthetic: no
1414
- Lazy: yes
15+
- Shared: yes
1516
- Synchronized: no
1617
- Abstract: yes
1718
- Factory Class: `Full\Qualified\FactoryClass`

Tests/Fixtures/Descriptor/builder_1_public.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<container>
33
<alias id="alias_1" service="service_1" public="true"/>
44
<alias id="alias_2" service="service_2" public="false"/>
5-
<definition id="definition_1" class="Full\Qualified\Class1" scope="container" public="true" synthetic="false" lazy="true" synchronized="false" abstract="true" file="">
5+
<definition id="definition_1" class="Full\Qualified\Class1" scope="container" public="true" synthetic="false" lazy="true" shared="true" synchronized="false" abstract="true" file="">
66
<factory class="Full\Qualified\FactoryClass" method="get"/>
77
</definition>
88
<service id="service_container" class="Symfony\Component\DependencyInjection\ContainerBuilder"/>

Tests/Fixtures/Descriptor/builder_1_services.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"public": true,
77
"synthetic": false,
88
"lazy": true,
9+
"shared": true,
910
"synchronized": false,
1011
"abstract": true,
1112
"file": null,
@@ -21,6 +22,7 @@
2122
"public": false,
2223
"synthetic": true,
2324
"lazy": false,
25+
"shared": true,
2426
"synchronized": false,
2527
"abstract": false,
2628
"file": "\/path\/to\/file",

Tests/Fixtures/Descriptor/builder_1_services.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ definition_1
1212
- Public: yes
1313
- Synthetic: no
1414
- Lazy: yes
15+
- Shared: yes
1516
- Synchronized: no
1617
- Abstract: yes
1718
- Factory Class: `Full\Qualified\FactoryClass`
@@ -25,6 +26,7 @@ definition_2
2526
- Public: no
2627
- Synthetic: yes
2728
- Lazy: no
29+
- Shared: yes
2830
- Synchronized: no
2931
- Abstract: no
3032
- File: `/path/to/file`

Tests/Fixtures/Descriptor/builder_1_services.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
<container>
33
<alias id="alias_1" service="service_1" public="true"/>
44
<alias id="alias_2" service="service_2" public="false"/>
5-
<definition id="definition_1" class="Full\Qualified\Class1" scope="container" public="true" synthetic="false" lazy="true" synchronized="false" abstract="true" file="">
5+
<definition id="definition_1" class="Full\Qualified\Class1" scope="container" public="true" synthetic="false" lazy="true" shared="true" synchronized="false" abstract="true" file="">
66
<factory class="Full\Qualified\FactoryClass" method="get"/>
77
</definition>
8-
<definition id="definition_2" class="Full\Qualified\Class2" scope="container" public="false" synthetic="true" lazy="false" synchronized="false" abstract="false" file="/path/to/file">
8+
<definition id="definition_2" class="Full\Qualified\Class2" scope="container" public="false" synthetic="true" lazy="false" shared="true" synchronized="false" abstract="false" file="/path/to/file">
99
<factory service="factory.service" method="get"/>
1010
<tags>
1111
<tag name="tag1">

Tests/Fixtures/Descriptor/builder_1_tag1.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"public": false,
77
"synthetic": true,
88
"lazy": false,
9+
"shared": true,
910
"synchronized": false,
1011
"abstract": false,
1112
"file": "\/path\/to\/file",

Tests/Fixtures/Descriptor/builder_1_tag1.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ definition_2
1212
- Public: no
1313
- Synthetic: yes
1414
- Lazy: no
15+
- Shared: yes
1516
- Synchronized: no
1617
- Abstract: no
1718
- File: `/path/to/file`

Tests/Fixtures/Descriptor/builder_1_tag1.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
<container>
3-
<definition id="definition_2" class="Full\Qualified\Class2" scope="container" public="false" synthetic="true" lazy="false" synchronized="false" abstract="false" file="/path/to/file">
3+
<definition id="definition_2" class="Full\Qualified\Class2" scope="container" public="false" synthetic="true" lazy="false" shared="true" synchronized="false" abstract="false" file="/path/to/file">
44
<factory service="factory.service" method="get"/>
55
<tags>
66
<tag name="tag1">

Tests/Fixtures/Descriptor/builder_1_tags.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"public": false,
77
"synthetic": true,
88
"lazy": false,
9+
"shared": true,
910
"synchronized": false,
1011
"abstract": false,
1112
"file": "\/path\/to\/file",
@@ -20,6 +21,7 @@
2021
"public": false,
2122
"synthetic": true,
2223
"lazy": false,
24+
"shared": true,
2325
"synchronized": false,
2426
"abstract": false,
2527
"file": "\/path\/to\/file",

Tests/Fixtures/Descriptor/builder_1_tags.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ definition_2
1212
- Public: no
1313
- Synthetic: yes
1414
- Lazy: no
15+
- Shared: yes
1516
- Synchronized: no
1617
- Abstract: no
1718
- File: `/path/to/file`
@@ -30,6 +31,7 @@ definition_2
3031
- Public: no
3132
- Synthetic: yes
3233
- Lazy: no
34+
- Shared: yes
3335
- Synchronized: no
3436
- Abstract: no
3537
- File: `/path/to/file`

Tests/Fixtures/Descriptor/builder_1_tags.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<container>
33
<tag name="tag1">
4-
<definition id="definition_2" class="Full\Qualified\Class2" scope="container" public="false" synthetic="true" lazy="false" synchronized="false" abstract="false" file="/path/to/file">
4+
<definition id="definition_2" class="Full\Qualified\Class2" scope="container" public="false" synthetic="true" lazy="false" shared="true" synchronized="false" abstract="false" file="/path/to/file">
55
<factory service="factory.service" method="get"/>
66
</definition>
77
</tag>
88
<tag name="tag2">
9-
<definition id="definition_2" class="Full\Qualified\Class2" scope="container" public="false" synthetic="true" lazy="false" synchronized="false" abstract="false" file="/path/to/file">
9+
<definition id="definition_2" class="Full\Qualified\Class2" scope="container" public="false" synthetic="true" lazy="false" shared="true" synchronized="false" abstract="false" file="/path/to/file">
1010
<factory service="factory.service" method="get"/>
1111
</definition>
1212
</tag>

Tests/Fixtures/Descriptor/definition_1.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"public": true,
55
"synthetic": false,
66
"lazy": true,
7+
"shared": true,
78
"synchronized": false,
89
"abstract": true,
910
"file": null,

Tests/Fixtures/Descriptor/definition_1.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- Public: yes
44
- Synthetic: no
55
- Lazy: yes
6+
- Shared: yes
67
- Synchronized: no
78
- Abstract: yes
89
- Factory Class: `Full\Qualified\FactoryClass`

Tests/Fixtures/Descriptor/definition_1.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<comment>Public</comment> yes
66
<comment>Synthetic</comment> no
77
<comment>Lazy</comment> yes
8+
<comment>Shared</comment> yes
89
<comment>Synchronized</comment> no
910
<comment>Abstract</comment> yes
1011
<comment>Factory Class</comment> Full\Qualified\FactoryClass
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<definition class="Full\Qualified\Class1" scope="container" public="true" synthetic="false" lazy="true" synchronized="false" abstract="true" file="">
2+
<definition class="Full\Qualified\Class1" scope="container" public="true" synthetic="false" lazy="true" shared="true" synchronized="false" abstract="true" file="">
33
<factory class="Full\Qualified\FactoryClass" method="get"/>
44
</definition>

Tests/Fixtures/Descriptor/definition_2.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"public": false,
55
"synthetic": true,
66
"lazy": false,
7+
"shared": true,
78
"synchronized": false,
89
"abstract": false,
910
"file": "\/path\/to\/file",

Tests/Fixtures/Descriptor/definition_2.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- Public: no
44
- Synthetic: yes
55
- Lazy: no
6+
- Shared: yes
67
- Synchronized: no
78
- Abstract: no
89
- File: `/path/to/file`

Tests/Fixtures/Descriptor/definition_2.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<comment>Public</comment> no
99
<comment>Synthetic</comment> yes
1010
<comment>Lazy</comment> no
11+
<comment>Shared</comment> yes
1112
<comment>Synchronized</comment> no
1213
<comment>Abstract</comment> no
1314
<comment>Required File</comment> /path/to/file

Tests/Fixtures/Descriptor/definition_2.xml

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"?>
2-
<definition class="Full\Qualified\Class2" scope="container" public="false" synthetic="true" lazy="false" synchronized="false" abstract="false" file="/path/to/file">
2+
<definition class="Full\Qualified\Class2" scope="container" public="false" synthetic="true" lazy="false" shared="true" synchronized="false" abstract="false" file="/path/to/file">
33
<factory service="factory.service" method="get"/>
44
<tags>
55
<tag name="tag1">

Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_1.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"public": true,
55
"synthetic": false,
66
"lazy": true,
7+
"shared": true,
78
"synchronized": true,
89
"abstract": true,
910
"file": null,

Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_1.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- Public: yes
44
- Synthetic: no
55
- Lazy: yes
6+
- Shared: yes
67
- Synchronized: yes
78
- Abstract: yes
89
- Factory Class: `Full\Qualified\FactoryClass`

Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_1.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<comment>Public</comment> yes
66
<comment>Synthetic</comment> no
77
<comment>Lazy</comment> yes
8+
<comment>Shared</comment> yes
89
<comment>Synchronized</comment> yes
910
<comment>Abstract</comment> yes
1011
<comment>Factory Class</comment> Full\Qualified\FactoryClass
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<definition class="Full\Qualified\Class1" factory-class="Full\Qualified\FactoryClass" factory-method="get" scope="container" public="true" synthetic="false" lazy="true" synchronized="true" abstract="true" file=""/>
2+
<definition class="Full\Qualified\Class1" factory-class="Full\Qualified\FactoryClass" factory-method="get" scope="container" public="true" synthetic="false" lazy="true" shared="true" synchronized="true" abstract="true" file=""/>

Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_2.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"public": false,
55
"synthetic": true,
66
"lazy": false,
7+
"shared": true,
78
"synchronized": false,
89
"abstract": false,
910
"file": "\/path\/to\/file",

Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_2.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- Public: no
44
- Synthetic: yes
55
- Lazy: no
6+
- Shared: yes
67
- Synchronized: no
78
- Abstract: no
89
- File: `/path/to/file`

Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_2.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<comment>Public</comment> no
99
<comment>Synthetic</comment> yes
1010
<comment>Lazy</comment> no
11+
<comment>Shared</comment> yes
1112
<comment>Synchronized</comment> no
1213
<comment>Abstract</comment> no
1314
<comment>Required File</comment> /path/to/file

Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_2.xml

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"?>
2-
<definition class="Full\Qualified\Class2" factory-service="factory.service" factory-method="get" scope="container" public="false" synthetic="true" lazy="false" synchronized="false" abstract="false" file="/path/to/file">
2+
<definition class="Full\Qualified\Class2" factory-service="factory.service" factory-method="get" scope="container" public="false" synthetic="true" lazy="false" shared="true" synchronized="false" abstract="false" file="/path/to/file">
33
<tags>
44
<tag name="tag1">
55
<parameter name="attr1">val1</parameter>

0 commit comments

Comments
 (0)