Skip to content

Commit

Permalink
Merge pull request schmittjoh#243 from schmittjoh/AFTERSETUP
Browse files Browse the repository at this point in the history
  • Loading branch information
GuilhemN committed Feb 16, 2016
2 parents c3a278a + 60ca64f commit d496296
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
4 changes: 0 additions & 4 deletions Generator/DefinitionInjectorGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions Metadata/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions Metadata/Driver/AnnotationDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 6 additions & 5 deletions Metadata/MetadataConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit d496296

Please sign in to comment.