/**
  * Sets a service.
  *
  * @param string $id      The service identifier
  * @param object $service The service instance
  *
  * @return void
  *
  * @api
  * @since 3.1.0
  */
 public function set($id, $service)
 {
     if ($this->isFrozen()) {
         throw new BadMethodCallException('Cannot set a service on a frozen container');
     }
     $this->_delegate->set($id, $service);
 }
Esempio n. 2
0
 /**
  * Sets a service.
  *
  * @param string $id      The service identifier
  * @param object $service The service instance
  * @param string $scope   The scope
  *
  * @throws ehough_iconic_exception_BadMethodCallException When this ContainerBuilder is frozen
  *
  * @api
  */
 public function set($id, $service, $scope = self::SCOPE_CONTAINER)
 {
     $id = strtolower($id);
     if ($this->isFrozen()) {
         // setting a synthetic service on a frozen container is alright
         if (!isset($this->definitions[$id]) && !isset($this->obsoleteDefinitions[$id]) || isset($this->definitions[$id]) && !$this->definitions[$id]->isSynthetic() || isset($this->obsoleteDefinitions[$id]) && !$this->obsoleteDefinitions[$id]->isSynthetic()) {
             throw new ehough_iconic_exception_BadMethodCallException(sprintf('Setting service "%s" on a frozen container is not allowed.', $id));
         }
     }
     if (isset($this->definitions[$id])) {
         $this->obsoleteDefinitions[$id] = $this->definitions[$id];
     }
     unset($this->definitions[$id], $this->aliasDefinitions[$id]);
     parent::set($id, $service, $scope);
     if (isset($this->obsoleteDefinitions[$id]) && $this->obsoleteDefinitions[$id]->isSynchronized()) {
         $this->synchronize($id);
     }
 }