From 998dedf7883627ebd434583702402aa0086a5bc8 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 6 Jan 2015 19:57:38 +0100 Subject: [PATCH] [2.7] silence deprecations for getFactory*() BC layer --- .../Console/Descriptor/XmlDescriptor.php | 18 ++++++----- .../Compiler/AnalyzeServiceReferencesPass.php | 8 ++--- .../Compiler/CheckDefinitionValidityPass.php | 4 +-- .../Compiler/InlineServiceDefinitionsPass.php | 2 +- .../ResolveDefinitionTemplatesPass.php | 18 +++++++---- .../DependencyInjection/ContainerBuilder.php | 12 +++---- .../DependencyInjection/Definition.php | 18 +++++++---- .../DependencyInjection/Dumper/PhpDumper.php | 32 +++++++++---------- .../DependencyInjection/Dumper/XmlDumper.php | 12 +++---- .../DependencyInjection/Dumper/YamlDumper.php | 12 +++---- 10 files changed, 75 insertions(+), 61 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php index 489b446512d7b..f773674832552 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php @@ -329,16 +329,18 @@ private function getContainerDefinitionDocument(Definition $definition, $id = nu $serviceXML->setAttribute('class', $definition->getClass()); - if ($definition->getFactoryClass()) { - $serviceXML->setAttribute('factory-class', $definition->getFactoryClass()); - } + if (method_exists($definition, 'getFactoryMethod')) { + if ($definition->getFactoryClass(false)) { + $serviceXML->setAttribute('factory-class', $definition->getFactoryClass(false)); + } - if ($definition->getFactoryService()) { - $serviceXML->setAttribute('factory-service', $definition->getFactoryService()); - } + if ($definition->getFactoryService(false)) { + $serviceXML->setAttribute('factory-service', $definition->getFactoryService(false)); + } - if ($definition->getFactoryMethod()) { - $serviceXML->setAttribute('factory-method', $definition->getFactoryMethod()); + if ($definition->getFactoryMethod(false)) { + $serviceXML->setAttribute('factory-method', $definition->getFactoryMethod(false)); + } } if ($factory = $definition->getFactory()) { diff --git a/src/Symfony/Component/DependencyInjection/Compiler/AnalyzeServiceReferencesPass.php b/src/Symfony/Component/DependencyInjection/Compiler/AnalyzeServiceReferencesPass.php index c5ecb2d5040b5..5120eb6215c1a 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/AnalyzeServiceReferencesPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/AnalyzeServiceReferencesPass.php @@ -71,8 +71,8 @@ public function process(ContainerBuilder $container) $this->currentDefinition = $definition; $this->processArguments($definition->getArguments()); - if ($definition->getFactoryService()) { - $this->processArguments(array(new Reference($definition->getFactoryService()))); + if ($definition->getFactoryService(false)) { + $this->processArguments(array(new Reference($definition->getFactoryService(false)))); } if (is_array($definition->getFactory())) { $this->processArguments($definition->getFactory()); @@ -118,8 +118,8 @@ private function processArguments(array $arguments) if (is_array($argument->getFactory())) { $this->processArguments($argument->getFactory()); } - if ($argument->getFactoryService()) { - $this->processArguments(array(new Reference($argument->getFactoryService()))); + if ($argument->getFactoryService(false)) { + $this->processArguments(array(new Reference($argument->getFactoryService(false)))); } } } diff --git a/src/Symfony/Component/DependencyInjection/Compiler/CheckDefinitionValidityPass.php b/src/Symfony/Component/DependencyInjection/Compiler/CheckDefinitionValidityPass.php index ce89f24e183e3..219e66313d13b 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/CheckDefinitionValidityPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/CheckDefinitionValidityPass.php @@ -50,13 +50,13 @@ public function process(ContainerBuilder $container) throw new RuntimeException(sprintf('A synthetic service ("%s") cannot be of scope "prototype".', $id)); } - if ($definition->getFactory() && ($definition->getFactoryClass() || $definition->getFactoryService() || $definition->getFactoryMethod())) { + if ($definition->getFactory() && ($definition->getFactoryClass(false) || $definition->getFactoryService(false) || $definition->getFactoryMethod(false))) { throw new RuntimeException(sprintf('A service ("%s") can use either the old or the new factory syntax, not both.', $id)); } // non-synthetic, non-abstract service has class if (!$definition->isAbstract() && !$definition->isSynthetic() && !$definition->getClass()) { - if ($definition->getFactory() || $definition->getFactoryClass() || $definition->getFactoryService()) { + if ($definition->getFactory() || $definition->getFactoryClass(false) || $definition->getFactoryService(false)) { throw new RuntimeException(sprintf('Please add the class to service "%s" even if it is constructed by a factory since we might need to add method calls based on compile-time checks.', $id)); } diff --git a/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php b/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php index 9d3a7814202ca..026700d2263d6 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php @@ -148,7 +148,7 @@ private function isInlineableDefinition(ContainerBuilder $container, $id, Defini return false; } - if (count($ids) > 1 && $definition->getFactoryService()) { + if (count($ids) > 1 && $definition->getFactoryService(false)) { return false; } diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPass.php b/src/Symfony/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPass.php index c1db3e04d6bbc..b0f970cb8b69e 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPass.php @@ -81,9 +81,15 @@ private function resolveDefinition($id, DefinitionDecorator $definition) $def->setArguments($parentDef->getArguments()); $def->setMethodCalls($parentDef->getMethodCalls()); $def->setProperties($parentDef->getProperties()); - $def->setFactoryClass($parentDef->getFactoryClass()); - $def->setFactoryMethod($parentDef->getFactoryMethod()); - $def->setFactoryService($parentDef->getFactoryService()); + if ($parentDef->getFactoryClass(false)) { + $def->setFactoryClass($parentDef->getFactoryClass(false)); + } + if ($parentDef->getFactoryMethod(false)) { + $def->setFactoryMethod($parentDef->getFactoryMethod(false)); + } + if ($parentDef->getFactoryService(false)) { + $def->setFactoryService($parentDef->getFactoryService(false)); + } $def->setFactory($parentDef->getFactory()); $def->setConfigurator($parentDef->getConfigurator()); $def->setFile($parentDef->getFile()); @@ -96,13 +102,13 @@ private function resolveDefinition($id, DefinitionDecorator $definition) $def->setClass($definition->getClass()); } if (isset($changes['factory_class'])) { - $def->setFactoryClass($definition->getFactoryClass()); + $def->setFactoryClass($definition->getFactoryClass(false)); } if (isset($changes['factory_method'])) { - $def->setFactoryMethod($definition->getFactoryMethod()); + $def->setFactoryMethod($definition->getFactoryMethod(false)); } if (isset($changes['factory_service'])) { - $def->setFactoryService($definition->getFactoryService()); + $def->setFactoryService($definition->getFactoryService(false)); } if (isset($changes['factory'])) { $def->setFactory($definition->getFactory()); diff --git a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php index e2b1761e6b898..dc1a73d111a9a 100644 --- a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php +++ b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php @@ -948,16 +948,16 @@ public function createService(Definition $definition, $id, $tryProxy = true) } $service = call_user_func_array($factory, $arguments); - } elseif (null !== $definition->getFactoryMethod()) { - if (null !== $definition->getFactoryClass()) { - $factory = $parameterBag->resolveValue($definition->getFactoryClass()); - } elseif (null !== $definition->getFactoryService()) { - $factory = $this->get($parameterBag->resolveValue($definition->getFactoryService())); + } elseif (null !== $definition->getFactoryMethod(false)) { + if (null !== $definition->getFactoryClass(false)) { + $factory = $parameterBag->resolveValue($definition->getFactoryClass(false)); + } elseif (null !== $definition->getFactoryService(false)) { + $factory = $this->get($parameterBag->resolveValue($definition->getFactoryService(false))); } else { throw new RuntimeException(sprintf('Cannot create service "%s" from factory method without a factory service or factory class.', $id)); } - $service = call_user_func_array(array($factory, $definition->getFactoryMethod()), $arguments); + $service = call_user_func_array(array($factory, $definition->getFactoryMethod(false)), $arguments); } else { $r = new \ReflectionClass($parameterBag->resolveValue($definition->getClass())); diff --git a/src/Symfony/Component/DependencyInjection/Definition.php b/src/Symfony/Component/DependencyInjection/Definition.php index 97cd849dda9bf..446d13aa2be22 100644 --- a/src/Symfony/Component/DependencyInjection/Definition.php +++ b/src/Symfony/Component/DependencyInjection/Definition.php @@ -113,9 +113,11 @@ public function setFactoryClass($factoryClass) * @api * @deprecated since version 2.6, to be removed in 3.0. */ - public function getFactoryClass() + public function getFactoryClass($triggerDeprecationError = true) { - trigger_error('The '.__METHOD__.' is deprecated since version 2.6 and will be removed in 3.0.', E_USER_DEPRECATED); + if ($triggerDeprecationError) { + trigger_error('The '.__METHOD__.' is deprecated since version 2.6 and will be removed in 3.0.', E_USER_DEPRECATED); + } return $this->factoryClass; } @@ -182,9 +184,11 @@ public function getDecoratedService() * @api * @deprecated since version 2.6, to be removed in 3.0. */ - public function getFactoryMethod() + public function getFactoryMethod($triggerDeprecationError = true) { - trigger_error('The '.__METHOD__.' is deprecated since version 2.6 and will be removed in 3.0.', E_USER_DEPRECATED); + if ($triggerDeprecationError) { + trigger_error('The '.__METHOD__.' is deprecated since version 2.6 and will be removed in 3.0.', E_USER_DEPRECATED); + } return $this->factoryMethod; } @@ -216,9 +220,11 @@ public function setFactoryService($factoryService) * @api * @deprecated since version 2.6, to be removed in 3.0. */ - public function getFactoryService() + public function getFactoryService($triggerDeprecationError = true) { - trigger_error('The '.__METHOD__.' is deprecated since version 2.6 and will be removed in 3.0.', E_USER_DEPRECATED); + if ($triggerDeprecationError) { + trigger_error('The '.__METHOD__.' is deprecated since version 2.6 and will be removed in 3.0.', E_USER_DEPRECATED); + } return $this->factoryService; } diff --git a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php index 6e2369144e636..caa5641671f7e 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php @@ -572,10 +572,10 @@ private function addService($id, $definition) $return[] = sprintf('@return object An instance returned by %s::%s().', $factory[0]->getClass(), $factory[1]); } } - } elseif ($definition->getFactoryClass()) { - $return[] = sprintf('@return object An instance returned by %s::%s().', $definition->getFactoryClass(), $definition->getFactoryMethod()); - } elseif ($definition->getFactoryService()) { - $return[] = sprintf('@return object An instance returned by %s::%s().', $definition->getFactoryService(), $definition->getFactoryMethod()); + } elseif ($definition->getFactoryClass(false)) { + $return[] = sprintf('@return object An instance returned by %s::%s().', $definition->getFactoryClass(false), $definition->getFactoryMethod(false)); + } elseif ($definition->getFactoryService(false)) { + $return[] = sprintf('@return object An instance returned by %s::%s().', $definition->getFactoryService(false), $definition->getFactoryMethod(false)); } $scope = $definition->getScope(); @@ -768,20 +768,20 @@ private function addNewInstance($id, Definition $definition, $return, $instantia } return sprintf(" $return{$instantiation}\\%s(%s);\n", $callable, $arguments ? implode(', ', $arguments) : ''); - } elseif (null !== $definition->getFactoryMethod()) { - if (null !== $definition->getFactoryClass()) { - $class = $this->dumpValue($definition->getFactoryClass()); + } elseif (null !== $definition->getFactoryMethod(false)) { + if (null !== $definition->getFactoryClass(false)) { + $class = $this->dumpValue($definition->getFactoryClass(false)); // If the class is a string we can optimize call_user_func away if (strpos($class, "'") === 0) { - return sprintf(" $return{$instantiation}%s::%s(%s);\n", $this->dumpLiteralClass($class), $definition->getFactoryMethod(), $arguments ? implode(', ', $arguments) : ''); + return sprintf(" $return{$instantiation}%s::%s(%s);\n", $this->dumpLiteralClass($class), $definition->getFactoryMethod(false), $arguments ? implode(', ', $arguments) : ''); } - return sprintf(" $return{$instantiation}call_user_func(array(%s, '%s')%s);\n", $this->dumpValue($definition->getFactoryClass()), $definition->getFactoryMethod(), $arguments ? ', '.implode(', ', $arguments) : ''); + return sprintf(" $return{$instantiation}call_user_func(array(%s, '%s')%s);\n", $this->dumpValue($definition->getFactoryClass(false)), $definition->getFactoryMethod(false), $arguments ? ', '.implode(', ', $arguments) : ''); } - if (null !== $definition->getFactoryService()) { - return sprintf(" $return{$instantiation}%s->%s(%s);\n", $this->getServiceCall($definition->getFactoryService()), $definition->getFactoryMethod(), implode(', ', $arguments)); + if (null !== $definition->getFactoryService(false)) { + return sprintf(" $return{$instantiation}%s->%s(%s);\n", $this->getServiceCall($definition->getFactoryService(false)), $definition->getFactoryMethod(false), implode(', ', $arguments)); } throw new RuntimeException(sprintf('Factory method requires a factory service or factory class in service definition for %s', $id)); @@ -1328,11 +1328,11 @@ private function dumpValue($value, $interpolate = true) throw new RuntimeException('Cannot dump definition because of invalid factory'); } - if (null !== $value->getFactoryMethod()) { - if (null !== $value->getFactoryClass()) { - return sprintf("call_user_func(array(%s, '%s')%s)", $this->dumpValue($value->getFactoryClass()), $value->getFactoryMethod(), count($arguments) > 0 ? ', '.implode(', ', $arguments) : ''); - } elseif (null !== $value->getFactoryService()) { - return sprintf("%s->%s(%s)", $this->getServiceCall($value->getFactoryService()), $value->getFactoryMethod(), implode(', ', $arguments)); + if (null !== $value->getFactoryMethod(false)) { + if (null !== $value->getFactoryClass(false)) { + return sprintf("call_user_func(array(%s, '%s')%s)", $this->dumpValue($value->getFactoryClass(false)), $value->getFactoryMethod(false), count($arguments) > 0 ? ', '.implode(', ', $arguments) : ''); + } elseif (null !== $value->getFactoryService(false)) { + return sprintf("%s->%s(%s)", $this->getServiceCall($value->getFactoryService(false)), $value->getFactoryMethod(false), implode(', ', $arguments)); } else { throw new RuntimeException('Cannot dump definitions which have factory method without factory service or factory class.'); } diff --git a/src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php index 5fed552ea98cd..1d19b2c862e52 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php @@ -117,14 +117,14 @@ private function addService($definition, $id, \DOMElement $parent) if ($definition->getClass()) { $service->setAttribute('class', $definition->getClass()); } - if ($definition->getFactoryMethod()) { - $service->setAttribute('factory-method', $definition->getFactoryMethod()); + if ($definition->getFactoryMethod(false)) { + $service->setAttribute('factory-method', $definition->getFactoryMethod(false)); } - if ($definition->getFactoryClass()) { - $service->setAttribute('factory-class', $definition->getFactoryClass()); + if ($definition->getFactoryClass(false)) { + $service->setAttribute('factory-class', $definition->getFactoryClass(false)); } - if ($definition->getFactoryService()) { - $service->setAttribute('factory-service', $definition->getFactoryService()); + if ($definition->getFactoryService(false)) { + $service->setAttribute('factory-service', $definition->getFactoryService(false)); } if (ContainerInterface::SCOPE_CONTAINER !== $scope = $definition->getScope()) { $service->setAttribute('scope', $scope); diff --git a/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php index 25f6b2dfe7b4b..a7ed2e8064b44 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php @@ -107,20 +107,20 @@ private function addService($id, $definition) $code .= sprintf(" synchronized: true\n"); } - if ($definition->getFactoryClass()) { - $code .= sprintf(" factory_class: %s\n", $definition->getFactoryClass()); + if ($definition->getFactoryClass(false)) { + $code .= sprintf(" factory_class: %s\n", $definition->getFactoryClass(false)); } if ($definition->isLazy()) { $code .= sprintf(" lazy: true\n"); } - if ($definition->getFactoryMethod()) { - $code .= sprintf(" factory_method: %s\n", $definition->getFactoryMethod()); + if ($definition->getFactoryMethod(false)) { + $code .= sprintf(" factory_method: %s\n", $definition->getFactoryMethod(false)); } - if ($definition->getFactoryService()) { - $code .= sprintf(" factory_service: %s\n", $definition->getFactoryService()); + if ($definition->getFactoryService(false)) { + $code .= sprintf(" factory_service: %s\n", $definition->getFactoryService(false)); } if ($definition->getArguments()) {