Skip to content

Commit 2856cae

Browse files
[2.6] cleanup deprecated uses
1 parent a054bed commit 2856cae

32 files changed

+148
-110
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\DependencyInjection\ContainerBuilder;
1616
use Symfony\Component\DependencyInjection\Definition;
1717
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
18+
use Symfony\Component\DependencyInjection\Reference;
1819
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
1920
use Symfony\Component\Routing\Route;
2021
use Symfony\Component\Routing\RouteCollection;
@@ -340,6 +341,23 @@ private function getContainerDefinitionDocument(Definition $definition, $id = nu
340341
$serviceXML->setAttribute('factory-method', $definition->getFactoryMethod());
341342
}
342343

344+
if ($factory = $definition->getFactory()) {
345+
$serviceXML->appendChild($factoryXML = $dom->createElement('factory'));
346+
347+
if (is_array($factory)) {
348+
if ($factory[0] instanceof Reference) {
349+
$factoryXML->setAttribute('service', (string) $factory[0]);
350+
} elseif ($factory[0] instanceof Definition) {
351+
throw new \InvalidArgumentException('Factory is not describable.');
352+
} else {
353+
$factoryXML->setAttribute('class', $factory[0]);
354+
}
355+
$factoryXML->setAttribute('method', $factory[1]);
356+
} else {
357+
$factoryXML->setAttribute('function', $factory);
358+
}
359+
}
360+
343361
$serviceXML->setAttribute('scope', $definition->getScope());
344362
$serviceXML->setAttribute('public', $definition->isPublic() ? 'true' : 'false');
345363
$serviceXML->setAttribute('synthetic', $definition->isSynthetic() ? 'true' : 'false');

src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\DependencyInjection\ContainerBuilder;
1616
use Symfony\Component\DependencyInjection\Definition;
1717
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
18+
use Symfony\Component\DependencyInjection\Reference;
1819
use Symfony\Component\EventDispatcher\EventDispatcher;
1920
use Symfony\Component\Routing\Route;
2021
use Symfony\Component\Routing\RouteCollection;
@@ -98,8 +99,7 @@ public static function getContainerDefinitions()
9899
->setLazy(true)
99100
->setSynchronized(true)
100101
->setAbstract(true)
101-
->setFactoryClass('Full\\Qualified\\FactoryClass')
102-
->setFactoryMethod('get'),
102+
->setFactory(array('Full\\Qualified\\FactoryClass', 'get')),
103103
'definition_2' => $definition2
104104
->setPublic(false)
105105
->setSynthetic(true)
@@ -110,8 +110,7 @@ public static function getContainerDefinitions()
110110
->addTag('tag1', array('attr1' => 'val1', 'attr2' => 'val2'))
111111
->addTag('tag1', array('attr3' => 'val3'))
112112
->addTag('tag2')
113-
->setFactoryService('factory.service')
114-
->setFactoryMethod('get'),
113+
->setFactory(array(new Reference('factory.service'), 'get')),
115114
);
116115
}
117116

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
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" factory-class="Full\Qualified\FactoryClass" factory-method="get" scope="container" public="true" synthetic="false" lazy="true" synchronized="true" abstract="true" file=""/>
5+
<definition id="definition_1" class="Full\Qualified\Class1" scope="container" public="true" synthetic="false" lazy="true" synchronized="true" abstract="true" file="">
6+
<factory class="Full\Qualified\FactoryClass" method="get"/>
7+
</definition>
68
<service id="service_container" class="Symfony\Component\DependencyInjection\ContainerBuilder"/>
79
</container>

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
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" factory-class="Full\Qualified\FactoryClass" factory-method="get" scope="container" public="true" synthetic="false" lazy="true" synchronized="true" abstract="true" file=""/>
6-
<definition id="definition_2" 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">
5+
<definition id="definition_1" class="Full\Qualified\Class1" scope="container" public="true" synthetic="false" lazy="true" synchronized="true" abstract="true" file="">
6+
<factory class="Full\Qualified\FactoryClass" method="get"/>
7+
</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">
9+
<factory service="factory.service" method="get"/>
710
<tags>
811
<tag name="tag1">
912
<parameter name="attr1">val1</parameter>

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<container>
3-
<definition id="definition_2" 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">
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">
4+
<factory service="factory.service" method="get"/>
45
<tags>
56
<tag name="tag1">
67
<parameter name="attr1">val1</parameter>
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<container>
33
<tag name="tag1">
4-
<definition id="definition_2" 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"/>
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">
5+
<factory service="factory.service" method="get"/>
6+
</definition>
57
</tag>
68
<tag name="tag2">
7-
<definition id="definition_2" 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"/>
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">
10+
<factory service="factory.service" method="get"/>
11+
</definition>
812
</tag>
913
</container>
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
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" scope="container" public="true" synthetic="false" lazy="true" synchronized="true" abstract="true" file="">
3+
<factory class="Full\Qualified\FactoryClass" method="get"/>
4+
</definition>

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
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" scope="container" public="false" synthetic="true" lazy="false" synchronized="false" abstract="false" file="/path/to/file">
3+
<factory service="factory.service" method="get"/>
34
<tags>
45
<tag name="tag1">
56
<parameter name="attr1">val1</parameter>

