Documentation

LineSessionTrait

Synchronous line-oriented communication session.

Tags
code

$session = new class { use LineSessionTrait; protected function onRequest(string $requestLine): ?string { return 'Thanks'; } protected function onException(string $requestLine, \Throwable $t): ?string { return 'Oops'; } } $session->setIO(STDIN, STDOUT)->run();

endCode

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.

$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

getResponsePrefix()

public getResponsePrefix() : string|null
Return values
string|null

run()

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
$this

setIO()

public setIO(resource $input, resource $output) : $this
Parameters
$input : resource
$output : resource
Return values
$this

setResponsePrefix()

public setResponsePrefix(string|null $responsePrefix) : $this
Parameters
$responsePrefix : string|null
Return values
$this

onConnect()

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
see
Civi::pipe
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

        
On this page

Search results