Exemplo n.º 1
0
 /**
  * Replaces object in the container.
  *
  * @param string   $service_id Name of the object in the container.
  * @param callable $callable   The callable that will return the object.
  * @param boolean  $is_factory The callable should be considered as a factory.
  *
  * @return callable Previous service version.
  * @throws \InvalidArgumentException When attempt is made to replace non-existing service.
  */
 public function replaceObject($service_id, $callable, $is_factory = false)
 {
     if (!isset($this->container[$service_id])) {
         throw new \InvalidArgumentException('Service "' . $service_id . '" not found');
     }
     $backup = $this->container->raw($service_id);
     unset($this->container[$service_id]);
     $this->container[$service_id] = $is_factory ? $this->container->factory($callable) : $callable;
     return $backup;
 }
Exemplo n.º 2
0
 /**
  * Creates container for testing.
  *
  * @return void
  */
 protected function setUp()
 {
     parent::setUp();
     $this->_container = new DIContainer();
     $this->_container->setApplication(new Application());
 }