PHP 클래스 PAGI\Node\Node

저자: Marcelo Gornstein ([email protected])
파일 보기 프로젝트 열기: marcelog/pagi 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
$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.

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