PHP Класс PAGI\Node\Node

Автор: Marcelo Gornstein ([email protected])
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$state integer Node state.

Открытые методы

Метод Описание
__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.

Защищенные методы

Метод Описание
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.

Описание методов

__toString() публичный Метод

A classic!
public __toString ( ) : string
Результат string

acceptInput() защищенный Метод

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
Результат void

addClientMethodCall() защищенный Метод

Internally used to execute prompt messages in the agi client.
protected addClientMethodCall ( ) : void
Результат void

addPrePromptClientMethodCall() защищенный Метод

Internally used to execute pre prompt messages in the agi client.
protected addPrePromptClientMethodCall ( ) : void
Результат void

addPrePromptMessage() публичный Метод

Adds a sound file to play as a pre prompt message.
public addPrePromptMessage ( string $filename ) : void
$filename string
Результат void

appendInput() защищенный Метод

Appends an input to the node input.
protected appendInput ( string $digit ) : void
$digit string A single character, one of the DTMF_* constants.
Результат void

beforeOnInputFailed() защищенный Метод

Convenient hook to execute before calling the onInputFailed callback.
protected beforeOnInputFailed ( ) : void
Результат void

beforeOnValidInput() защищенный Метод

Convenient hook to execute before calling the onValidInput callback.
protected beforeOnValidInput ( ) : void
Результат void

callClientMethod() защищенный Метод

Call a specific method on a client.
protected callClientMethod ( string $name, array $arguments = [] ) : PAGI\Client\Result\IResult
$name string
$arguments array
Результат PAGI\Client\Result\IResult

callClientMethods() защищенный Метод

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.
Результат PAGI\Client\Result\IResult

cancelWith() публичный Метод

Configures a specific digit as the cancel digit.
public cancelWith ( string $digit ) : Node
$digit string A single character, one of the DTMF_* constants.
Результат Node

cancelWithInputRetriesInput() публичный Метод

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
Результат Node

clearPrePromptMessages() защищенный Метод

Internally used to clear pre prompt messages after being played.
protected clearPrePromptMessages ( ) : void
Результат void

clearPromptMessages() публичный Метод

Removes prompt messages.
public clearPromptMessages ( ) : Node
Результат Node

createValidatorInfo() публичный статический Метод

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
Результат validatorInfo

delCustomData() публичный Метод

Remove a key/value from the registry.
public delCustomData ( string $key ) : Node
$key string
Результат Node

doInput() защищенный Метод

Internally used to accept input from the user. Plays pre prompt messages, prompt, and waits for a complete input or cancel.
protected doInput ( ) : void
Результат void

dontAcceptPrePromptInputAsInput() публичный Метод

Digits entered during the pre prompt messages are not considered as node input.
public dontAcceptPrePromptInputAsInput ( ) : Node
Результат Node

endInputWith() публичный Метод

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.
Результат Node

evaluateInput() защищенный Метод

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.
Результат integer

executeAfterFailedValidation() публичный Метод

Executes after the 1st failed validation.
public executeAfterFailedValidation ( Closure $callback ) : Node
$callback Closure
Результат Node

executeAfterRun() публичный Метод

Executes after running the node.
public executeAfterRun ( Closure $callback ) : Node
$callback Closure
Результат Node

executeBeforeRun() публичный Метод

Executes before running the node.
public executeBeforeRun ( Closure $callback ) : Node
$callback Closure
Результат Node

executeOnInputFailed() публичный Метод

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
Результат Node

executeOnValidInput() публичный Метод

Specify a callback function to invoke when the user entered a valid input.
public executeOnValidInput ( Closure $callback ) : Node
$callback Closure
Результат Node

expectAtLeast() публичный Метод

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
Результат Node

expectAtMost() публичный Метод

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
Результат Node

expectExactly() публичный Метод

Configure this node to expect at least and at most this many digits.
public expectExactly ( integer $length ) : Node
$length integer
Результат Node

getClient() публичный Метод

Returns the agi client in use.
public getClient ( ) : PAGI\Client\IClient
Результат PAGI\Client\IClient

getCustomData() публичный Метод

Returns the value for the given key in the registry.
public getCustomData ( string $key ) : mixed
$key string
Результат mixed

getInput() публичный Метод

Returns input.
public getInput ( ) : string
Результат string

getName() публичный Метод

Returns the node name.
public getName ( ) : string
Результат string

getTotalInputAttemptsUsed() публичный Метод

Returns the total number of input attempts used by the user.
public getTotalInputAttemptsUsed ( ) : integer
Результат integer

hasCustomData() публичный Метод

True if the given key exists in the registry.
public hasCustomData ( string $key ) : boolean
$key string
Результат boolean

hasInput() публичный Метод

