Exemple #1
0
 /**
  * @codeCoverageIgnore
  */
 public function __toString()
 {
     if ($this->lazy) {
         return sprintf('Binding listener [lazy]: %s->%s()', $this->binding->getTypeName(), $this->methodName);
     }
     return sprintf('Binding listener: %s->%s()', $this->binding->getTypeName(), $this->methodName);
 }
 /**
  * {@inheritdoc}
  */
 public function getBound(BindingInterface $binding, InjectionPointInterface $point = NULL)
 {
     if (!$binding instanceof DelegateBinding) {
         return $this->get($binding->getTypeName(), $point);
     }
     $scope = $binding->getScope();
     if ($scope === NULL) {
         return $binding($this, $point);
     }
     $name = $binding->getTypeName();
     if (isset($this->proxies[$name])) {
         return $this->proxies[$name];
     }
     if (empty($this->scopes[$scope])) {
         throw new ScopeNotFoundException(sprintf('Scope %s of %s not found', $scope, $name));
     }
     if ($this->scopes[$scope] instanceof ProxyScopeManagerInterface) {
         return $this->proxies[$name] = $this->scopes[$scope]->createProxy($binding, $this);
     }
     return $this->proxies[$name] = $this->scopes[$scope]->lookup($name, function () use($binding) {
         return $binding($this);
     });
 }
Exemple #3
0
 /**
  * {@inheritdoc}
  */
 public function getBound(BindingInterface $binding, InjectionPointInterface $point = NULL)
 {
     $scope = $binding->getScope();
     if ($scope === NULL) {
         switch ($binding->getOptions() & BindingInterface::MASK_TYPE) {
             case BindingInterface::TYPE_ALIAS:
                 return $this->get($binding->getTarget(), $point);
             case BindingInterface::TYPE_FACTORY:
             case BindingInterface::TYPE_FACTORY_ALIAS:
                 return $this->createObjectUsingFactory($binding, $point);
             default:
                 return $this->createObject($binding->getTarget(), $binding->getResolvers(), $binding->getInitializers(), $binding->getMarkers(SetterInjection::class));
         }
     }
     $name = $binding->getTypeName();
     if (isset($this->proxies[$name])) {
         return $this->proxies[$name];
     }
     if (empty($this->scopes[$scope])) {
         throw new ScopeNotFoundException(sprintf('Scope %s of %s not found', $scope, $name));
     }
     if ($this->scopes[$scope] instanceof ProxyScopeManagerInterface) {
         return $this->proxies[$name] = $this->scopes[$scope]->createProxy($binding, $this);
     }
     switch ($binding->getOptions() & BindingInterface::MASK_TYPE) {
         case BindingInterface::TYPE_FACTORY:
         case BindingInterface::TYPE_FACTORY_ALIAS:
             return $this->proxies[$name] = $this->scopes[$scope]->lookup($name, function () use($binding) {
                 return $this->createObjectUsingFactory($binding);
             });
         default:
             return $this->proxies[$name] = $this->scopes[$scope]->lookup($name, function () use($binding) {
                 return $this->createObject($binding->getTarget(), $binding->getResolvers(), $binding->getInitializers(), $binding->getMarkers(SetterInjection::class));
             });
     }
 }
 /**
  * Register a binding in the locator, will use the name of the bound type when no
  * name for the service is given.
  * 
  * @param BindingInterface $binding The binding being used to load the service.
  * @param string $name Optional name of the registered service.
  * 
  * @throws DuplicateServiceRegistrationException
  */
 public function registerService(BindingInterface $binding, $name = NULL)
 {
     $key = $name === NULL ? $binding->getTypeName() : (string) $name;
     if (isset($this->bindings[$key])) {
         throw new DuplicateServiceRegistrationException(sprintf('Service "%s" is already registered', $key));
     }
     $this->bindings[$key] = $binding;
 }