Asks a question to the user.

@return mixed The user answer

@throws RuntimeException If there is no data to read in the input stream
198861
public function ask(InputInterface $input, OutputInterface $output, Question $question)
    {
        if ($output instanceof ConsoleOutputInterface) {
            $output = $output->getErrorOutput();
        }

        if (!$input->isInteractive()) {
            $default = $question->getDefault();

            if (null === $default) {
                return $default;
            }

            if ($validator = $question->getValidator()) {
                return \call_user_func($question->getValidator(), $default);
            } elseif ($question instanceof ChoiceQuestion) {
                $choices = $question->getChoices();

                if (!$question->isMultiselect()) {
                    return isset($choices[$default]) ? $choices[$default] : $default;
                }

                $default = explode(',', $default);
                foreach ($default as $k => $v) {
                    $v = trim($v);
                    $default[$k] = isset($choices[$v]) ? $choices[$v] : $v;
                }
            }

            return $default;
        }

        if ($input instanceof StreamableInputInterface && $stream = $input->getStream()) {
            $this->inputStream = $stream;
        }

        if (!$question->getValidator()) {
            return $this->doAsk($output, $question);
        }

        $interviewer = function () use ($output, $question) {
            return $this->doAsk($output, $question);
        };

        return $this->validateAttempts($interviewer, $output, $question);
    }
276026
public function searchUsersAction()
    {
        if (!$this->getRequest()->isXmlHttpRequest()) {
            throw new \RuntimeException('This action must be called via ajax request');
        }
        
        $model = new JsonModel();
        $query = $this->params()->fromPost('query', false);
        if (!$query) {
            $query = $this->params()->fromQuery('q', false);
        }
        if (false === $query) {
            $result = array();
        } else {
            $repositories = $this->repositories;
            $repository   = $repositories->get('Auth/User');
            
            $users = $repository->findByQuery($query);
        
            $userFilter = $this->filterManager->get('Auth/Entity/UserToSearchResult');
            $filterFunc = function ($user) use ($userFilter) {
                return $userFilter->filter($user);
            };
            $result     = array_values(array_map($filterFunc, $users->toArray()));
        }
        
        //$model->setVariable('users', $result);
        $model->setVariables($result);
        return $model;
    }
1050753
public function create()
    {
        if ($this->getIsNewRecord() == false) {
            throw new \RuntimeException('Calling "' . __CLASS__ . '::' . __METHOD__ . '" on existing user');
        }
        if ($this->scenario == self::SCENARIO_CREATE_MOBILE) {
            $this->mobile_confirmed_at = time();
        }

        $this->password = $this->password == null ? Password::generate(8) : $this->password;
        $this->trigger(self::BEFORE_CREATE);
        if (!$this->save()) {
            return false;
        }
        //$this->module->sendMessage($this->email, Yii::t('user', 'Welcome to {0}', Yii::$app->name), 'welcome', ['user' => $this, 'token' => null, 'module' => $this->module, 'showPassword' => true]);
        $this->trigger(self::AFTER_CREATE);
        return true;
    }
993296
public function json()
    {
        $json = json_decode($this->getBody(), true);
        if ($json === null) {
            throw new RuntimeException(sprintf(
                "Can't decode response as JSON: %s",
                function_exists('json_last_error_msg')?
                    json_last_error_msg():
                    'Error code '.json_last_error()
            ));
        }
        return $json;
    }
598752
public function asQuestion()
    {
        $instance = $this->questionClassInstance()
            ->setMaxAttempts($this->maxAttempt);

        // Set question instance hidden if defined by the field.
        if ($this->hidden) {
            $instance->setHidden(true);
        }

        // Set validation callback if field is required.
        if ($this->isRequire()) {
            $this->setValidation(function ($answer) {
                if ($answer == ''
                    && $this->dataType() !== 'boolean') {
                    throw new \Exception('Field is required.');
                }
            });
        }

        // Set question instance validator callback.
        $instance->setValidator(function ($answer) {

            // Iterate over all field validation callbacks.
            foreach ($this->validation as $callback) {
                if (!is_callable($callback)) {
                    continue;
                }

                $callback($answer);
            }

            return $answer;
        });

        // Set question normalizer based on the field normalizer. If a default
        // normalizer is being set from the question class then setting the
        // normalizer will trump it's execution, as only one normalizer can be
        // set per question instance.
        if (isset($this->normalizer)
            && is_callable($this->normalizer)) {
            $instance->setNormalizer($this->normalizer);
        }

        return $instance;
    }
