protected function askForBoolean($key, $required = false, $default = null) {
        $question = sprintf(
            'Enable configuration setting "%s"?',
            $key
        );

        if (isset($default)) {
            switch ($default) {
                case true:
                    $question .= ' [Y|n]:';
                    break;
                case false:
                    $question .= ' [y|N]:';
                    break;
            }
        }

        $answer = strtolower(IO::in($question));

        switch ($answer) {
            case 'yes':
            case 'y':
            case '1':
            case 'true':
                return true;
            case 'no':
            case 'n':
            case '0':
            case 'false':
                return false;
            case '':
                if (isset($default)) {
                    return $default;
                } elseif ($required) {
                    $this->log->warning('Excuse me, what do you mean?');

                    return $this->askForBoolean($key, $required, $default);
                }
                break;
            default:
                if ($required) {
                    $this->log->warning('Excuse me, what do you mean?');

                    return $this->askForBoolean($key, $required, $default);
                }
                break;
        }

        return null;
    }
protected function askForBoolean($key, $required = false, $default = null) {
        $question = sprintf(
            'Enable configuration setting "%s"?',
            $key
        );

        if (isset($default)) {
            switch ($default) {
                case true:
                    $question .= ' [Y|n]:';
                    break;
                case false:
                    $question .= ' [y|N]:';
                    break;
            }
        }

        $answer = strtolower(IO::in($question));

        switch ($answer) {
            case 'yes':
            case 'y':
            case '1':
            case 'true':
                return true;
            case 'no':
            case 'n':
            case '0':
            case 'false':
                return false;
            case '':
                if (isset($default)) {
                    return $default;
                } elseif ($required) {
                    $this->log->warning('Excuse me, what do you mean?');

                    return $this->askForBoolean($key, $required, $default);
                }
                break;
            default:
                if ($required) {
                    $this->log->warning('Excuse me, what do you mean?');

                    return $this->askForBoolean($key, $required, $default);
                }
                break;
        }

        return null;
    }
protected function askForBoolean ( $ key , $ required = false , $ default = null ) { $ question = sprintf ( 'Enable configuration setting "%s"?' , $ key ) ; if ( isset ( $ default ) ) { switch ( $ default ) { case true : $ question .= ' [Y|n]:' ; break ; case false : $ question .= ' [y|N]:' ; break ; } } $ answer = strtolower ( IO :: in ( $ question ) ) ; switch ( $ answer ) { case 'yes' : case 'y' : case '1' : case 'true' : return true ; case 'no' : case 'n' : case '0' : case 'false' : return false ; case '' : if ( isset ( $ default ) ) { return $ default ; } elseif ( $ required ) { $ this -> log -> warning ( 'Excuse me, what do you mean?' ) ; return $ this -> askForBoolean ( $ key , $ required , $ default ) ; } break ; default : if ( $ required ) { $ this -> log -> warning ( 'Excuse me, what do you mean?' ) ; return $ this -> askForBoolean ( $ key , $ required , $ default ) ; } break ; } return null ; }
Ask user for a value which should be a boolean

@param string $key Setting
@param bool $required Is this setting required? Defaults to false (no, it isn't)
@param bool $default Optional default value which will be used if user doesn't provide a value

@return bool|null Value or nothing

@throws Exception on error
Ask user for a value which should be a boolean