/** * Resolve the Component string into an Object instance. * * @param IDependencyInjectionContainer $container * @param IComponentAdapter $adapter * @return mixed */ public function resolve(IDependencyInjectionContainer $container, IComponentAdapter $adapter) { $instance = $container->getInstanceOf($this->component); if (is_null($instance)) { throw new InjecteeArgumentException("Cannot create '{$this->component}' component, reffered to by '{$adapter->getKey()}' component"); } return $instance; }
/** * Resolve arguments of ReflectionMethod by their optionality or class name. * * If argument is optional and it's default value is supplied, * use its default value. Else the argument must be a Class or Interface, * so the container is able to instantiate and provide proper values. * * @param IDependencyInjectionContainer $container * @param ReflectionMethod $method * @return array of mixed */ protected function getArgumentsOfMethod(IDependencyInjectionContainer $container, ReflectionMethod $method) { $result = array(); $parameters = $method->getParameters(); foreach ($parameters as $parameter) { if ($parameter->isOptional() || $parameter->isDefaultValueAvailable()) { $result[] = $parameter->getDefaultValue(); } else { $parameterClass = $parameter->getClass(); if (!$parameterClass) { throw new InjecteeArgumentException("Argument '{$parameter->getName()}' cannot be instantiated, it is either a Value or an Unknown type"); } $result[] = $container->getInstanceOf($parameterClass->getName()); } } return $result; }