LineSessionTrait
Synchronous line-oriented communication session.
Tags
Table of Contents
Properties
- $bufferSize : int
- Maximum size of the buffer for reading lines.
- $delimiter : string
- Line-delimiter.
- $input : resource
- $output : resource
- $responsePrefix : string|null
- A value to display immediately before the response lines.
Methods
- __construct() : mixed
- getBufferSize() : int
- getResponsePrefix() : string|null
- run() : mixed
- Run the main loop. Poll for commands on $input and write responses to $output.
- setBufferSize() : $this
- setIO() : $this
- setResponsePrefix() : $this
- onConnect() : string|null
- The onConnect() method is called when a new session is opened.
- onException() : string|null
- The onRequest() method is called after receiving one line of text.
- onRequest() : string|null
- The onRequest() method is called after receiving one line of text.
- write() : void
Properties
$bufferSize
Maximum size of the buffer for reading lines.
protected
int
$bufferSize
= 524288
Clients may need to set this if they submit large requests.
$delimiter
Line-delimiter.
protected
string
$delimiter
= "\n"
$input
protected
resource
$input
Ex: STDIN
$output
protected
resource
$output
Ex: STDOUT
$responsePrefix
A value to display immediately before the response lines.
protected
string|null
$responsePrefix
= NULL
Clients may set this is if they want to detect and skip buggy noise.
Ex: chr(1).chr(1)
Methods
__construct()
public
__construct([resource|null $input = NULL ][, resource|null $output = NULL ]) : mixed
Parameters
- $input : resource|null = NULL
- $output : resource|null = NULL
getBufferSize()
public
getBufferSize() : int
Return values
intgetResponsePrefix()
public
getResponsePrefix() : string|null
Return values
string|nullrun()
Run the main loop. Poll for commands on $input and write responses to $output.
public
run([string $negotiationFlags = '' ]) : mixed
Parameters
- $negotiationFlags : string = ''
-
List of pipe initialization flags. See Civi::pipe() for description of flags.
setBufferSize()
public
setBufferSize(int $bufferSize) : $this
Parameters
- $bufferSize : int
Return values
$thissetIO()
public
setIO(resource $input, resource $output) : $this
Parameters
- $input : resource
- $output : resource
Return values
$thissetResponsePrefix()
public
setResponsePrefix(string|null $responsePrefix) : $this
Parameters
- $responsePrefix : string|null
Return values
$thisonConnect()
The onConnect() method is called when a new session is opened.
protected
onConnect(string $negotiationFlags) : string|null
Parameters
- $negotiationFlags : string
-
List of pipe initialization flags. See Civi::pipe() for description of flags.
Tags
Return values
string|null —Header/welcome line, or NULL if none.
onException()
The onRequest() method is called after receiving one line of text.
protected
abstract onException(string $requestLine, Throwable $t) : string|null
Parameters
- $requestLine : string
-
The received line of text - which led to the unhandled exception.
- $t : Throwable
-
The unhandled exception.
Return values
string|null —The line to send back, or NULL if none.
onRequest()
The onRequest() method is called after receiving one line of text.
protected
abstract onRequest(string $requestLine) : string|null
Parameters
- $requestLine : string
-
The received line of text.
Return values
string|null —The line to send back, or NULL if none.
write()
protected
write(string|null $response) : void
Parameters
- $response : string|null