protected function inject($target, $name, $dependency)
{
if (!is_object($target)) {
throw new \InvalidArgumentException('Wrong type for argument $target, must be object.');
}
$objectReflection = new \ReflectionObject($target);
$methodNamePart = strtoupper($name[0]) . substr($name, 1);
if ($objectReflection->hasMethod('set' . $methodNamePart)) {
$methodName = 'set' . $methodNamePart;
$target->{$methodName}($dependency);
} elseif ($objectReflection->hasMethod('inject' . $methodNamePart)) {
$methodName = 'inject' . $methodNamePart;
$target->{$methodName}($dependency);
} elseif ($objectReflection->hasProperty($name)) {
$property = $objectReflection->getProperty($name);
$property->setAccessible(true);
$property->setValue($target, $dependency);
} else {
throw new \RuntimeException('Could not inject ' . $name . ' into object of type ' . get_class($target));
}
}