PHP Class Gui\Ipc\Receiver

This class is used to receive communication messages
Since: 0.1
Author: Gabriel Couto @gabrielrcouto
显示文件 Open project: gabrielrcouto/php-gui Class Usage Examples

Public Properties

Property Type Description
$application gui\Application The application object
$messageCallbacks array Array of callbacks

Protected Properties

Property Type Description
$buffer string The buffer of received messages
$isWaitingMessage boolean Defines if is waiting message
$parseMessagesBuffer array Array of messages in buffer
$waitingMessageId integer The id of the waitingMessage
$waitingMessageResult mixed The return of the waitingMessage

Public Methods

Method Description
__construct ( Application $application ) : void The constructor
addMessageCallback ( integer $id, callable $callback ) : void When the result of a message arrives, we call a callback
callMessageCallback ( integer $id, string | Array | Object | integer $result ) : void Result received, time to call the message callback
callObjectEventListener ( integer $id, string $eventName ) : void Fire a event on a object
onData ( string $data ) : void Process Stdout handler
tick ( ) : void Read the stdout pipe from Lazarus process. This function uses stream_select to be non blocking
waitMessage ( Stream $stdout, MessageInterface $message ) : mixed Wait a message result

Protected Methods

Method Description
jsonDecode ( string $json ) : MessageInterface | void Decode a received message
parseDebug ( $message ) : void Parse a debug message
parseNormal ( $message ) : void Parse a normal message, can be a command, command result or an event
prepareOutput ( string $string ) : String Construct the output string

Method Details

__construct() public method

The constructor
public __construct ( Application $application ) : void
$application gui\Application
return void

addMessageCallback() public method

When the result of a message arrives, we call a callback
public addMessageCallback ( integer $id, callable $callback ) : void
$id integer Message ID
$callback callable Callback function
return void

callMessageCallback() public method

Result received, time to call the message callback
public callMessageCallback ( integer $id, string | Array | Object | integer $result ) : void
$id integer Message ID
$result string | Array | Object | integer Command Result
return void

callObjectEventListener() public method

Fire a event on a object
public callObjectEventListener ( integer $id, string $eventName ) : void
$id integer Object ID
$eventName string Event Name
return void

jsonDecode() protected method

Decode a received message
protected jsonDecode ( string $json ) : MessageInterface | void
$json string Received json message
return MessageInterface | void

onData() public method

Process Stdout handler
public onData ( string $data ) : void
$data string Data received
return void

parseDebug() protected method

Parse a debug message
protected parseDebug ( $message ) : void
$message Message
return void

parseNormal() protected method

Parse a normal message, can be a command, command result or an event
protected parseNormal ( $message ) : void
$message Message
return void

prepareOutput() protected method

Construct the output string
protected prepareOutput ( string $string ) : String
$string string Output string
return String New output string

tick() public method

Read the stdout pipe from Lazarus process. This function uses stream_select to be non blocking
public tick ( ) : void
return void

waitMessage() public method

Wait a message result
public waitMessage ( Stream $stdout, MessageInterface $message ) : mixed
$stdout React\Stream\Stream Stdout Stream
$message MessageInterface Command waiting result
return mixed The result

Property Details

$application public_oe property

The application object
public Application,Gui $application
return gui\Application

$buffer protected_oe property

The buffer of received messages
protected string $buffer
return string

$isWaitingMessage protected_oe property

Defines if is waiting message
protected bool $isWaitingMessage
return boolean

$messageCallbacks public_oe property

Array of callbacks
public array $messageCallbacks
return array

$parseMessagesBuffer protected_oe property

Array of messages in buffer
protected array $parseMessagesBuffer
return array

$waitingMessageId protected_oe property

The id of the waitingMessage
protected int $waitingMessageId
return integer

$waitingMessageResult protected_oe property

The return of the waitingMessage
protected mixed $waitingMessageResult
return mixed