PhpSpec\ServiceContainer\IndexedServiceContainer::set PHP Method

set() public method

Sets a object to be used as a service
public set ( string $id, object $service, array $tags = [] )
$id string
$service object
$tags array
    public function set($id, $service, $tags = [])
    {
        if (!is_object($service)) {
            throw new InvalidArgumentException(sprintf('Service should be an object, but %s given.', gettype($service)));
        }
        $this->services[$id] = $service;
        unset($this->definitions[$id]);
        $this->indexTags($id, $tags);
    }

Usage Example

Example #1
0
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return int
  */
 public function doRun(InputInterface $input, OutputInterface $output)
 {
     $helperSet = $this->getHelperSet();
     $this->container->set('console.input', $input);
     $this->container->set('console.output', $output);
     $this->container->set('console.helper_set', $helperSet);
     $this->container->define('process.executioncontext', function () {
         return JsonExecutionContext::fromEnv($_SERVER);
     });
     $assembler = new ContainerAssembler();
     $assembler->build($this->container);
     $this->loadConfigurationFile($input, $this->container);
     foreach ($this->container->getByTag('console.commands') as $command) {
         $this->add($command);
     }
     $this->setDispatcher($this->container->get('console_event_dispatcher'));
     $this->container->get('console.io')->setConsoleWidth($this->getTerminalWidth());
     StreamWrapper::reset();
     foreach ($this->container->getByTag('loader.resource_loader.spec_transformer') as $transformer) {
         StreamWrapper::addTransformer($transformer);
     }
     StreamWrapper::register();
     return parent::doRun($input, $output);
 }