class Protocol

Properties

protected bool $connected
protected bool $connecting
protected int $nextRequestId
protected NegotiatedConnection|null $connection
protected ResponseCache|null $cache

Methods

__construct(Transport $transport, Implementation $clientInfo, ProtocolVersion|null $pinnedProtocolVersion = null)

Create a protocol connection for the transport.

bool
connected()

Determine whether the connection has completed negotiation.

initializeResult()

Get the legacy initialization result.

discoverResult()

Get the modern discovery result.

array
capabilities()

Get the negotiated server capabilities.

serverInfo()

Get the server implementation information.

string|null
instructions()

Get the server instructions.

void
pinProtocolVersion(ProtocolVersion|null $protocolVersion)

Pin the protocol version and invalidate the existing negotiation.

ProtocolVersion|null
pinnedProtocolVersion()

Get the explicitly selected protocol version.

void
connect()

Connect and negotiate once for concurrent callers.

void
handshake()

Negotiate the pinned, remembered or preferred protocol version.

probe()

Probe modern discovery before falling back to legacy initialization.

initialize(ProtocolVersion $protocolVersion, bool $pinned = false)

Complete the legacy initialization handshake.

discover(ProtocolVersion|null $pinned = null)

Discover the server and settle on a mutually supported version.

retryWithMutualVersion(JsonRpcException $jsonRpcException)

Initialize a mutually supported version from a discovery rejection.

versionMismatch(ProtocolVersion $settled, ProtocolVersion $pinned)

Create an error for a server rejecting the pinned version.

bool
identifiesModernServer(JsonRpcException $jsonRpcException)

Determine whether an error identifies a modern server.

bool
identifiesLegacyServer(JsonRpcException $jsonRpcException)

Determine whether an error permits a legacy handshake.

void
disconnect()

Disconnect the transport after any active negotiation finishes.

array
dispatch(Method $method)

Dispatch a method, using the response cache when configured.

void
useCache(ResponseCache|null $responseCache)

Set the response cache for this client.

cache()

Get the configured response cache.

array
roundTrip(Method $method)

Send a complete request, retrying an expired session once.

array
attempt(Method $method, ProtocolVersion $protocolVersion)

Send a request and consume its matching terminal response.

array
requestHeaders(Method $method, JsonRpcRequest $request, ProtocolVersion $protocolVersion)

Get the headers required by the selected protocol version.

array
params(Method $method, ProtocolVersion $protocolVersion)

Add protocol metadata to the method parameters when required.

void
notify(string $method, ProtocolVersion|null $protocolVersion = null)

Send a notification without overlapping connection mutations.

ProtocolVersion
connectionProtocol()

Get the currently negotiated protocol version.

void
configureTransport(ProtocolVersion $protocolVersion)

Apply the protocol version to transports that use it.

void
handleServerRequest(array $frame)

Reply to server requests supported by the transport.

Details

at line 57
__construct(Transport $transport, Implementation $clientInfo, ProtocolVersion|null $pinnedProtocolVersion = null)

Create a protocol connection for the transport.

Parameters

Transport $transport
Implementation $clientInfo
ProtocolVersion|null $pinnedProtocolVersion

at line 67
bool connected()

Determine whether the connection has completed negotiation.

Return Value

bool

at line 75
InitializeResult|null initializeResult()

Get the legacy initialization result.

Return Value

InitializeResult|null

at line 83
DiscoverResult|null discoverResult()

Get the modern discovery result.

Return Value

DiscoverResult|null

at line 93
array capabilities()

Get the negotiated server capabilities.

Return Value

array

at line 101
Implementation|null serverInfo()

Get the server implementation information.

Return Value

Implementation|null

at line 109
string|null instructions()

Get the server instructions.

Return Value

string|null

at line 117
void pinProtocolVersion(ProtocolVersion|null $protocolVersion)

Pin the protocol version and invalidate the existing negotiation.

Parameters

ProtocolVersion|null $protocolVersion

