PHP Class PAGI\Node\Node

Author: Marcelo Gornstein ([email protected])
Afficher le fichier Open project: marcelog/pagi Class Usage Examples

Protected Properties

Свойство Type Description
$state integer Node state.

Méthodes publiques

Méthode Description
__toString ( ) : string A classic!
addPrePromptMessage ( string $filename ) : void Adds a sound file to play as a pre prompt message.
cancelWith ( string $digit ) : Node Configures a specific digit as the cancel digit.
cancelWithInputRetriesInput ( ) : Node Allow the user to retry input by pressing the cancel digit after entered one or more digits. For example, when entering a 12 number pin, the user might press the cancel digit at the 5th digit to re-enter it. This counts as a failed input, but will not cancel the node. The node will be cancelled only if the user presses the cancel digit with NO input at all.
clearPromptMessages ( ) : Node Removes prompt messages.
createValidatorInfo ( Closure $validation, string | null $soundOnError = null ) : validatorInfo Given a callback and an optional sound to play on error, this will return a validator information structure to be used with validateInputWith().
delCustomData ( string $key ) : Node Remove a key/value from the registry.
dontAcceptPrePromptInputAsInput ( ) : Node Digits entered during the pre prompt messages are not considered as node input.
endInputWith ( string $digit ) : Node Configures a specific digit as the end of input digit.
executeAfterFailedValidation ( Closure $callback ) : Node Executes after the 1st failed validation.
executeAfterRun ( Closure $callback ) : Node Executes after running the node.
executeBeforeRun ( Closure $callback ) : Node Executes before running the node.
executeOnInputFailed ( Closure $callback ) : Node Executes a callback when the node fails to properly get input from the user (either because of cancel, max attempts reached, timeout).
executeOnValidInput ( Closure $callback ) : Node Specify a callback function to invoke when the user entered a valid input.
expectAtLeast ( integer $length ) : Node Configure the node to expect at least this many digits. The input is considered complete when this many digits has been entered. Cancel and end of input digits (if configured) are not taken into account.
expectAtMost ( integer $length ) : Node Configure the node to expect at most this many digits. The reading loop will try to read this many digits.
expectExactly ( integer $length ) : Node Configure this node to expect at least and at most this many digits.
getClient ( ) : PAGI\Client\IClient Returns the agi client in use.
getCustomData ( string $key ) : mixed Returns the value for the given key in the registry.
getInput ( ) : string Returns input.
getName ( ) : string Returns the node name.
getTotalInputAttemptsUsed ( ) : integer Returns the total number of input attempts used by the user.
hasCustomData ( string $key ) : boolean True if the given key exists in the registry.
hasInput ( ) : boolean True if this node has at least 1 digit as input, excluding cancel and end of input digits.
inputLengthIsAtLeast ( integer $length ) : boolean True if this node has at least this many digits entered.
isComplete ( ) : boolean True if this node is in COMPLETE state.
isTimeout ( ) : boolean True if this node is in TIMEOUT state.
loadValidatorsFrom ( array $validatorsInformation ) : Node Given an array of validator information structures, this will load all validators into this node.
maxAttemptsForInput ( integer $number ) : Node Specify a maximum attempt number for the user to enter a valid input.
maxInputsReached ( ) : boolean True if the user reached the maximum allowed attempts for valid input.
maxTimeBetweenDigits ( integer $milliseconds ) : Node Configures the maximum time available between digits before a timeout.
maxTotalTimeForInput ( integer $milliseconds ) : Node Configures the maximum time available for the user to enter valid input per attempt.
playNoInputMessageOnLastAttempt ( ) : Node Forces to play "no input" message on last attempt too.
playOnMaxValidInputAttempts ( string $filename ) : Node Optional message to play when the user exhausted all the available attempts to enter a valid input.
playOnNoInput ( string $filename ) : Node Specify an optional message to play when the user did not enter any input at all. By default, will NOT be played if this happens in the last allowed attempt.
prePromptMessagesNotInterruptable ( ) : Node Make pre prompt messages not interruptable
run ( ) : Node Executes this node.
saveCustomData ( string $key, mixed $value ) : Node Saves a custom key/value to the registry.
sayDateTime ( integer $timestamp, string $format ) : Node Loads a prompt message for saying a date/time expressed by a unix timestamp and a format.
sayDigits ( integer $digits ) : Node Loads a prompt message for saying the digits of the given number.
sayNumber ( integer $number ) : Node Loads a prompt message for saying a number.
saySound ( string $filename ) : Node Loads a prompt message for playing an audio file.
setAgiClient ( PAGI\Client\IClient $client ) : Node Sets the pagi client to use by this node.
setName ( string $name ) : Node Gives a name for this node.
unInterruptablePrompts ( ) : Node Make prompt messages not interruptable.
validate ( ) : boolean Calls all validators in order. Will stop when any of them returns false.
validateInputWith ( string $name, Closure $validation, string | null $soundOnError = null ) : Node Add an input validation to this node.
wasCancelled ( ) : boolean True if this node is in CANCEL state.

