getStream());
}
/**
* Start a new buffer.
* The callable acts like a light filter.
*
* @param mixed $callable Callable.
* @param int $size Size.
* @return int
*/
public function newBuffer($callable = null, $size = null)
{
$this->setStreamBuffer($size);
//@TODO manage $callable as a filter?
return 1;
}
/**
* Flush the output to a stream.
*
* @return bool
*/
public function flush()
{
return fflush($this->getStream());
}
/**
* Delete buffer.
*
* @return bool
*/
public function deleteBuffer()
{
return $this->disableStreamBuffer();
}
/**
* Get bufffer level.
*
* @return int
*/
public function getBufferLevel()
{
return 1;
}
/**
* Get buffer size.
*
* @return int
*/
public function getBufferSize()
{
return $this->getStreamBufferSize();
}
/**
* Portable advisory locking.
*
* @param int $operation Operation, use the
* \Hoa\Stream\IStream\Lockable::LOCK_* constants.
* @return bool
*/
public function lock($operation)
{
return flock($this->getStream(), $operation);
}
/**
* Rewind the position of a stream pointer.
*
* @return bool
*/
public function rewind()
{
return rewind($this->getStream());
}
/**
* Seek on a stream pointer.
*
* @param int $offset Offset (negative value should be supported).
* @param int $whence When, use the \Hoa\Stream\IStream\Pointable::SEEK_*
* constants.
* @return int
*/
public function seek($offset, $whence = Stream\IStream\Pointable::SEEK_SET)
{
return fseek($this->getStream(), $offset, $whence);
}
/**
* Get the current position of the stream pointer.
*
* @return int
*/
public function tell()
{
$stream = $this->getStream();
if (null === $stream) {
return 0;
}
return ftell($stream);
}
/**
* Initialize the string buffer.
*
* @param string $string String.
* @return \Hoa\Stringbuffer
*/
public function initializeWith($string)
{
ftruncate($this->getStream(), 0);
fwrite($this->getStream(), $string, strlen($string));
$this->rewind();
return $this;
}
}
/**
* Class \Hoa\Stringbuffer\_Protocol.
*
* The `hoa://Library/Stringbuffer` node.
*
* @copyright Copyright © 2007-2017 Hoa community
* @license New BSD License
*/
class _Protocol extends Protocol\Node
{
/**
* Component's name.
*
* @var string
*/
protected $_name = 'Stringbuffer';
/**
* ID of the component.
*
* @param string $id ID of the component.
* @return mixed
*/
public function reachId($id)
{
$stream = resolve(
'hoa://Library/Stream#hoa://Library/Stringbuffer#' . $id
);
if (null === $stream) {
return null;
}
$meta = $stream->getStreamMetaData();
return $meta['uri'];
}
}
/**
* Flex entity.
*/
Consistency::flexEntity('Hoa\Stringbuffer\Stringbuffer');
/**
* Add the `hoa://Library/Stringbuffer` node. Help to know the real path of a
* stringbuffer.
*/
$protocol = Protocol::getInstance();
$protocol['Library'][] = new _Protocol();