718494
public function indexAction()
    {
        $request = $this->getRequest();
        $type    = $request->getParam( 'type' );

        if ( ! $request instanceof ConsoleRequest )
        {
            throw new \RuntimeException( sprintf(
                '%s can only be used from a console.',
                __METHOD__
            ) );
        }

        $phpSelf = realpath( static::PHP_SELF );

        if ( empty( $phpSelf ) || ! is_file( $phpSelf ) )
        {
            throw new \RuntimeException( sprintf(
                '%s: php not found at "%s" (in "%s").',
                __METHOD__,
                static::PHP_SELF,
                getcwd()
            ) );
        }

        $result = 'Running ' . $type . ' cron(s) ...' . PHP_EOL . PHP_EOL;

        foreach ( $this->mimicSiteInfos() as $siteInfo )
        {
            $domain  = $siteInfo->getDomain();
            $process = new Process( array(
                'command'   => 'php',
                'arguments' => array(
                    $phpSelf,
                    'cron',
                    $domain,
                    $type,
                ),
                'environmentVariables'  => array(
                    'GRIDGUYZ_HOST'     => $domain,
                    'HTTP_HOST'         => $domain,
                ),
            ) );

            $result .= 'Calling process ...' . PHP_EOL .
                       $process->getRunCommand() . PHP_EOL;

            $output = tempnam( './data/', $domain );
            $descr  = array( Process::TYPE_FILE, $output, Process::MODE_APPEND );
            file_put_contents( $output, '' );

            $process->open( array(
                Process::STREAM_STDOUT => $descr,
                Process::STREAM_STDERR => $descr,
            ) );

            $return     = $process->close();
            $messages   = rtrim( file_get_contents( $output ), PHP_EOL );
            unlink( $output );

            if ( $messages )
            {
                $result .= static::PADDING . preg_replace(
                    '/[' . PHP_EOL . ']+/',
                    '$0' . static::PADDING,
                    $messages
                ) . PHP_EOL;
            }

            $result .= sprintf(
                'Process returned with #%d: %s' . PHP_EOL . PHP_EOL,
                $return,
                $return ? 'error!' : 'success.'
            );
        }

        $result .= 'Done.' . PHP_EOL;
        return $result;
    }
509480
public function getResponse()
    {
        if (is_null($this->response)) {
            $this->response = $this->getRunner()->run();
        }
        return $this->response;
    }
322280
private function getQuestionData()
    {
        $configuration = $this->questionInteract->getUserConfiguration();
        $data = $configuration->getAnswers()->get($this->questionInteract->getCurrentQuestion());

        return is_null($data) ? array() : $data;
    }
776067
public function execute()
    {
        $statement = $this->getPdoStatement();
        $result = $statement->execute($this->bindings);
        if (!$result) {
            $errorInfo = $statement->errorInfo();
            throw new RuntimeException(
                $errorInfo[1],
                $errorInfo[2]
            );
        }
        return $statement;
    }
159832
public function httpRequest()
    {
        if ($this->httpRequest === null) {
            throw new RuntimeException(sprintf(
                'PSR-7 HTTP Request is not defined for "%s"',
                get_class($this)
            ));
        }

        return $this->httpRequest;
    }
987992
protected function getClientUserAgent()
    {
        if ($this->requestStack->getCurrentRequest() === null) {
            throw new \RuntimeException(sprintf('%s can not be called outside of request cycle', __METHOD__));
        }

        return $this->requestStack->getCurrentRequest()->server->get('HTTP_USER_AGENT');
    }
621419
private function getRequest()
    {
        if ($this->requestStack instanceof Request) {
            $request = $this->requestStack;
        } elseif ($this->requestStack instanceof RequestStack) {
            $request = $this->requestStack->getCurrentRequest();
        }

        if ($request !== null) {
            return $request;
        }

        throw new \RuntimeException('There is no current request.');
    }
1123397
public function tell(): int
    {
        if ($this->isAttached() === false || ($position = ftell($this->stream)) === false) {
            throw new RuntimeException('Could not get the position of the pointer in stream');
        }

        return $position;
    }
315975
public function execute()
    {
        $storage = $this->em->unwrap();

        if (! $storage instanceof RangeQueryStorage) {
            throw new \RuntimeException(
                'The storage backend ' . $storage->getName() . ' does not support range queries.'
            );
        }

        $uow   = $this->em->getUnitOfWork();
        $class = $this->em->getClassMetadata($this->className);

        $rowHydration = function ($row) use ($uow, $class) {
            $key = [];
            foreach ($class->identifier as $id) {
                $key[$id] = $row[$id];
            }

            return $uow->createEntity($class, $key, $row);
        };
        return $storage->executeRangeQuery($this, $class->storageName, $class->identifier, $rowHydration);
    }
297453
public function tell()
    {
        if ($this->stream === null || ($position = ftell($this->stream)) === false) {
            throw new RuntimeException('Could not get the position of the pointer in stream');
        }

        return $position;
    }
536750
public function getUser()
    {
        if (null === $tokenStorage = $this->tokenStorage) {
            throw new \RuntimeException('The "app.user" variable is not available.');
        }

        if (!$token = $tokenStorage->getToken()) {
            return;
        }

        $user = $token->getUser();
        if (\is_object($user)) {
            return $user;
        }
    }
94673
public function getContents() : string
    {
        $r = false;
        $err = ($this->stream === null || $this->readable === false);

        if ($err === false) {
            $r = stream_get_contents($this->stream);
        }

        if ($err === true || $r === false) {
            // @codeCoverageIgnoreStart
            throw new \RuntimeException("Could not get contents of stream.");
            // @codeCoverageIgnoreEnd
        }

        return $r;
    }