Skip to content

Commit

Permalink
[FrameworkBundle] remove usage of deprecated Definition::setFactoryCl…
Browse files Browse the repository at this point in the history
…ass(), Definition::setFactoryService() and Definition::setFactoryMethod() methods.
  • Loading branch information
Hugo Hamon committed Jan 16, 2015
1 parent da9d88d commit fbcc574
Show file tree
Hide file tree
Showing 43 changed files with 497 additions and 116 deletions.
Expand Up @@ -216,23 +216,24 @@ private function getContainerDefinitionData(Definition $definition, $omitTags =
'synthetic' => $definition->isSynthetic(),
'lazy' => $definition->isLazy(),
);

if (method_exists($definition, 'isSynchronized')) {
$data['synchronized'] = $definition->isSynchronized();
$data['synchronized'] = $definition->isSynchronized(false);
}

$data['abstract'] = $definition->isAbstract();
$data['file'] = $definition->getFile();

if ($definition->getFactoryClass()) {
$data['factory_class'] = $definition->getFactoryClass();
if ($definition->getFactoryClass(false)) {
$data['factory_class'] = $definition->getFactoryClass(false);
}

if ($definition->getFactoryService()) {
$data['factory_service'] = $definition->getFactoryService();
if ($definition->getFactoryService(false)) {
$data['factory_service'] = $definition->getFactoryService(false);
}

if ($definition->getFactoryMethod()) {
$data['factory_method'] = $definition->getFactoryMethod();
if ($definition->getFactoryMethod(false)) {
$data['factory_method'] = $definition->getFactoryMethod(false);
}

if ($factory = $definition->getFactory()) {
Expand Down
Expand Up @@ -186,7 +186,7 @@ protected function describeContainerDefinition(Definition $definition, array $op
;

if (method_exists($definition, 'isSynchronized')) {
$output .= "\n".'- Synchronized: '.($definition->isSynchronized() ? 'yes' : 'no');
$output .= "\n".'- Synchronized: '.($definition->isSynchronized(false) ? 'yes' : 'no');
}

$output .= "\n".'- Abstract: '.($definition->isAbstract() ? 'yes' : 'no');
Expand All @@ -195,16 +195,16 @@ protected function describeContainerDefinition(Definition $definition, array $op
$output .= "\n".'- File: `'.$definition->getFile().'`';
}

if ($definition->getFactoryClass()) {
$output .= "\n".'- Factory Class: `'.$definition->getFactoryClass().'`';
if ($definition->getFactoryClass(false)) {
$output .= "\n".'- Factory Class: `'.$definition->getFactoryClass(false).'`';
}

if ($definition->getFactoryService()) {
$output .= "\n".'- Factory Service: `'.$definition->getFactoryService().'`';
if ($definition->getFactoryService(false)) {
$output .= "\n".'- Factory Service: `'.$definition->getFactoryService(false).'`';
}

if ($definition->getFactoryMethod()) {
$output .= "\n".'- Factory Method: `'.$definition->getFactoryMethod().'`';
if ($definition->getFactoryMethod(false)) {
$output .= "\n".'- Factory Method: `'.$definition->getFactoryMethod(false).'`';
}

if ($factory = $definition->getFactory()) {
Expand Down
Expand Up @@ -266,24 +266,24 @@ protected function describeContainerDefinition(Definition $definition, array $op
$description[] = sprintf('<comment>Synthetic</comment> %s', $definition->isSynthetic() ? 'yes' : 'no');
$description[] = sprintf('<comment>Lazy</comment> %s', $definition->isLazy() ? 'yes' : 'no');
if (method_exists($definition, 'isSynchronized')) {
$description[] = sprintf('<comment>Synchronized</comment> %s', $definition->isSynchronized() ? 'yes' : 'no');
$description[] = sprintf('<comment>Synchronized</comment> %s', $definition->isSynchronized(false) ? 'yes' : 'no');
}
$description[] = sprintf('<comment>Abstract</comment> %s', $definition->isAbstract() ? 'yes' : 'no');

if ($definition->getFile()) {
$description[] = sprintf('<comment>Required File</comment> %s', $definition->getFile() ? $definition->getFile() : '-');
}

if ($definition->getFactoryClass()) {
$description[] = sprintf('<comment>Factory Class</comment> %s', $definition->getFactoryClass());
if ($definition->getFactoryClass(false)) {
$description[] = sprintf('<comment>Factory Class</comment> %s', $definition->getFactoryClass(false));
}

if ($definition->getFactoryService()) {
$description[] = sprintf('<comment>Factory Service</comment> %s', $definition->getFactoryService());
if ($definition->getFactoryService(false)) {
$description[] = sprintf('<comment>Factory Service</comment> %s', $definition->getFactoryService(false));
}

if ($definition->getFactoryMethod()) {
$description[] = sprintf('<comment>Factory Method</comment> %s', $definition->getFactoryMethod());
if ($definition->getFactoryMethod(false)) {
$description[] = sprintf('<comment>Factory Method</comment> %s', $definition->getFactoryMethod(false));
}

if ($factory = $definition->getFactory()) {
Expand Down
Expand Up @@ -66,6 +66,21 @@ public function getDescribeContainerBuilderTestData()
return $this->getContainerBuilderDescriptionTestData(ObjectsProvider::getContainerBuilders());
}

/** @dataProvider provideLegacySynchronizedServiceDefinitionTestData */
public function testLegacyDescribeSynchronizedServiceDefinition(Definition $definition, $expectedDescription)
{
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);

$this->assertDescription($expectedDescription, $definition);
}

public function provideLegacySynchronizedServiceDefinitionTestData()
{
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);

return $this->getDescriptionTestData(ObjectsProvider::getLegacyContainerDefinitions());
}

/** @dataProvider getDescribeContainerDefinitionTestData */
public function testDescribeContainerDefinition(Definition $definition, $expectedDescription)
{
Expand Down
Expand Up @@ -97,15 +97,13 @@ public static function getContainerDefinitions()
->setPublic(true)
->setSynthetic(false)
->setLazy(true)
->setSynchronized(true)
->setAbstract(true)
->setFactory(array('Full\\Qualified\\FactoryClass', 'get')),
'definition_2' => $definition2
->setPublic(false)
->setSynthetic(true)
->setFile('/path/to/file')
->setLazy(false)
->setSynchronized(false)
->setAbstract(false)
->addTag('tag1', array('attr1' => 'val1', 'attr2' => 'val2'))
->addTag('tag1', array('attr3' => 'val3'))
Expand All @@ -114,6 +112,39 @@ public static function getContainerDefinitions()
);
}

/**
* @deprecated since version 2.7, to be removed in 3.0
* @internal
*/
public static function getLegacyContainerDefinitions()
{
$definition1 = new Definition('Full\\Qualified\\Class1');
$definition2 = new Definition('Full\\Qualified\\Class2');

return array(
'legacy_synchronized_service_definition_1' => $definition1
->setPublic(true)
->setSynthetic(false)
->setLazy(true)
->setSynchronized(true)
->setAbstract(true)
->setFactoryClass('Full\\Qualified\\FactoryClass', 'get')
->setFactoryMethod('get'),
'legacy_synchronized_service_definition_2' => $definition2
->setPublic(false)
->setSynthetic(true)
->setFile('/path/to/file')
->setLazy(false)
->setSynchronized(false)
->setAbstract(false)
->addTag('tag1', array('attr1' => 'val1', 'attr2' => 'val2'))
->addTag('tag1', array('attr3' => 'val3'))
->addTag('tag2')
->setFactoryService('factory.service')
->setFactoryMethod('get'),
);
}

public static function getContainerAliases()
{
return array(
Expand Down
Expand Up @@ -6,7 +6,7 @@
"public": true,
"synthetic": false,
"lazy": true,
"synchronized": true,
"synchronized": false,
"abstract": true,
"file": null,
"factory_class": "Full\\Qualified\\FactoryClass",
Expand Down
Expand Up @@ -12,7 +12,7 @@ definition_1
- Public: yes
- Synthetic: no
- Lazy: yes
- Synchronized: yes
- Synchronized: no
- Abstract: yes
- Factory Class: `Full\Qualified\FactoryClass`
- Factory Method: `get`
Expand All @@ -37,4 +37,4 @@ alias_2
Services
--------
- `service_container`: `Symfony\Component\DependencyInjection\ContainerBuilder`
- `service_container`: `Symfony\Component\DependencyInjection\ContainerBuilder`
Expand Up @@ -2,7 +2,7 @@
<container>
<alias id="alias_1" service="service_1" public="true"/>
<alias id="alias_2" service="service_2" public="false"/>
<definition id="definition_1" class="Full\Qualified\Class1" scope="container" public="true" synthetic="false" lazy="true" synchronized="true" abstract="true" file="">
<definition id="definition_1" class="Full\Qualified\Class1" scope="container" public="true" synthetic="false" lazy="true" synchronized="false" abstract="true" file="">
<factory class="Full\Qualified\FactoryClass" method="get"/>
</definition>
<service id="service_container" class="Symfony\Component\DependencyInjection\ContainerBuilder"/>
Expand Down
Expand Up @@ -6,7 +6,7 @@
"public": true,
"synthetic": false,
"lazy": true,
"synchronized": true,
"synchronized": false,
"abstract": true,
"file": null,
"factory_class": "Full\\Qualified\\FactoryClass",
Expand Down
Expand Up @@ -12,7 +12,7 @@ definition_1
- Public: yes
- Synthetic: no
- Lazy: yes
- Synchronized: yes
- Synchronized: no
- Abstract: yes
- Factory Class: `Full\Qualified\FactoryClass`
- Factory Method: `get`
Expand Down Expand Up @@ -57,4 +57,4 @@ alias_2
Services
--------

- `service_container`: `Symfony\Component\DependencyInjection\ContainerBuilder`
- `service_container`: `Symfony\Component\DependencyInjection\ContainerBuilder`
Expand Up @@ -2,7 +2,7 @@
<container>
<alias id="alias_1" service="service_1" public="true"/>
<alias id="alias_2" service="service_2" public="false"/>
<definition id="definition_1" class="Full\Qualified\Class1" scope="container" public="true" synthetic="false" lazy="true" synchronized="true" abstract="true" file="">
<definition id="definition_1" class="Full\Qualified\Class1" scope="container" public="true" synthetic="false" lazy="true" synchronized="false" abstract="true" file="">
<factory class="Full\Qualified\FactoryClass" method="get"/>
</definition>
<definition id="definition_2" class="Full\Qualified\Class2" scope="container" public="false" synthetic="true" lazy="false" synchronized="false" abstract="false" file="/path/to/file">
Expand Down
Expand Up @@ -4,7 +4,7 @@
"public": true,
"synthetic": false,
"lazy": true,
"synchronized": true,
"synchronized": false,
"abstract": true,
"file": null,
"factory_class": "Full\\Qualified\\FactoryClass",
Expand Down
Expand Up @@ -3,7 +3,7 @@
- Public: yes
- Synthetic: no
- Lazy: yes
- Synchronized: yes
- Synchronized: no
- Abstract: yes
- Factory Class: `Full\Qualified\FactoryClass`
- Factory Method: `get`
- Factory Method: `get`
Expand Up @@ -5,7 +5,7 @@
<comment>Public</comment> yes
<comment>Synthetic</comment> no
<comment>Lazy</comment> yes
<comment>Synchronized</comment> yes
<comment>Synchronized</comment> no
<comment>Abstract</comment> yes
<comment>Factory Class</comment> Full\Qualified\FactoryClass
<comment>Factory Method</comment> get
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<definition class="Full\Qualified\Class1" scope="container" public="true" synthetic="false" lazy="true" synchronized="true" abstract="true" file="">
<definition class="Full\Qualified\Class1" scope="container" public="true" synthetic="false" lazy="true" synchronized="false" abstract="true" file="">
<factory class="Full\Qualified\FactoryClass" method="get"/>
</definition>
@@ -0,0 +1,15 @@
{
"class": "Full\\Qualified\\Class1",
"scope": "container",
"public": true,
"synthetic": false,
"lazy": true,
"synchronized": true,
"abstract": true,
"file": null,
"factory_class": "Full\\Qualified\\FactoryClass",
"factory_method": "get",
"tags": [

]
}
@@ -0,0 +1,9 @@
- Class: `Full\Qualified\Class1`
- Scope: `container`
- Public: yes
- Synthetic: no
- Lazy: yes
- Synchronized: yes
- Abstract: yes
- Factory Class: `Full\Qualified\FactoryClass`
- Factory Method: `get`
@@ -0,0 +1,11 @@
<comment>Service Id</comment> -
<comment>Class</comment> Full\Qualified\Class1
<comment>Tags</comment> -
<comment>Scope</comment> container
<comment>Public</comment> yes
<comment>Synthetic</comment> no
<comment>Lazy</comment> yes
<comment>Synchronized</comment> yes
<comment>Abstract</comment> yes
<comment>Factory Class</comment> Full\Qualified\FactoryClass
<comment>Factory Method</comment> get
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<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=""/>
@@ -0,0 +1,33 @@
{
"class": "Full\\Qualified\\Class2",
"scope": "container",
"public": false,
"synthetic": true,
"lazy": false,
"synchronized": false,
"abstract": false,
"file": "\/path\/to\/file",
"factory_service": "factory.service",
"factory_method": "get",
"tags": [
{
"name": "tag1",
"parameters": {
"attr1": "val1",
"attr2": "val2"
}
},
{
"name": "tag1",
"parameters": {
"attr3": "val3"
}
},
{
"name": "tag2",
"parameters": [

]
}
]
}
@@ -0,0 +1,16 @@
- Class: `Full\Qualified\Class2`
- Scope: `container`
- Public: no
- Synthetic: yes
- Lazy: no
- Synchronized: no
- Abstract: no
- File: `/path/to/file`
- Factory Service: `factory.service`
- Factory Method: `get`
- Tag: `tag1`
- Attr1: val1
- Attr2: val2
- Tag: `tag1`
- Attr3: val3
- Tag: `tag2`
@@ -0,0 +1,15 @@
<comment>Service Id</comment> -
<comment>Class</comment> Full\Qualified\Class2
<comment>Tags</comment>
- tag1 (<info>attr1</info>: val1, <info>attr2</info>: val2)
- tag1 (<info>attr3</info>: val3)
- tag2 ()
<comment>Scope</comment> container
<comment>Public</comment> no
<comment>Synthetic</comment> yes
<comment>Lazy</comment> no
<comment>Synchronized</comment> no
<comment>Abstract</comment> no
<comment>Required File</comment> /path/to/file
<comment>Factory Service</comment> factory.service
<comment>Factory Method</comment> get
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<tags>
<tag name="tag1">
<parameter name="attr1">val1</parameter>
<parameter name="attr2">val2</parameter>
</tag>
<tag name="tag1">
<parameter name="attr3">val3</parameter>
</tag>
<tag name="tag2"/>
</tags>
</definition>

0 comments on commit fbcc574

Please sign in to comment.