Méthodes protégées

Méthode Description
acceptInput ( string $digit ) : void Process a single digit input by the user. Changes the node state according to the digit entered (CANCEL, COMPLETE).
addClientMethodCall ( ) : void Internally used to execute prompt messages in the agi client.
addPrePromptClientMethodCall ( ) : void Internally used to execute pre prompt messages in the agi client.
appendInput ( string $digit ) : void Appends an input to the node input.
beforeOnInputFailed ( ) : void Convenient hook to execute before calling the onInputFailed callback.
beforeOnValidInput ( ) : void Convenient hook to execute before calling the onValidInput callback.
callClientMethod ( string $name, array $arguments = [] ) : PAGI\Client\Result\IResult Call a specific method on a client.
callClientMethods ( methodInfo[] $methods, Closure $stopWhen = null ) : PAGI\Client\Result\IResult Calls methods in the PAGI client.
clearPrePromptMessages ( ) : void Internally used to clear pre prompt messages after being played.
doInput ( ) : void Internally used to accept input from the user. Plays pre prompt messages, prompt, and waits for a complete input or cancel.
evaluateInput ( string $digit ) : integer Returns the kind of digit entered by the user, CANCEL, END, NORMAL.
inputIsCancel ( string $digit ) : boolean True if the digit matches the cancel digit.
inputIsEnd ( string $digit ) : boolean True if the digit matches the end of input digit.
logDebug ( string $msg ) : void Used internally to log debug messages
playPrePromptMessages ( ) : PAGI\Client\Result\IResult Internally used to play all pre prompt queued messages. Clears the queue after it.
playPromptMessages ( ) : PAGI\Client\Result\IResult | null Plays pre prompt messages, like error messages from validations.
resetInput ( ) : Node Internally used to clear the input per input attempt. Also resets state to TIMEOUT.
stateToString ( integer $state ) : string Maps the current node state to a human readable string.

Method Details

__toString() public méthode

A classic!
public __toString ( ) : string
Résultat string

acceptInput() protected méthode

Process a single digit input by the user. Changes the node state according to the digit entered (CANCEL, COMPLETE).
protected acceptInput ( string $digit ) : void
$digit string
Résultat void

addClientMethodCall() protected méthode

Internally used to execute prompt messages in the agi client.
protected addClientMethodCall ( ) : void
Résultat void

addPrePromptClientMethodCall() protected méthode

Internally used to execute pre prompt messages in the agi client.
protected addPrePromptClientMethodCall ( ) : void
Résultat void

addPrePromptMessage() public méthode

Adds a sound file to play as a pre prompt message.
public addPrePromptMessage ( string $filename ) : void
$filename string
Résultat void

appendInput() protected méthode

Appends an input to the node input.
protected appendInput ( string $digit ) : void
$digit string A single character, one of the DTMF_* constants.
Résultat void

beforeOnInputFailed() protected méthode

Convenient hook to execute before calling the onInputFailed callback.
protected beforeOnInputFailed ( ) : void
Résultat void

beforeOnValidInput() protected méthode

Convenient hook to execute before calling the onValidInput callback.
protected beforeOnValidInput ( ) : void
Résultat void

callClientMethod() protected méthode

Call a specific method on a client.
protected callClientMethod ( string $name, array $arguments = [] ) : PAGI\Client\Result\IResult
$name string
$arguments array
Résultat PAGI\Client\Result\IResult

callClientMethods() protected méthode

Calls methods in the PAGI client.
protected callClientMethods ( methodInfo[] $methods, Closure $stopWhen = null ) : PAGI\Client\Result\IResult
$methods methodInfo[] Methods to call, an array of arrays. The second array has the method name as key and an array of arguments as value.
$stopWhen Closure If any, this callback is evaluated before returning. Will return when false.
Résultat PAGI\Client\Result\IResult

cancelWith() public méthode

Configures a specific digit as the cancel digit.
public cancelWith ( string $digit ) : Node
$digit string A single character, one of the DTMF_* constants.
Résultat Node

cancelWithInputRetriesInput() public méthode

Allow the user to retry input by pressing the cancel digit after entered one or more digits. For example, when entering a 12 number pin, the user might press the cancel digit at the 5th digit to re-enter it. This counts as a failed input, but will not cancel the node. The node will be cancelled only if the user presses the cancel digit with NO input at all.
public cancelWithInputRetriesInput ( ) : Node
Résultat Node

