public getInstance ( |
||
$factory | ||
$binder |
public function getInstance(InstanceFactory $factory, Binder $binder)
{
$instance = $binder->getInstance();
if ($instance) {
return $instance;
}
$className = $binder->getBoundClassName() ?: $binder->getClassName();
$scope = $binder->getScope();
if ($scope == Scope::SINGLETON) {
return $this->singletonInstance($factory, $className);
}
if ($scope == Scope::PROTOTYPE) {
return $factory->createInstance($this, $className);
}
throw new BadMethodCallException("Unknown scope: {$scope}");
}
private function injectDependencies(InstanceRepository $repository, $instance) { $annotations = $this->provider->getMetadata($instance); $class = new ReflectionClass($instance); $properties = $class->getProperties(); foreach ($properties as $property) { $annotation = Arrays::getValue($annotations, $property->getName()); if ($annotation) { $binder = $this->bindings->getBinder($annotation['className'], $annotation['name']); $dependencyInstance = $repository->getInstance($this, $binder); $property->setAccessible(true); $property->setValue($instance, $dependencyInstance); } } }