DI\Definition\ObjectDefinition::addMethodInjection PHP Méthode

addMethodInjection() public méthode

public addMethodInjection ( DI\Definition\ObjectDefinition\MethodInjection $methodInjection )
$methodInjection DI\Definition\ObjectDefinition\MethodInjection
    public function addMethodInjection(MethodInjection $methodInjection)
    {
        $method = $methodInjection->getMethodName();
        if (!isset($this->methodInjections[$method])) {
            $this->methodInjections[$method] = [];
        }
        $this->methodInjections[$method][] = $methodInjection;
    }

Usage Example

Exemple #1
0
 /**
  * Browse the object's methods looking for annotated methods.
  */
 private function readMethods(ReflectionClass $class, ObjectDefinition $objectDefinition)
 {
     // This will look in all the methods, including those of the parent classes
     foreach ($class->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
         if ($method->isStatic()) {
             continue;
         }
         $methodInjection = $this->getMethodInjection($method);
         if (!$methodInjection) {
             continue;
         }
         if ($method->isConstructor()) {
             $objectDefinition->setConstructorInjection($methodInjection);
         } else {
             $objectDefinition->addMethodInjection($methodInjection);
         }
     }
 }