for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace ButterAMQP\IO;
use ButterAMQP\IOInterface;
class BufferIO implements IOInterface
{
/**
* @var string
*/
private $writeBuffer;
private $readBuffer;
* @param string $readBuffer
public function __construct($readBuffer = '')
$this->readBuffer = $readBuffer;
}
* {@inheritdoc}
public function open($protocol, $host, $port, array $parameters = [])
return $this;
public function close()
public function read($length, $blocking = true)
if (strlen($this->readBuffer) < $length) {
$length = strlen($this->readBuffer);
$data = substr($this->readBuffer, 0, $length);
$this->readBuffer = substr($this->readBuffer, $length, strlen($this->readBuffer) - $length);
return $data;
public function write($data, $length = null)
$this->writeBuffer .= $data;
* @param string $data
*
* @return $this
public function push($data)
$this->readBuffer .= $data;
* @param null $length
* @return string
public function pop($length = null)
if ($length === null) {
$data = $this->writeBuffer;
$this->writeBuffer = '';
} else {
$data = substr($this->writeBuffer, 0, $length);
$this->writeBuffer = substr($this->writeBuffer, $length, strlen($this->writeBuffer) - $length);