Setup ServiceJob

@param CommandInterface $command
@param ArrayAccess $identity
@throws RuntimeException
497003
public function setup(CommandInterface $command, $identity)
    {
        if (!$identity) {
            throw new RuntimeException(
                'Unable to initialize Job: identity is not available');
        }
        
        $this->setContent([
            'context'      => $command->getContext(),
            'service'      => $command->getName(),
            'operation'    => $command->getOperation(),
            'params'       => $command->getParams()->getArrayCopy(),
            'identity'     => $identity
        ]);
    }
761302
public function execute(InputInterface $input, OutputInterface $output)
    {
        $runner = $this->commandDefinition->getRunner();
        $runner();
    }
1345120
public function init(ConnectionInterface $conn = null, $runlevel = ApplicationServerInterface::FULL)
    {

        // switch to the new runlevel
        $this->synchronized(function ($self, $newRunlevel) {
            // wait till the previous commands has been finished
            while ($self->locked === true) {
                sleep(1);
            }

            // set the command name
            $self->command = InitCommand::COMMAND;

            // lock process
            $self->locked = true;
            $self->params = $newRunlevel;

            // notify the AS to execute the command
            $self->notify();

        }, $this, $runlevel);
    }
776095
public function runCommand(Command $command, InputInterface $input, OutputInterface $output) {
    return $this->doRunCommand($command, $input, $output);
  }
715067
protected function setIsStoreAware(CommandInterface $command, array $definition)
    {
        if (isset($definition[static::CONFIG_STORES])) {
            $command->setIsStoreAware($this->getIsStoreAware($definition));
        }
    }
220411
private function startProcess(OutputInterface $output)
    {
        $arguments = $this->resolveProcessArgs();
        $name = sha1(serialize($arguments));
        if ($this->background->hasProcess($name)) {
            throw new \RuntimeException("Service is already running.");
        }

        $builder = new ProcessBuilder($arguments);

        if ($this->hasParameter('cwd')) {
            $builder->setWorkingDirectory($this->getParameter('cwd'));
        }

        $process = $builder->getProcess();

        if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) {
            $output->writeln($process->getCommandLine());
        }

        if ($this->hasParameter('output')) {
            $append = $this->hasParameter('append') && $this->getParameter('append') ? 'a' : 'w';
            $stream = fopen($this->getParameter('output'), $append);
            $output = new StreamOutput($stream, StreamOutput::VERBOSITY_NORMAL, true);
        }

        $process->start(
            function ($type, $buffer) use ($output) {
                $output->write($buffer);
            }
        );

        $this->background->addProcess($name, $process);

        if (!in_array($process->getExitCode(), $this->getParameter('successCodes'))) {
            throw new TaskRuntimeException($this->getName(), $process->getErrorOutput());
        }
    }
632971
private function setInputAndOutput(InputInterface $input, OutputInterface $output)
    {
        if (is_null($this->assistant)) {
            $this->assistant = new CommandAssistant();
            $this->assistant->setQuestionHelper($this->getQuestionHelper());
            $this->assistant->setKernel($this->getApplication()->getKernel());
        }
        $this->assistant->setOutput($output);
        $this->assistant->setInput($input);
    }
1236718
protected function handle(CommandInterface $command)
	{
		if($command instanceof SelfHandlingCommandInterface)
		{
			return $command->handle();
		}

		$handler = $this->resolveCommandHandler($command);

		return $this->executeCommandHandler($handler, $command);
	}
61921
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $verbose = OutputInterface::VERBOSITY_VERBOSE === $output->getVerbosity();
        $invoke  = $input->getOption('invoke');

        $sm                 = $this->getServiceManager()->get('ServiceManager');
        $registeredServices = $sm->getRegisteredServicesReal();

        $lines = array();
        $pad   = array(
            'id'    => 0,
            'type'  => strlen('Instance  '),
            'class' => strlen('Class name|type|alias'),
        );
        $serviceTypeToColumnName = array(
            'invokableClasses'  => 'Invokable',
            'factories'         => 'Factory',
            'aliases'           => 'Alias',
            'instances'         => 'Instance',
        );

        foreach ($registeredServices as $type => $services) {
            foreach ($services as $key => $service) {
                $lines[$key]['type'] = $serviceTypeToColumnName[$type];
                if (strlen($key) > $pad['id']) {
                    $pad['id'] = strlen($key);
                }

                if (is_object($service)) {
                    // As of PHP 5.4 you can rely on Closure being a Closure: php.net/manual/en/class.closure.php
                    if ($service instanceof \Closure) {
                        $r = new \ReflectionFunction($service);
                        if ($ns = $r->getNamespaceName()) {
                            $filename             = basename($r->getFileName(), '.php');
                            $lines[$key]['class'] = $ns . '\\' . $filename . '\{closure}';
                        } else {
                            $lines[$key]['class'] = 'Closure in ' . $r->getFileName();
                        }
                    } else {
                        $r                    = new \ReflectionObject($service);
                        $lines[$key]['class'] = $r->getName();
                    }
                } elseif (is_array($service)) {
                    $lines[$key]['class'] = 'Array';
                } elseif (is_string($service) && ($type != 'aliases')) {
                    $r                    = new \ReflectionClass($service);
                    $lines[$key]['class'] = $r->getName();
                } else { // Alias
                    $lines[$key]['class'] = $service;
                }

                $len = strlen($lines[$key]['class']);
                if ('aliases' == $type) {
                    $len += 10; // add the "alias for " prefix
                }
                if ($len > $pad['class']) {
                    $pad['class'] = $len;
                }
            }
        }

        ksort($lines);
        $output->write(sprintf('<comment>%s</comment> <comment>%s</comment> <comment>%s</comment>',
            str_pad('Service Id', $pad['id']),
            str_pad('Type', $pad['type']),
            str_pad('Class Name|Type|Alias', $pad['class'])));
        $output->writeln($invoke ? '  <comment>Invokation Status [result]</comment>' : '');
        foreach ($lines as $id => $line) {
            $output->write(sprintf('<info>%s</info> ', str_pad($id, $pad['id'])));
            $output->write(sprintf('%s ', str_pad($line['type'], $pad['type'])));
            if ('Alias' == $line['type']) {
                $output->write(sprintf('<comment>alias for</comment> <info>%s </info>', str_pad($line['class'], $pad['class'] - 10)));
            } else {
                $output->write(sprintf('%s ', str_pad($line['class'], $pad['class'])));
            }
            if ($invoke) {
                try {
                    $service = $sm->get($id);
                    $output->write(sprintf(' <info>OK</info> [%s]', is_object($service) ? get_class($service) : gettype($service)));
                } catch (\Exception $e) {
                    $output->write(' <error>FAIL</error> [' . $e->getMessage() . ']');
                }
            }
            $output->writeln('');
        }
    }
