diff --git a/Generator/DefinitionInjectorGenerator.php b/Generator/DefinitionInjectorGenerator.php index 0238e5c..3c97a1d 100644 --- a/Generator/DefinitionInjectorGenerator.php +++ b/Generator/DefinitionInjectorGenerator.php @@ -109,10 +109,6 @@ public function generate(Definition $def, $className, $targetPath) } } - if (method_exists($def, 'getInitMethod') && $def->getInitMethod()) { - $writer->writeln('$instance->'.$def->getInitMethod().'();'); - } - $writer ->writeln('return $instance;') ->outdent() diff --git a/Metadata/ClassMetadata.php b/Metadata/ClassMetadata.php index 2814377..4a250e2 100644 --- a/Metadata/ClassMetadata.php +++ b/Metadata/ClassMetadata.php @@ -35,7 +35,11 @@ class ClassMetadata extends BaseClassMetadata public $methodCalls = array(); public $lookupMethods = array(); public $properties = array(); + /** + * @deprecated since version 1.7, to be removed in 2.0. Use $initMethods instead. + */ public $initMethod; + public $initMethods = array(); public $environments = array(); public $decorates; public $decoration_inner_name; diff --git a/Metadata/Driver/AnnotationDriver.php b/Metadata/Driver/AnnotationDriver.php index 28da6ed..3efc9fa 100644 --- a/Metadata/Driver/AnnotationDriver.php +++ b/Metadata/Driver/AnnotationDriver.php @@ -209,6 +209,7 @@ public function loadMetadataForClass(\ReflectionClass $class) } $metadata->initMethod = $method->name; + $metadata->initMethods[] = $method->name; } else if ($annot instanceof MetadataProcessorInterface) { if (null === $metadata->id) { $metadata->id = $this->namingStrategy->classToServiceName($className); diff --git a/Metadata/MetadataConverter.php b/Metadata/MetadataConverter.php index a7c3174..2010413 100644 --- a/Metadata/MetadataConverter.php +++ b/Metadata/MetadataConverter.php @@ -86,12 +86,13 @@ public function convert(ClassHierarchyMetadata $metadata) $classMetadata->id = '_jms_di_extra.unnamed.service_'.$count++; } - if ($classMetadata->initMethod) { - if (!method_exists($definition, 'setInitMethod')) { - throw new \RuntimeException(sprintf('@AfterSetup is not available on your Symfony version.')); + if (0 !== count($classMetadata->initMethods)) { + foreach ($classMetadata->initMethods as $initMethod) { + $definition->addMethodCall($initMethod); } - - $definition->setInitMethod($classMetadata->initMethod); + } elseif (null !== $classMetadata->initMethod) { + @trigger_error('ClassMetadata::$initMethod is deprecated since version 1.7 and will be removed in 2.0. Use ClassMetadata::$initMethods instead.', E_USER_DEPRECATED); + $definition->addMethodCall($classMetadata->initMethod); } $definitions[$classMetadata->id] = $definition;