True if this node has at least 1 digit as input, excluding cancel and end of input digits.
public hasInput ( ) : boolean
Результат boolean

inputIsCancel() защищенный Метод

True if the digit matches the cancel digit.
protected inputIsCancel ( string $digit ) : boolean
$digit string A single character, one of the DTMF_* constants.
Результат boolean

inputIsEnd() защищенный Метод

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.
Результат boolean

inputLengthIsAtLeast() публичный Метод

True if this node has at least this many digits entered.
public inputLengthIsAtLeast ( integer $length ) : boolean
$length integer
Результат boolean

isComplete() публичный Метод

True if this node is in COMPLETE state.
public isComplete ( ) : boolean
Результат boolean

isTimeout() публичный Метод

True if this node is in TIMEOUT state.
public isTimeout ( ) : boolean
Результат boolean

loadValidatorsFrom() публичный Метод

Given an array of validator information structures, this will load all validators into this node.
public loadValidatorsFrom ( array $validatorsInformation ) : Node
$validatorsInformation array
Результат Node

logDebug() защищенный Метод

Used internally to log debug messages
protected logDebug ( string $msg ) : void
$msg string
Результат void

maxAttemptsForInput() публичный Метод

Defaults to 1.
public maxAttemptsForInput ( integer $number ) : Node
$number integer
Результат Node

maxInputsReached() публичный Метод

True if the user reached the maximum allowed attempts for valid input.
public maxInputsReached ( ) : boolean
Результат boolean

maxTimeBetweenDigits() публичный Метод

Configures the maximum time available between digits before a timeout.
public maxTimeBetweenDigits ( integer $milliseconds ) : Node
$milliseconds integer
Результат Node

maxTotalTimeForInput() публичный Метод

Configures the maximum time available for the user to enter valid input per attempt.
public maxTotalTimeForInput ( integer $milliseconds ) : Node
$milliseconds integer
Результат Node

playNoInputMessageOnLastAttempt() публичный Метод

Forces to play "no input" message on last attempt too.
public playNoInputMessageOnLastAttempt ( ) : Node
Результат Node

playOnMaxValidInputAttempts() публичный Метод

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.
Результат Node

playOnNoInput() публичный Метод

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.
Результат Node

playPrePromptMessages() защищенный Метод

Internally used to play all pre prompt queued messages. Clears the queue after it.
protected playPrePromptMessages ( ) : PAGI\Client\Result\IResult
Результат PAGI\Client\Result\IResult

playPromptMessages() защищенный Метод

Plays pre prompt messages, like error messages from validations.
protected playPromptMessages ( ) : PAGI\Client\Result\IResult | null
Результат PAGI\Client\Result\IResult | null

prePromptMessagesNotInterruptable() публичный Метод

Make pre prompt messages not interruptable
public prePromptMessagesNotInterruptable ( ) : Node
Результат Node

resetInput() защищенный Метод

Internally used to clear the input per input attempt. Also resets state to TIMEOUT.
protected resetInput ( ) : Node
Результат Node

run() публичный Метод

Executes this node.
public run ( ) : Node
Результат Node

saveCustomData() публичный Метод

Saves a custom key/value to the registry.
public saveCustomData ( string $key, mixed $value ) : Node
$key string
$value mixed
Результат Node

sayDateTime() публичный Метод

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
Результат Node

sayDigits() публичный Метод

Loads a prompt message for saying the digits of the given number.
public sayDigits ( integer $digits ) : Node
$digits integer
Результат Node

sayNumber() публичный Метод

Loads a prompt message for saying a number.
public sayNumber ( integer $number ) : Node
$number integer
Результат Node

saySound() публичный Метод

Loads a prompt message for playing an audio file.
public saySound ( string $filename ) : Node
$filename string
Результат Node

setAgiClient() публичный Метод

Sets the pagi client to use by this node.
public setAgiClient ( PAGI\Client\IClient $client ) : Node
$client PAGI\Client\IClient
Результат Node

setName() публичный Метод

Gives a name for this node.
public setName ( string $name ) : Node
$name string
Результат Node

stateToString() защищенный Метод

Maps the current node state to a human readable string.
protected stateToString ( integer $state ) : string
$state integer One of the STATE_* constants.
Результат string

unInterruptablePrompts() публичный Метод

Make prompt messages not interruptable.
public unInterruptablePrompts ( ) : Node
Результат Node

validate() публичный Метод

Calls all validators in order. Will stop when any of them returns false.
public validate ( ) : boolean
Результат boolean

validateInputWith() публичный Метод

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
Результат Node

wasCancelled() публичный Метод

True if this node is in CANCEL state.
public wasCancelled ( ) : boolean
Результат boolean

Описание свойств

$state защищенное свойство

Node state.
protected int $state
Результат integer