Ouzo\Injection\InstanceRepository::getInstance PHP Method

getInstance() public method

public getInstance ( InstanceFactory $factory, Binder $binder )
$factory InstanceFactory
$binder 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}");
    }

Usage Example

Exemplo n.º 1
0
 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);
         }
     }
 }
All Usage Examples Of Ouzo\Injection\InstanceRepository::getInstance