diff --git a/src/Transport/AbstractTransport.php b/src/Transport/AbstractTransport.php deleted file mode 100644 index d565cc0..0000000 --- a/src/Transport/AbstractTransport.php +++ /dev/null @@ -1,87 +0,0 @@ -toJson(); - - if (strlen($json) > static::MAX_MESSAGE_SIZE) { - throw new TransportException("Encoded message exceeds size limit of " . static::MAX_MESSAGE_SIZE . " bytes."); - } - - return $json; - } - - /** - * Decodes and validates a received JSON string into a JsonRpcMessage. - * - * @param string $data The raw JSON data received from the transport. - * @return JsonRpcMessage|null The decoded message, or null if decoding fails (e.g., invalid JSON). - * @throws TransportException If the received data string exceeds MAX_MESSAGE_SIZE before decoding. - */ - protected function decodeMessage(string $data): ?JsonRpcMessage - { - if (strlen($data) > static::MAX_MESSAGE_SIZE) { - throw new TransportException("Received data exceeds size limit of " . static::MAX_MESSAGE_SIZE . " bytes."); - } - - try { - return JsonRpcMessage::fromJson($data); - } catch (\Exception $e) { - // Log but don't throw - allow server to handle invalid messages - $this->log("Error parsing received JSON message: " . $e->getMessage() . ". Data: " . substr($data, 0, 200) . "..."); - return null; - } - } - - /** - * Logs a message related to the transport's operation. - * - * This default implementation writes messages to PHP's error_log. - * Subclasses can override this to use a more sophisticated logging mechanism. - * - * @param string $message The message to log. - */ - public function log(string $message): void - { - error_log(get_class($this) . ": " . $message); - } - - /** - * Indicates a preference for using Server-Sent Events (SSE) for streaming responses, if applicable. - * - * Transports that support SSE (like HttpTransport) can use this hint to switch - * their response mode. Other transports can ignore this. - * - * @param bool $prefer True to prefer SSE, false otherwise. - */ - public function preferSseStream(bool $prefer = true): void - { - // Default implementation does nothing, to be overridden by transports that support SSE. - } -} diff --git a/src/Transport/HttpTransport.php b/src/Transport/HttpTransport.php index 98c1945..97e1387 100644 --- a/src/Transport/HttpTransport.php +++ b/src/Transport/HttpTransport.php @@ -24,7 +24,7 @@ * Origin checks, complex ACK logic, and related session properties have been removed. * It primarily focuses on basic JSON-RPC via POST. */ -class HttpTransport extends AbstractTransport +class HttpTransport implements TransportInterface { // Kept essential properties for basic POST JSON-RPC. /** @var ResponseInterface|null The PSR-7 response object being prepared. */ diff --git a/src/Transport/StdioTransport.php b/src/Transport/StdioTransport.php index 3d30a57..8d07c4d 100644 --- a/src/Transport/StdioTransport.php +++ b/src/Transport/StdioTransport.php @@ -13,7 +13,7 @@ * Implements a transport using STDIN, STDOUT, and STDERR for line-based JSON messaging. * Each JSON-RPC message (or batch of messages) is expected to be on a single line. */ -class StdioTransport extends AbstractTransport +class StdioTransport implements TransportInterface { /** @var resource The standard input stream. */ private $stdin; diff --git a/src/Transport/TransportInterface.php b/src/Transport/TransportInterface.php index 6cd95fc..696c7ca 100644 --- a/src/Transport/TransportInterface.php +++ b/src/Transport/TransportInterface.php @@ -50,16 +50,6 @@ public function receive(): ?array; */ public function send(JsonRpcMessage|array $message): void; - /** - * Logs a message specific to the transport's operation. - * - * Example: For StdioTransport, this might write to STDERR. - * For HttpTransport, it might use a PSR-3 logger if integrated. - * - * @param string $message The message to log. - */ - public function log(string $message): void; - /** * Checks if the transport connection is considered closed. * @@ -79,14 +69,4 @@ public function isClosed(): bool; * @return bool True if a stream is actively open, false otherwise. */ public function isStreamOpen(): bool; - - /** - * Hints to the transport that Server-Sent Events (SSE) are preferred for the response stream, if applicable. - * - * Transports that support SSE (e.g., HttpTransport) can use this to modify - * how they format and send responses. Transports that do not support SSE can ignore this hint. - * - * @param bool $prefer True to indicate a preference for SSE streaming, false otherwise. - */ - public function preferSseStream(bool $prefer = true): void; } diff --git a/tests/Util/MockTransport.php b/tests/Util/MockTransport.php index 1543cd2..e54862b 100644 --- a/tests/Util/MockTransport.php +++ b/tests/Util/MockTransport.php @@ -80,12 +80,6 @@ public function log(string $message): void // error_log("MockTransport Log: " . $message); // For debugging tests } - public function preferSseStream(bool $prefer = true): void - { - // No-op for this mock implementation. - // Could store the preference if tests need to assert it was called. - } - /** * Checks if the transport stream is currently open. * For this mock, defaults to false. Can be made configurable if needed.