PHP Class PAMI\Client\Impl\ClientImpl

PHP Version 5
Author: Marcelo Gornstein ([email protected])
Inheritance: implements PAMI\Client\IClient
Datei anzeigen Open project: marcelog/pami Class Usage Examples

Public Methods

Method Description
__construct ( array $options ) Constructor.
close ( ) : void Closes the connection to ami.
open ( ) : void Opens a tcp connection to ami.
process ( ) Main processing loop. Also called from send(), you should call this in your own application in order to continue reading events and responses from ami.
registerEventListener ( mixed $listener, Closure | null $predicate = null ) : string Registers the given listener so it can receive events. Returns the generated id for this new listener. You can pass in a an IEventListener, a Closure, and an array containing the object and name of the method to invoke. Can specify an optional predicate to invoke before calling the callback.
send ( PAMI\Message\OutgoingMessage $message ) : PAMI\Message\Response\ResponseMessage Sends a message to ami.
setLogger ( Psr\Log\LoggerInterface $logger ) : void Sets the logger implementation.
unregisterEventListener ( string $listenerId ) : void Unregisters an event listener.

Protected Methods

Method Description
dispatch ( PAMI\Message\IncomingMessage $message ) : void Dispatchs the incoming message to a handler.
findResponse ( PAMI\Message\IncomingMessage $message ) : PAMI\Message\Response\ResponseMessage Tries to find an associated response for the given message.
getMessages ( ) : string[] Reads a complete message over the stream until EOM.
getRelated ( PAMI\Message\OutgoingMessage $message ) : PAMI\Message\IncomingMessage Returns a message (response) related to the given message. This uses the ActionID tag (key).

Private Methods

Method Description
messageToEvent ( string $msg ) : PAMI\Message\Event\EventMessage Returns a EventMessage from a raw string that came from asterisk.
messageToResponse ( string $msg ) : PAMI\Message\Response\ResponseMessage Returns a ResponseMessage from a raw string that came from asterisk.

Method Details

__construct() public method

Constructor.
public __construct ( array $options )
$options array Options for ami client.

close() public method

Closes the connection to ami.
public close ( ) : void
return void

dispatch() protected method

Dispatchs the incoming message to a handler.
protected dispatch ( PAMI\Message\IncomingMessage $message ) : void
$message PAMI\Message\IncomingMessage Message to dispatch.
return void

findResponse() protected method

Tries to find an associated response for the given message.
protected findResponse ( PAMI\Message\IncomingMessage $message ) : PAMI\Message\Response\ResponseMessage
$message PAMI\Message\IncomingMessage Message sent by asterisk.
return PAMI\Message\Response\ResponseMessage

getMessages() protected method

Reads a complete message over the stream until EOM.
protected getMessages ( ) : string[]
return string[]

getRelated() protected method

Returns a message (response) related to the given message. This uses the ActionID tag (key).
protected getRelated ( PAMI\Message\OutgoingMessage $message ) : PAMI\Message\IncomingMessage
$message PAMI\Message\OutgoingMessage
return PAMI\Message\IncomingMessage

open() public method

Opens a tcp connection to ami.
public open ( ) : void
return void

process() public method

Main processing loop. Also called from send(), you should call this in your own application in order to continue reading events and responses from ami.
public process ( )

registerEventListener() public method

Registers the given listener so it can receive events. Returns the generated id for this new listener. You can pass in a an IEventListener, a Closure, and an array containing the object and name of the method to invoke. Can specify an optional predicate to invoke before calling the callback.
public registerEventListener ( mixed $listener, Closure | null $predicate = null ) : string
$listener mixed
$predicate Closure | null
return string

send() public method

Sends a message to ami.
See also: ClientImpl::send()
public send ( PAMI\Message\OutgoingMessage $message ) : PAMI\Message\Response\ResponseMessage
$message PAMI\Message\OutgoingMessage Message to send.
return PAMI\Message\Response\ResponseMessage

setLogger() public method

Sets the logger implementation.
public setLogger ( Psr\Log\LoggerInterface $logger ) : void
$logger Psr\Log\LoggerInterface The PSR3-Logger
return void

unregisterEventListener() public method

Unregisters an event listener.
public unregisterEventListener ( string $listenerId ) : void
$listenerId string The id returned by registerEventListener.
return void