303840
public function run(CommandInterface $command, $result = null)
    {
        $key = $command->getRequestMethod() === 'GET' ? 'query' : 'body';
        $options = [$key => []];

        if(!empty($params = $command->getParams())) {
            $options[$key] = array_merge($options[$key], $params);
        }

        if($config = $this->getConfig()) {
            if(!empty($config->getSteamKey())) {
                $options[$key]['key'] = $config->getSteamKey();
            }

            $this->urlBuilder->setBaseUrl($config->getBaseSteamApiUrl());
        }

        $request = new Request(
            $command->getRequestMethod(),
            $this->urlBuilder->build($command)
        );

        return $this->client->sendAsync($request, $options);
    }
538142
protected function runCommand(InputInterface $input, OutputInterface $output)
    {
        list($appUUID, $indices) = $this->getRepositoryAndIndices($input, $output);
        $endpoints = $this->getEndpoints($input);

        $this
            ->repositoryBucket->findRepository($input->getArgument('app-name'))
            ->addToken(
                new Token(
                    TokenUUID::createById($input->getArgument('uuid')),
                    $appUUID,
                    $indices,
                    $endpoints,
                    $input->getOption('plugin'),
                    (int) $input->getOption('ttl')
                )
            );
    }
1154055
private function runCommand($arguments, ConnectionInterface $connection)
    {
        try {

            $commandClass = array_shift($arguments);

            if (null !== $this->getLogger()) {
                $this->log(
                    'Command from ' . $connection->getRemoteAddress() .
                    ": [$commandClass] " .
                    join(', ', array_map('json_encode', $arguments))
                );
            }


            if (isset($this->commands[$commandClass])) {
                $command = $this->commands[$commandClass];
            } else {

                if (!class_exists($commandClass)) {
                    throw new \RuntimeException("Command class `$commandClass` does not found.");
                }

                $command = new $commandClass($this);

                if (!$command instanceof Command\CommandInterface) {
                    throw new \RuntimeException("Every command must implement Command\\CommandInterface.");
                }

                $this->commands[$commandClass] = $command;
            }

            $result = $command->run($arguments, $connection);
            $result = [self::RESULT, $result];

        } catch (\Exception $e) {

            $result = [self::EXCEPTION, get_class($e), $e->getMessage()];
            $this->log('Exception: ' . $e->getMessage());

        }

        $connection->write(json_encode($result) . self::END_OF_RESULT);
    }
757465
protected function validateCommand(CommandInterface $command)
    {
        $this->checkCommandType($command);

        if (!$this->validator instanceof ValidatorInterface) {
            $validatorUnavailableException = new \RuntimeException('Validator is not available');
            $this->logError('Validator service unavailable', $validatorUnavailableException);
            throw $validatorUnavailableException;
        }

        $violationsList = $this->validator->validate($command);

        if (count($violationsList) > 0) {
            throw new InvalidCommandParametersException($violationsList);
        }
    }
1151786
protected function execute(InputInterface $input, OutputInterface $output)
    {
        try
        {
            if (method_exists($this, 'start'))
            {
                $this->start();
            }
            else
            {
                throw new \RuntimeException('Command is not set correctly.');
            }
        }
        catch (\Exception $e)
        {
            $this->error($e->getMessage());
        }
    }
821528
private function execute(CommandInterface $command)
    {
        $handler = $this->locator->locate($command);

        if (!$handler->supports($command)) {
            throw new InvalidCommandException(sprintf('The registered command handler doesn\'t support "%s"', get_class($command)));
        }

        $this->executing = true;

        $handler->execute($command);

        $this->executing = false;
    }
272554
public function command($command)
    {
        if ($command instanceof CommandInterface) {
            $command->setContainer($this);
        }

        $this['console']->add($command);
    }
269784
public function execute(CommandInterface $command)
    {
        $commandHandler = $this->handlerRepository->getHandler($command);

        if ($commandHandler instanceof CommandExecutorAwareInterface) {
            $commandHandler->setCommandExecutor($this);
        }

        try {
            $result = $commandHandler->handle($command);

            if (!($result instanceof CommandResultInterface)) {
                if (false === $result) {
                    $result = CommandResult::error();
                } else {
                    $result = CommandResult::success();
                }
            }
        } catch (\Exception $e) {
            if ($this->debug) {
                throw $e;
            }

            $result = CommandResult::error(null, [], $e);
        }

        $this->processMessages($command, $result);

        return $result;
    }