src/Symfony/Bundle/FrameworkBundle/Tests/Templating/GlobalVariablesTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ public function setUp()
2626
$this->globals = new GlobalVariables($this->container);
2727
}
2828

29-
public function testGetSecurity()
29+
public function testLegacyGetSecurity()
3030
{
31+
$this->iniSet('error_reporting', -1 & E_USER_DEPRECATED);
32+
3133
$securityContext = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
3234

3335
$this->assertNull($this->globals->getSecurity());

src/Symfony/Component/Debug/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ if ('cli' !== php_sapi_name()) {
2424
} elseif (!ini_get('log_errors') || ini_get('error_log')) {
2525
ini_set('display_errors', 1);
2626
}
27-
ErrorHandler::register($errorReportingLevel);
27+
ErrorHandler::register();
2828
```
2929

3030
Note that the `Debug::enable()` call also registers the debug class loader

src/Symfony/Component/Debug/Tests/FatalErrorHandler/ClassNotFoundFatalErrorHandlerTest.php

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,42 +21,48 @@ class ClassNotFoundFatalErrorHandlerTest extends \PHPUnit_Framework_TestCase
2121
/**
2222
* @dataProvider provideClassNotFoundData
2323
*/
24-
public function testHandleClassNotFound($error, $translatedMessage, $autoloader = null)
24+
public function testHandleClassNotFound($error, $translatedMessage)
2525
{
26-
if ($autoloader) {
27-
// Unregister all autoloaders to ensure the custom provided
28-
// autoloader is the only one to be used during the test run.
29-
$autoloaders = spl_autoload_functions();
30-
array_map('spl_autoload_unregister', $autoloaders);
31-
spl_autoload_register($autoloader);
32-
}
33-
3426
$handler = new ClassNotFoundFatalErrorHandler();
3527

3628
$exception = $handler->handleError($error, new FatalErrorException('', 0, $error['type'], $error['file'], $error['line']));
3729

38-
if ($autoloader) {
39-
spl_autoload_unregister($autoloader);
40-
array_map('spl_autoload_register', $autoloaders);
41-
}
42-
4330
$this->assertInstanceof('Symfony\Component\Debug\Exception\ClassNotFoundException', $exception);
4431
$this->assertSame($translatedMessage, $exception->getMessage());
4532
$this->assertSame($error['type'], $exception->getSeverity());
4633
$this->assertSame($error['file'], $exception->getFile());
4734
$this->assertSame($error['line'], $exception->getLine());
4835
}
4936

50-
public function provideClassNotFoundData()
37+
/**
38+
* @dataProvider provideLegacyClassNotFoundData
39+
*/
40+
public function testLegacyHandleClassNotFound($error, $translatedMessage, $autoloader)
5141
{
52-
$prefixes = array('Symfony\Component\Debug\Exception\\' => realpath(__DIR__.'/../../Exception'));
42+
$this->iniSet('error_reporting', -1 & E_USER_DEPRECATED);
5343

54-
$symfonyAutoloader = new SymfonyClassLoader();
55-
$symfonyAutoloader->addPrefixes($prefixes);
44+
// Unregister all autoloaders to ensure the custom provided
45+
// autoloader is the only one to be used during the test run.
46+
$autoloaders = spl_autoload_functions();
47+
array_map('spl_autoload_unregister', $autoloaders);
48+
spl_autoload_register($autoloader);
5649

57-
$symfonyUniversalClassLoader = new SymfonyUniversalClassLoader();
58-
$symfonyUniversalClassLoader->registerPrefixes($prefixes);
50+
$handler = new ClassNotFoundFatalErrorHandler();
51+
52+
$exception = $handler->handleError($error, new FatalErrorException('', 0, $error['type'], $error['file'], $error['line']));
53+
54+
spl_autoload_unregister($autoloader);
55+
array_map('spl_autoload_register', $autoloaders);
56+
57+
$this->assertInstanceof('Symfony\Component\Debug\Exception\ClassNotFoundException', $exception);
58+
$this->assertSame($translatedMessage, $exception->getMessage());
59+
$this->assertSame($error['type'], $exception->getSeverity());
60+
$this->assertSame($error['file'], $exception->getFile());
61+
$this->assertSame($error['line'], $exception->getLine());
62+
}
5963

64+
public function provideClassNotFoundData()
65+
{
6066
return array(
6167
array(
6268
array(
@@ -103,6 +109,20 @@ public function provideClassNotFoundData()
103109
),
104110
"Attempted to load class \"UndefinedFunctionException\" from namespace \"Foo\Bar\".\nDid you forget a \"use\" statement for \"Symfony\Component\Debug\Exception\UndefinedFunctionException\"?",
105111
),
112+
);
113+
}
114+
115+
public function provideLegacyClassNotFoundData()
116+
{
117+
$prefixes = array('Symfony\Component\Debug\Exception\\' => realpath(__DIR__.'/../../Exception'));
118+
119+
$symfonyAutoloader = new SymfonyClassLoader();
120+
$symfonyAutoloader->addPrefixes($prefixes);
121+
122+
$symfonyUniversalClassLoader = new SymfonyUniversalClassLoader();
123+
$symfonyUniversalClassLoader->registerPrefixes($prefixes);
124+
125+
return array(
106126
array(
107127
array(
108128
'type' => 1,

src/Symfony/Component/DependencyInjection/Compiler/AnalyzeServiceReferencesPass.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,16 @@ public function process(ContainerBuilder $container)
7474
if ($definition->getFactoryService()) {
7575
$this->processArguments(array(new Reference($definition->getFactoryService())));
7676
}
77+
if (is_array($definition->getFactory())) {
78+
$this->processArguments($definition->getFactory());
79+
}
7780

7881
if (!$this->onlyConstructorArguments) {
7982
$this->processArguments($definition->getMethodCalls());
8083
$this->processArguments($definition->getProperties());
8184
if ($definition->getConfigurator()) {
8285
$this->processArguments(array($definition->getConfigurator()));
8386
}
84-
if ($definition->getFactory()) {
85-
$this->processArguments(array($definition->getFactory()));
86-
}
8787
}
8888
}
8989

@@ -115,6 +115,9 @@ private function processArguments(array $arguments)
115115
$this->processArguments($argument->getMethodCalls());
116116
$this->processArguments($argument->getProperties());
117117

118+
if (is_array($argument->getFactory())) {
119+
$this->processArguments($argument->getFactory());
120+
}
118121
if ($argument->getFactoryService()) {
119122
$this->processArguments(array(new Reference($argument->getFactoryService())));
120123
}

src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ private function isInlineableDefinition(ContainerBuilder $container, $id, Defini
144144
return false;
145145
}
146146

147+
if (count($ids) > 1 && is_array($factory = $definition->getFactory()) && ($factory[0] instanceof Reference || $factory[0] instanceof Definition)) {
148+
return false;
149+
}
150+
147151
if (count($ids) > 1 && $definition->getFactoryService()) {
148152
return false;
149153
}

src/Symfony/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPass.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,9 @@ private function resolveDefinition($id, DefinitionDecorator $definition)
8181
$def->setArguments($parentDef->getArguments());
8282
$def->setMethodCalls($parentDef->getMethodCalls());
8383
$def->setProperties($parentDef->getProperties());
84-
if (null !== $parentDef->getFactoryMethod()) {
85-
$def->setFactoryClass($parentDef->getFactoryClass());
86-
$def->setFactoryMethod($parentDef->getFactoryMethod());
87-
$def->setFactoryService($parentDef->getFactoryService());
88-
}
84+
$def->setFactoryClass($parentDef->getFactoryClass());
85+
$def->setFactoryMethod($parentDef->getFactoryMethod());
86+
$def->setFactoryService($parentDef->getFactoryService());
8987
$def->setFactory($parentDef->getFactory());
9088
$def->setConfigurator($parentDef->getConfigurator());
9189
$def->setFile($parentDef->getFile());

src/Symfony/Component/DependencyInjection/Tests/Compiler/AnalyzeServiceReferencesPassTest.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function testProcessDetectsReferencesFromInlinedFactoryDefinitions()
8787
;
8888

8989
$factory = new Definition();
90-
$factory->setFactoryService('a');
90+
$factory->setFactory(array(new Reference('a'), 'a'));
9191

9292
$container
9393
->register('b')
@@ -124,13 +124,11 @@ public function testProcessDetectsFactoryReferences()
124124

125125
$container
126126
->register('foo', 'stdClass')
127-
->setFactoryClass('stdClass')
128-
->setFactoryMethod('getInstance');
127+
->setFactory(array('stdClass', 'getInstance'));
129128

130129
$container
131130
->register('bar', 'stdClass')
132-
->setFactoryService('foo')
133-
->setFactoryMethod('getInstance');
131+
->setFactory(array(new Reference('foo'), 'getInstance'));
134132

135133
$graph = $this->process($container);
136134

src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckCircularReferencesPassTest.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,11 @@ public function testProcessWithFactory()
5353

5454
$container
5555
->register('a', 'stdClass')
56-
->setFactoryService('b')
57-
->setFactoryMethod('getInstance');
56+
->setFactory(array(new Reference('b'), 'getInstance'));
5857

5958
$container
6059
->register('b', 'stdClass')
61-
->setFactoryService('a')
62-
->setFactoryMethod('getInstance');
60+
->setFactory(array(new Reference('a'), 'getInstance'));
6361

6462
$this->process($container);
6563
}
@@ -88,8 +86,7 @@ public function testProcessDetectsIndirectCircularReferenceWithFactory()
8886

8987
$container
9088
->register('b', 'stdClass')
91-
->setFactoryService('c')
92-
->setFactoryMethod('getInstance');
89+
->setFactory(array(new Reference('c'), 'getInstance'));
9390

9491
$container->register('c')->addArgument(new Reference('a'));
9592

src/Symfony/Component/DependencyInjection/Tests/Compiler/InlineServiceDefinitionsPassTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public function testProcessInlinesPrivateFactoryReference()
118118
$b = $container
119119
->register('b')
120120
->setPublic(false)
121-
->setFactoryService('a')
121+
->setFactory(array(new Reference('a'), 'a'))
122122
;
123123

124124
$container
@@ -142,7 +142,7 @@ public function testProcessDoesNotInlinePrivateFactoryIfReferencedMultipleTimesW
142142
$container
143143
->register('b')
144144
->setPublic(false)
145-
->setFactoryService('a')
145+
->setFactory(array(new Reference('a'), 'a'))
146146
;
147147

148148
$container
@@ -168,12 +168,12 @@ public function testProcessDoesNotInlineReferenceWhenUsedByInlineFactory()
168168
$container
169169
->register('b')
170170
->setPublic(false)
171-
->setFactoryService('a')
171+
->setFactory(array(new Reference('a'), 'a'))
172172
;
173173

174174
$inlineFactory = new Definition();
175175
$inlineFactory->setPublic(false);
176-
$inlineFactory->setFactoryService('b');
176+
$inlineFactory->setFactory(array(new Reference('b'), 'b'));
177177

178178
$container
179179
->register('foo')

src/Symfony/Component/DependencyInjection/Tests/Compiler/RemoveUnusedDefinitionsPassTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,12 @@ public function testProcessWontRemovePrivateFactory()
8686

8787
$container
8888
->register('foo', 'stdClass')
89-
->setFactoryClass('stdClass')
90-
->setFactoryMethod('getInstance')
89+
->setFactory(array('stdClass', 'getInstance'))
9190
->setPublic(false);
9291

9392
$container
9493
->register('bar', 'stdClass')
95-
->setFactoryService('foo')
96-
->setFactoryMethod('getInstance')
94+
->setFactory(array(new Reference('foo'), 'getInstance'))
9795
->setPublic(false);
9896

9997
$container

0 commit comments

Comments
 (0)