clearPrePromptMessages() protected méthode

Internally used to clear pre prompt messages after being played.
protected clearPrePromptMessages ( ) : void
Résultat void

clearPromptMessages() public méthode

Removes prompt messages.
public clearPromptMessages ( ) : Node
Résultat Node

createValidatorInfo() public static méthode

Given a callback and an optional sound to play on error, this will return a validator information structure to be used with validateInputWith().
public static createValidatorInfo ( Closure $validation, string | null $soundOnError = null ) : validatorInfo
$validation Closure Callback to use as validator
$soundOnError string | null Sound file to play on error
Résultat validatorInfo

delCustomData() public méthode

Remove a key/value from the registry.
public delCustomData ( string $key ) : Node
$key string
Résultat Node

doInput() protected méthode

Internally used to accept input from the user. Plays pre prompt messages, prompt, and waits for a complete input or cancel.
protected doInput ( ) : void
Résultat void

dontAcceptPrePromptInputAsInput() public méthode

Digits entered during the pre prompt messages are not considered as node input.
public dontAcceptPrePromptInputAsInput ( ) : Node
Résultat Node

endInputWith() public méthode

Configures a specific digit as the end of input digit.
public endInputWith ( string $digit ) : Node
$digit string A single character, one of the DTMF_* constants.
Résultat Node

evaluateInput() protected méthode

Returns the kind of digit entered by the user, CANCEL, END, NORMAL.
protected evaluateInput ( string $digit ) : integer
$digit string A single character, one of the DTMF_* constants.
Résultat integer

executeAfterFailedValidation() public méthode

Executes after the 1st failed validation.
public executeAfterFailedValidation ( Closure $callback ) : Node
$callback Closure
Résultat Node

executeAfterRun() public méthode

Executes after running the node.
public executeAfterRun ( Closure $callback ) : Node
$callback Closure
Résultat Node

executeBeforeRun() public méthode

Executes before running the node.
public executeBeforeRun ( Closure $callback ) : Node
$callback Closure
Résultat Node

executeOnInputFailed() public méthode

Executes a callback when the node fails to properly get input from the user (either because of cancel, max attempts reached, timeout).
public executeOnInputFailed ( Closure $callback ) : Node
$callback Closure
Résultat Node

executeOnValidInput() public méthode

Specify a callback function to invoke when the user entered a valid input.
public executeOnValidInput ( Closure $callback ) : Node
$callback Closure
Résultat Node

expectAtLeast() public méthode

Configure the node to expect at least this many digits. The input is considered complete when this many digits has been entered. Cancel and end of input digits (if configured) are not taken into account.
public expectAtLeast ( integer $length ) : Node
$length integer
Résultat Node

expectAtMost() public méthode

Configure the node to expect at most this many digits. The reading loop will try to read this many digits.
public expectAtMost ( integer $length ) : Node
$length integer
Résultat Node

expectExactly() public méthode

Configure this node to expect at least and at most this many digits.
public expectExactly ( integer $length ) : Node
$length integer
Résultat Node

getClient() public méthode

Returns the agi client in use.
public getClient ( ) : PAGI\Client\IClient
Résultat PAGI\Client\IClient

getCustomData() public méthode

Returns the value for the given key in the registry.
public getCustomData ( string $key ) : mixed
$key string
Résultat mixed

getInput() public méthode

Returns input.
public getInput ( ) : string
Résultat string

getName() public méthode

Returns the node name.
public getName ( ) : string
Résultat string

getTotalInputAttemptsUsed() public méthode

Returns the total number of input attempts used by the user.
public getTotalInputAttemptsUsed ( ) : integer
Résultat integer

hasCustomData() public méthode

True if the given key exists in the registry.
public hasCustomData ( string $key ) : boolean
$key string
Résultat boolean

hasInput() public méthode

True if this node has at least 1 digit as input, excluding cancel and end of input digits.
public hasInput ( ) : boolean
Résultat boolean

inputIsCancel() protected méthode

True if the digit matches the cancel digit.
protected inputIsCancel ( string $digit ) : boolean
$digit string A single character, one of the DTMF_* constants.
Résultat boolean

inputIsEnd() protected méthode

True if the digit matches the end of input digit.
protected inputIsEnd ( string $digit ) : boolean
$digit string A single character, one of the DTMF_* constants.
Résultat boolean

inputLengthIsAtLeast() public méthode

True if this node has at least this many digits entered.
public inputLengthIsAtLeast ( integer $length ) : boolean
$length integer
Résultat boolean

isComplete() public méthode

True if this node is in COMPLETE state.
public isComplete ( ) : boolean
Résultat boolean

isTimeout() public méthode

