2016-08-25 13:27:14 +00:00
|
|
|
<?php
|
|
|
|
declare(strict_types = 1);
|
|
|
|
|
|
|
|
namespace LanguageServer;
|
|
|
|
|
2016-08-25 15:03:29 +00:00
|
|
|
use LanguageServer\Protocol\Message;
|
|
|
|
|
2016-08-25 13:27:14 +00:00
|
|
|
class ProtocolStreamWriter implements ProtocolWriter
|
|
|
|
{
|
|
|
|
private $output;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param resource $output
|
|
|
|
*/
|
|
|
|
public function __construct($output)
|
|
|
|
{
|
|
|
|
$this->output = $output;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends a Message to the client
|
|
|
|
*
|
|
|
|
* @param Message $msg
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-08-25 15:01:29 +00:00
|
|
|
public function write(Message $msg)
|
2016-08-25 13:27:14 +00:00
|
|
|
{
|
2016-09-30 09:30:08 +00:00
|
|
|
$data = (string)$msg;
|
|
|
|
$msgSize = strlen($data);
|
|
|
|
$totalBytesWritten = 0;
|
|
|
|
|
|
|
|
while ($totalBytesWritten < $msgSize) {
|
2016-10-24 11:46:39 +00:00
|
|
|
$bytesWritten = fwrite($this->output, substr($data, $totalBytesWritten));
|
2016-09-30 09:30:08 +00:00
|
|
|
$totalBytesWritten += $bytesWritten;
|
|
|
|
}
|
2016-08-25 13:27:14 +00:00
|
|
|
}
|
|
|
|
}
|