PhpSpec\ServiceContainer\IndexedServiceContainer::get PHP Method

get() public method

Retrieves a service from the container
public get ( string $id ) : object
$id string
return object
    public function get($id)
    {
        if (!array_key_exists($id, $this->services)) {
            if (!array_key_exists($id, $this->definitions)) {
                throw new InvalidArgumentException(sprintf('Service "%s" is not defined.', $id));
            }
            $this->services[$id] = call_user_func($this->definitions[$id], $this);
        }
        return $this->services[$id];
    }

Usage Example

Exemplo n.º 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);
 }