True if this node is in TIMEOUT state.
public isTimeout ( ) : boolean
Résultat boolean

loadValidatorsFrom() public méthode

Given an array of validator information structures, this will load all validators into this node.
public loadValidatorsFrom ( array $validatorsInformation ) : Node
$validatorsInformation array
Résultat Node

logDebug() protected méthode

Used internally to log debug messages
protected logDebug ( string $msg ) : void
$msg string
Résultat void

maxAttemptsForInput() public méthode

Defaults to 1.
public maxAttemptsForInput ( integer $number ) : Node
$number integer
Résultat Node

maxInputsReached() public méthode

True if the user reached the maximum allowed attempts for valid input.
public maxInputsReached ( ) : boolean
Résultat boolean

maxTimeBetweenDigits() public méthode

Configures the maximum time available between digits before a timeout.
public maxTimeBetweenDigits ( integer $milliseconds ) : Node
$milliseconds integer
Résultat Node

maxTotalTimeForInput() public méthode

Configures the maximum time available for the user to enter valid input per attempt.
public maxTotalTimeForInput ( integer $milliseconds ) : Node
$milliseconds integer
Résultat Node

playNoInputMessageOnLastAttempt() public méthode

Forces to play "no input" message on last attempt too.
public playNoInputMessageOnLastAttempt ( ) : Node
Résultat Node

playOnMaxValidInputAttempts() public méthode

Optional message to play when the user exhausted all the available attempts to enter a valid input.
public playOnMaxValidInputAttempts ( string $filename ) : Node
$filename string Sound file to play.
Résultat Node

playOnNoInput() public méthode

Specify an optional message to play when the user did not enter any input at all. By default, will NOT be played if this happens in the last allowed attempt.
public playOnNoInput ( string $filename ) : Node
$filename string Sound file to play.
Résultat Node

playPrePromptMessages() protected méthode

Internally used to play all pre prompt queued messages. Clears the queue after it.
protected playPrePromptMessages ( ) : PAGI\Client\Result\IResult
Résultat PAGI\Client\Result\IResult

playPromptMessages() protected méthode

Plays pre prompt messages, like error messages from validations.
protected playPromptMessages ( ) : PAGI\Client\Result\IResult | null
Résultat PAGI\Client\Result\IResult | null

prePromptMessagesNotInterruptable() public méthode

Make pre prompt messages not interruptable
public prePromptMessagesNotInterruptable ( ) : Node
Résultat Node

resetInput() protected méthode

Internally used to clear the input per input attempt. Also resets state to TIMEOUT.
protected resetInput ( ) : Node
Résultat Node

run() public méthode

Executes this node.
public run ( ) : Node
Résultat Node

saveCustomData() public méthode

Saves a custom key/value to the registry.
public saveCustomData ( string $key, mixed $value ) : Node
$key string
$value mixed
Résultat Node

sayDateTime() public méthode

Loads a prompt message for saying a date/time expressed by a unix timestamp and a format.
public sayDateTime ( integer $timestamp, string $format ) : Node
$timestamp integer
$format string
Résultat Node

sayDigits() public méthode

Loads a prompt message for saying the digits of the given number.
public sayDigits ( integer $digits ) : Node
$digits integer
Résultat Node

sayNumber() public méthode

Loads a prompt message for saying a number.
public sayNumber ( integer $number ) : Node
$number integer
Résultat Node

saySound() public méthode

Loads a prompt message for playing an audio file.
public saySound ( string $filename ) : Node
$filename string
Résultat Node

setAgiClient() public méthode

Sets the pagi client to use by this node.
public setAgiClient ( PAGI\Client\IClient $client ) : Node
$client PAGI\Client\IClient
Résultat Node

setName() public méthode

Gives a name for this node.
public setName ( string $name ) : Node
$name string
Résultat Node

stateToString() protected méthode

Maps the current node state to a human readable string.
protected stateToString ( integer $state ) : string
$state integer One of the STATE_* constants.
Résultat string

unInterruptablePrompts() public méthode

Make prompt messages not interruptable.
public unInterruptablePrompts ( ) : Node
Résultat Node

validate() public méthode

Calls all validators in order. Will stop when any of them returns false.
public validate ( ) : boolean
Résultat boolean

validateInputWith() public méthode

Add an input validation to this node.
public validateInputWith ( string $name, Closure $validation, string | null $soundOnError = null ) : Node
$name string A distrinctive name for this validator
$validation Closure Callback to use for validation
$soundOnError string | null Optional sound to play on error
Résultat Node

wasCancelled() public méthode

True if this node is in CANCEL state.
public wasCancelled ( ) : boolean
Résultat boolean

Property Details

$state protected_oe property

Node state.
protected int $state
Résultat integer