CommandOutputProcessor

Class
Final: Yes

Converts buffered command output objects into serializable context entries.

Description

JSON payloads are decoded eagerly so parent command envelopes can expose nested structured output without re-encoding it as an escaped string.

Table of Contents

Interfaces

ContextProcessorInterface

Defines a processor that transforms log context payloads.

Methods

 : array<string, mixed>
consumeJsonDocument()

Consumes a single top-level JSON document from a multi-document stream.

 : string|null
decodeJsonDocumentStream()

Decodes a stream that contains multiple JSON documents separated by whitespace.

 : array<int, mixed>|null
decodeStructuredOutput()

Decodes a buffered output string when it contains JSON content.

 : mixed
decodeStructuredOutputAfterTextPreamble()

Decodes structured output that is preceded by plain-text warnings or banners.

 : mixed
findNextJsonDocumentOffset()

Finds the offset of the next possible JSON document opening token.

 : int|null
normalizeStructuredPayload()

Normalizes decoded structured payloads produced by wrapped tooling.

 : mixed
Methods

process()

Public
public process( array<string, mixed>  $context) : array<string, mixed>
Parameters
$context : array<string, mixed>
Return values
array<string, mixed>

consumeJsonDocument()

Private

Consumes a single top-level JSON document from a multi-document stream.

private consumeJsonDocument( string  $content, int  &$offset) : string|null
Parameters
$content : string

Description

the buffered output contents

$offset : int

Description

the current stream offset, advanced past the document on success

Return values
string|null

Description

the extracted JSON document

decodeJsonDocumentStream()

Private

Decodes a stream that contains multiple JSON documents separated by whitespace.

private decodeJsonDocumentStream( string  $content) : array<int, mixed>|null
Parameters
$content : string

Description

the buffered output contents

Return values
array<int, mixed>|null

Description

the decoded JSON documents when the stream is valid

decodeStructuredOutput()

Private

Decodes a buffered output string when it contains JSON content.

private decodeStructuredOutput( string  $content) : mixed
Parameters
$content : string

Description

the buffered output contents

Return values

Description

the decoded JSON payload or the original string

decodeStructuredOutputAfterTextPreamble()

Private

Decodes structured output that is preceded by plain-text warnings or banners.

private decodeStructuredOutputAfterTextPreamble( string  $content) : mixed

Description

Some tooling emits advisory text before a valid JSON payload even when a machine-readable format is requested. When the suffix starting at the first valid JSON token is fully decodable, the textual preamble SHALL be ignored so parent command envelopes remain parseable.

Parameters
$content : string

Description

the buffered output contents

Return values

Description

the decoded JSON payload when a valid structured suffix exists

extractBufferedOutput()

Private
private extractBufferedOutput(OutputInterface  $output) : mixed
Parameters
$output : OutputInterface

findNextJsonDocumentOffset()

Private

Finds the offset of the next possible JSON document opening token.

private findNextJsonDocumentOffset( string  $content, int  $offset) : int|null
Parameters
$content : string

Description

the buffered output contents

$offset : int

Description

the offset from which scanning SHALL start

Return values
int|null

Description

the offset of the next "{" or "[" token

normalizeStructuredPayload()

Private

Normalizes decoded structured payloads produced by wrapped tooling.

private normalizeStructuredPayload( mixed  $payload) : mixed
Parameters
$payload : mixed

Description

the decoded payload

Return values

Description

the normalized payload