Copied!

GuzzleHttp\Psr7 stream decoder extension for charset conversion.

CloneableInstantiable
Methods
public __call(string $method, array $args)
 

Allow decorators to implement custom methods

  • return mixed
public __construct(Psr\Http\Message\StreamInterface $stream, string $streamCharset = 'ISO-8859-1', string $stringCharset = 'UTF-8')
 
  • param \StreamInterface $stream Stream to decorate
  • param string $streamCharset The underlying stream's charset
  • param string $stringCharset The charset to encode strings to (or expected for write)
public __get(string $name)
 

Magic method used to create a new stream if streams are not added in the constructor of a decorator (e.g., LazyOpenStream).

  • return \StreamInterface
public __toString() : string
public close() : void
public detach()
public eof() : bool
 

Returns true if the end of stream has been reached.

public getContents() : string
public getMetadata( $key = NULL)
 
  • return mixed
public getSize() : ?int
 

Returns null, getSize isn't supported

  • return null
public isReadable() : bool
public isSeekable() : bool
 

Overridden to return false

public isWritable() : bool
public read( $length) : string
 

Reads up to $length decoded chars from the underlying stream and returns them after converting to the target string charset.

  • param int $length
  • return string
public rewind() : void
public seek( $offset, $whence = 0ZBateson\StreamDecorators\SEEK_SET) : void
 

Not supported.

  • param int $offset
  • param int $whence
  • throws \RuntimeException
public tell() : int
 

Overridden to return the position in the target encoding.

public write( $string) : int
 

Writes the passed string to the underlying stream after converting it to the target stream encoding.

  • param string $string
  • return int the number of bytes written
Properties
protected $converter = NULL
 
  • var \MbWrapper the charset converter
protected $streamCharset = 'ISO-8859-1'
 
  • var string charset of the source stream
protected $stringCharset = 'UTF-8'
 
  • var string charset of strings passed in write operations, and returned in read operations.
Methods
protected createStream() : Psr\Http\Message\StreamInterface
 

Implement in subclasses to dynamically create streams when requested.

  • throws \BadMethodCallException
Properties
private $buffer = ''
 
  • var string a buffer of characters read in the original $streamCharset encoding
private $bufferLength = 0
 
  • var int number of $stringCharset characters in $buffer
private $position = 0
 
  • var int current read/write position
private $stream = NULL
 
  • var \StreamInterface $stream
Methods
private readRawCharsIntoBuffer(int $length) : void
 

Reads a minimum of $length characters from the underlying stream in its encoding into $this->buffer.

Aligning to 4 bytes seemed to solve an issue reading from UTF-16LE streams and pass testReadUtf16LeToEof, although the buffered string should've solved that on its own.

© 2024 Bruce Wells
Search Namespaces \ Classes
Configuration