TYPO3  7.6
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
DialogHelper Class Reference
Inheritance diagram for DialogHelper:
InputAwareHelper Helper InputAwareInterface HelperInterface

Public Member Functions

 __construct ($triggerDeprecationError=true)
 
 select (OutputInterface $output, $question, $choices, $default=null, $attempts=false, $errorMessage= 'Value"%s"is invalid', $multiselect=false)
 
 ask (OutputInterface $output, $question, $default=null, array $autocomplete=null)
 
 askConfirmation (OutputInterface $output, $question, $default=true)
 
 askHiddenResponse (OutputInterface $output, $question, $fallback=true)
 
 askAndValidate (OutputInterface $output, $question, $validator, $attempts=false, $default=null, array $autocomplete=null)
 
 askHiddenResponseAndValidate (OutputInterface $output, $question, $validator, $attempts=false, $fallback=true)
 
 setInputStream ($stream)
 
 getInputStream ()
 
 getName ()
 
- Public Member Functions inherited from InputAwareHelper
 setInput (InputInterface $input)
 
- Public Member Functions inherited from Helper
 setHelperSet (HelperSet $helperSet=null)
 
 getHelperSet ()
 

Private Member Functions

 getShell ()
 
 hasSttyAvailable ()
 
 validateAttempts ($interviewer, OutputInterface $output, $validator, $attempts)
 

Private Attributes

 $inputStream
 

Static Private Attributes

static $shell
 
static $stty
 

Additional Inherited Members

- Static Public Member Functions inherited from Helper
static strlen ($string)
 
static formatTime ($secs)
 
static formatMemory ($memory)
 
static strlenWithoutDecoration (OutputFormatterInterface $formatter, $string)
 
- Protected Attributes inherited from InputAwareHelper
 $input
 

Detailed Description

The Dialog class provides helpers to interact with the user.

Author
Fabien Potencier fabie.nosp@m.n@sy.nosp@m.mfony.nosp@m..com
Deprecated:
since version 2.5, to be removed in 3.0. Use Symfony\Component\Console\Helper\QuestionHelperinstead.

Definition at line 25 of file DialogHelper.php.

Constructor & Destructor Documentation

__construct (   $triggerDeprecationError = true)

Definition at line 31 of file DialogHelper.php.

Member Function Documentation

ask ( OutputInterface  $output,
  $question,
  $default = null,
array  $autocomplete = null 
)

Asks a question to the user.

Parameters
OutputInterface$outputAn Output instance
string | array$questionThe question to ask
string$defaultThe default answer if none is given by the user
array$autocompleteList of values to autocomplete
Returns
string The user answer
Exceptions
\RuntimeExceptionIf there is no data to read in the input stream

Definition at line 109 of file DialogHelper.php.

References DialogHelper\$inputStream, elseif, OutputInterface\getFormatter(), DialogHelper\hasSttyAvailable(), Helper\strlen(), and OutputInterface\write().

Referenced by DialogHelper\askConfirmation(), and DialogHelper\askHiddenResponse().

askAndValidate ( OutputInterface  $output,
  $question,
  $validator,
  $attempts = false,
  $default = null,
array  $autocomplete = null 
)

Asks for a value and validates the response.

The validator receives the data to validate. It must return the validated data when the data is valid and throw an exception otherwise.

Parameters
OutputInterface$outputAn Output instance
string | array$questionThe question to ask
callable$validatorA PHP callback
int | false$attemptsMax number of times to ask before giving up (false by default, which means infinite)
string$defaultThe default answer if none is given by the user
array$autocompleteList of values to autocomplete
Returns
mixed
Exceptions
\ExceptionWhen any of the validators return an error

Definition at line 347 of file DialogHelper.php.

References DialogHelper\validateAttempts().

Referenced by DialogHelper\select().

askConfirmation ( OutputInterface  $output,
  $question,
  $default = true 
)

Asks a confirmation to the user.

The question will be asked until the user answers by nothing, yes, or no.

Parameters
OutputInterface$outputAn Output instance
string | array$questionThe question to ask
bool$defaultThe default answer if the user enters nothing
Returns
bool true if the user has confirmed, false otherwise

Definition at line 245 of file DialogHelper.php.

References DialogHelper\ask().

