private function dumpMethodParameters($className, MethodInjection $methodInjection) { $methodReflection = new \ReflectionMethod($className, $methodInjection->getMethodName()); $args = array(); foreach ($methodReflection->getParameters() as $index => $parameter) { if ($methodInjection->hasParameter($index)) { $value = $methodInjection->getParameter($index); if ($value instanceof EntryReference) { $args[] = sprintf('$%s = link(%s)', $parameter->getName(), $value->getName()); } else { $args[] = sprintf('$%s = %s', $parameter->getName(), var_export($value, true)); } continue; } // If the parameter is optional and wasn't specified, we take its default value if ($parameter->isOptional()) { try { $value = $parameter->getDefaultValue(); $args[] = sprintf('$%s = (default value) %s', $parameter->getName(), var_export($value, true)); continue; } catch (ReflectionException $e) { // The default value can't be read through Reflection because it is a PHP internal class } } $args[] = sprintf('$%s = #UNDEFINED#', $parameter->getName()); } return implode(PHP_EOL . ' ', $args); }
/** * Inject dependencies through methods. * * @param ClassDefinition $definition * @param object $object Object to inject dependencies into * @param MethodInjection $methodInjection * * @throws DependencyException * @throws DefinitionException */ private function injectMethod(ClassDefinition $definition, $object, MethodInjection $methodInjection) { $methodReflection = new ReflectionMethod($object, $methodInjection->getMethodName()); $args = $this->prepareMethodParameters($definition, $methodInjection, $methodReflection); $methodReflection->invokeArgs($object, $args); }
/** * @param MethodInjection $methodInjection */ public function addMethodInjection(MethodInjection $methodInjection) { $this->methodInjections[$methodInjection->getMethodName()] = $methodInjection; }