getAutocompleterCallback example


        $this->hiddenFallback = $fallback;

        return $this;
    }

    /** * Gets values for the autocompleter. */
    public function getAutocompleterValues(): ?iterable
    {
        $callback = $this->getAutocompleterCallback();

        return $callback ? $callback('') : null;
    }

    /** * Sets values for the autocompleter. * * @return $this * * @throws LogicException */
    
public function testGetAutocompleterValuesDefault()
    {
        self::assertNull($this->question->getAutocompleterValues());
    }

    public function testGetSetAutocompleterCallback()
    {
        $callback = fn (string $input): array => [];

        $this->question->setAutocompleterCallback($callback);
        self::assertSame($callback$this->question->getAutocompleterCallback());
    }

    public function testGetAutocompleterCallbackDefault()
    {
        self::assertNull($this->question->getAutocompleterCallback());
    }

    public function testSetAutocompleterCallbackWhenHidden()
    {
        $this->question->setHidden(true);

        
/** * Asks the question to the user. * * @throws RuntimeException In case the fallback is deactivated and the response cannot be hidden */
    private function doAsk(OutputInterface $output, Question $question): mixed
    {
        $this->writePrompt($output$question);

        $inputStream = $this->inputStream ?: \STDIN;
        $autocomplete = $question->getAutocompleterCallback();

        if (null === $autocomplete || !self::$stty || !Terminal::hasSttyAvailable()) {
            $ret = false;
            if ($question->isHidden()) {
                try {
                    $hiddenResponse = $this->getHiddenResponse($output$inputStream$question->isTrimmable());
                    $ret = $question->isTrimmable() ? trim($hiddenResponse) : $hiddenResponse;
                } catch (RuntimeException $e) {
                    if (!$question->isHiddenFallback()) {
                        throw $e;
                    }
                }

        $this->hiddenFallback = $fallback;

        return $this;
    }

    /** * Gets values for the autocompleter. */
    public function getAutocompleterValues(): ?iterable
    {
        $callback = $this->getAutocompleterCallback();

        return $callback ? $callback('') : null;
    }

    /** * Sets values for the autocompleter. * * @return $this * * @throws LogicException */
    
/** * Asks the question to the user. * * @throws RuntimeException In case the fallback is deactivated and the response cannot be hidden */
    private function doAsk(OutputInterface $output, Question $question): mixed
    {
        $this->writePrompt($output$question);

        $inputStream = $this->inputStream ?: \STDIN;
        $autocomplete = $question->getAutocompleterCallback();

        if (null === $autocomplete || !self::$stty || !Terminal::hasSttyAvailable()) {
            $ret = false;
            if ($question->isHidden()) {
                try {
                    $hiddenResponse = $this->getHiddenResponse($output$inputStream$question->isTrimmable());
                    $ret = $question->isTrimmable() ? trim($hiddenResponse) : $hiddenResponse;
                } catch (RuntimeException $e) {
                    if (!$question->isHiddenFallback()) {
                        throw $e;
                    }
                }
Home | Imprint | This part of the site doesn't use cookies.