askHiddenResponse ( OutputInterface  $output,
  $question,
  $fallback = true 
)

Asks a question to the user, the response is hidden.

Parameters
OutputInterface$outputAn Output instance
string | array$questionThe question
bool$fallbackIn case the response can not be hidden, whether to fallback on non-hidden question or not
Returns
string The answer
Exceptions
\RuntimeExceptionIn case the fallback is deactivated and the response can not be hidden

Definition at line 270 of file DialogHelper.php.

References DialogHelper\$shell, DialogHelper\ask(), DialogHelper\getShell(), DialogHelper\hasSttyAvailable(), OutputInterface\write(), and OutputInterface\writeln().

askHiddenResponseAndValidate ( OutputInterface  $output,
  $question,
  $validator,
  $attempts = false,
  $fallback = true 
)

Asks for a value, hide and validates the response.

The validator receives the data to validate. It must return the validated data when the data is valid and throw an exception otherwise.

Parameters
OutputInterface$outputAn Output instance
string | array$questionThe question to ask
callable$validatorA PHP callback
int | false$attemptsMax number of times to ask before giving up (false by default, which means infinite)
bool$fallbackIn case the response can not be hidden, whether to fallback on non-hidden question or not
Returns
string The response
Exceptions
\ExceptionWhen any of the validators return an error
\RuntimeExceptionIn case the fallback is deactivated and the response can not be hidden

Definition at line 376 of file DialogHelper.php.

References DialogHelper\validateAttempts().

getInputStream ( )

Returns the helper's input stream.

Returns
string

Definition at line 404 of file DialogHelper.php.

References DialogHelper\$inputStream.

getName ( )

{Returns the canonical name of this helper.

Returns
string The canonical name
}

Implements HelperInterface.

Definition at line 412 of file DialogHelper.php.

getShell ( )
private

Return a valid Unix shell.

Returns
string|bool The valid shell name, false in case no valid shell is found

Definition at line 422 of file DialogHelper.php.

Referenced by DialogHelper\askHiddenResponse().

hasSttyAvailable ( )
private

Definition at line 444 of file DialogHelper.php.

Referenced by DialogHelper\ask(), and DialogHelper\askHiddenResponse().

select ( OutputInterface  $output,
  $question,
  $choices,
  $default = null,
  $attempts = false,
  $errorMessage = 'Value "%s" is invalid',
  $multiselect = false 
)

Asks the user to select a value.

Parameters
OutputInterface$outputAn Output instance
string | array$questionThe question to ask
array$choicesList of choices to pick from
bool | string$defaultThe default answer if the user enters nothing
bool | int$attemptsMax number of times to ask before giving up (false by default, which means infinite)
string$errorMessageMessage which will be shown if invalid value from choice list would be picked
bool$multiselectSelect more than one value separated by comma
Returns
int|string|array The selected value or values (the key of the choices array)
Exceptions
\InvalidArgumentException

Definition at line 53 of file DialogHelper.php.

References DialogHelper\askAndValidate(), and OutputInterface\writeln().

setInputStream (   $stream)

Sets the input stream to read from when interacting with the user.

This is mainly useful for testing purpose.

Parameters
resource$streamThe input stream

Definition at line 394 of file DialogHelper.php.

validateAttempts (   $interviewer,
OutputInterface  $output,
  $validator,
  $attempts 
)
private

Validate an attempt.

Parameters
callable$interviewerA callable that will ask for a question and return the result
OutputInterface$outputAn Output instance
callable$validatorA PHP callback
int | false$attemptsMax number of times to ask before giving up ; false will ask infinitely
Returns
string The validated response
Exceptions
\ExceptionIn case the max number of attempts has been reached and no valid response has been given

Definition at line 467 of file DialogHelper.php.

References Helper\getHelperSet(), and OutputInterface\writeln().

Referenced by DialogHelper\askAndValidate(), and DialogHelper\askHiddenResponseAndValidate().

Member Data Documentation

$inputStream
private

Definition at line 27 of file DialogHelper.php.

Referenced by DialogHelper\ask(), and DialogHelper\getInputStream().

$shell
staticprivate

Definition at line 28 of file DialogHelper.php.

Referenced by DialogHelper\askHiddenResponse().

$stty
staticprivate

Definition at line 29 of file DialogHelper.php.