Return Value

void

at line 132
ProtocolVersion|null pinnedProtocolVersion()

Get the explicitly selected protocol version.

Return Value

ProtocolVersion|null

at line 140
void connect()

Connect and negotiate once for concurrent callers.

Return Value

void

at line 178
protected void handshake()

Negotiate the pinned, remembered or preferred protocol version.

Return Value

void

at line 216
protected NegotiatedConnection probe()

Probe modern discovery before falling back to legacy initialization.

Return Value

NegotiatedConnection

at line 258
protected NegotiatedConnection initialize(ProtocolVersion $protocolVersion, bool $pinned = false)

Complete the legacy initialization handshake.

Parameters

ProtocolVersion $protocolVersion
bool $pinned

Return Value

NegotiatedConnection

at line 278
protected NegotiatedConnection discover(ProtocolVersion|null $pinned = null)

Discover the server and settle on a mutually supported version.

Parameters

ProtocolVersion|null $pinned

Return Value

NegotiatedConnection

at line 304
protected NegotiatedConnection retryWithMutualVersion(JsonRpcException $jsonRpcException)

Initialize a mutually supported version from a discovery rejection.

Parameters

JsonRpcException $jsonRpcException

Return Value

NegotiatedConnection

at line 323
protected ClientException versionMismatch(ProtocolVersion $settled, ProtocolVersion $pinned)

Create an error for a server rejecting the pinned version.

Parameters

ProtocolVersion $settled
ProtocolVersion $pinned

Return Value

ClientException

at line 335
protected bool identifiesModernServer(JsonRpcException $jsonRpcException)

Determine whether an error identifies a modern server.

Parameters

JsonRpcException $jsonRpcException

Return Value

bool

at line 347
protected bool identifiesLegacyServer(JsonRpcException $jsonRpcException)

Determine whether an error permits a legacy handshake.

Parameters

JsonRpcException $jsonRpcException

Return Value

bool

at line 361
void disconnect()

Disconnect the transport after any active negotiation finishes.

Return Value

void

at line 382
array dispatch(Method $method)

Dispatch a method, using the response cache when configured.

Parameters

Method $method

Return Value

array

at line 398
void useCache(ResponseCache|null $responseCache)

Set the response cache for this client.

Parameters

ResponseCache|null $responseCache

Return Value

void

at line 406
ResponseCache|null cache()

Get the configured response cache.

Return Value

ResponseCache|null

at line 417
protected array roundTrip(Method $method)

Send a complete request, retrying an expired session once.

Parameters

Method $method

Return Value

array

at line 450
protected array attempt(Method $method, ProtocolVersion $protocolVersion)

Send a request and consume its matching terminal response.

Parameters

Method $method
ProtocolVersion $protocolVersion

Return Value

array

at line 546
protected array requestHeaders(Method $method, JsonRpcRequest $request, ProtocolVersion $protocolVersion)

Get the headers required by the selected protocol version.

Parameters

Method $method
JsonRpcRequest $request
ProtocolVersion $protocolVersion

Return Value

array

at line 564
protected array params(Method $method, ProtocolVersion $protocolVersion)

Add protocol metadata to the method parameters when required.

Parameters

Method $method
ProtocolVersion $protocolVersion

Return Value

array

at line 585
void notify(string $method, ProtocolVersion|null $protocolVersion = null)

Send a notification without overlapping connection mutations.

Parameters

string $method
ProtocolVersion|null $protocolVersion

Return Value

void

at line 613
ProtocolVersion connectionProtocol()

Get the currently negotiated protocol version.

Return Value

ProtocolVersion

at line 625
protected void configureTransport(ProtocolVersion $protocolVersion)

Apply the protocol version to transports that use it.

Parameters

ProtocolVersion $protocolVersion

Return Value

void

at line 637
protected void handleServerRequest(array $frame)

Reply to server requests supported by the transport.

Parameters

array $frame

Return Value

void