Bencodex

Encoder
in package

Encodes PHP values into corresponding Bencodex data.

Table of Contents

$byteOrderMark  : bool
__construct()  : void
Creates a new {@see Encoder} instance.
encode()  : void
Encodes the given value into Bencodex data.
encodeBinary()  : mixed
encodeBoolean()  : mixed
encodeDictionary()  : mixed
encodeInteger()  : mixed
encodeList()  : mixed
encodeNull()  : mixed
encodeString()  : mixed
encodeText()  : mixed
getKeyEncoding()  : string|null
Determines what text encoding the string keys of the PHP arrays you want to encode are in.
getTextEncoding()  : string|null
Determines what text encoding the PHP strings you want to encode are in.
setKeyEncoding()  : void
Determines what text encoding the string keys of the PHP arrays you want to encode are in.
setTextEncoding()  : void
Determines what text encoding the PHP strings you want to encode are in.

Properties

$byteOrderMark

public bool $byteOrderMark = false

Whether to respect BOMs (byte order marks). If turned on, strings without BOMs are considered as binary and BOMs are stripped after encoding. If turned off (default), there's no special treatment for BOM.

Methods

__construct()

Creates a new {@see Encoder} instance.

public __construct([string|null $textEncoding = 'utf-8' ][, string|null $keyEncoding = 'utf-8' ][, bool $byteOrderMark = false ]) : void
Parameters
$textEncoding : string|null = 'utf-8'

Determines what text encoding the PHP strings you want to encode are in. If the PHP strings are binary data and not Unicode text, then this should be set to null. UTF-8 by default.

$keyEncoding : string|null = 'utf-8'

Determines what text encoding the string keys of the PHP arrays you want to encode are in. If the PHP string keys are binary keys and not Unicode keys, they should be set to null. UTF-8 by default.

$byteOrderMark : bool = false

Whether to respect BOMs (byte order marks). If turned on, strings without BOMs are considered as binary and BOMs are stripped after encoding. If turned off (default), there's no special treatment for BOM.

Tags
throws
TextEncodingError

Thrown when the given text encoding is invalid or unsupported by iconv.

Return values
void —

encode()

Encodes the given value into Bencodex data.

public encode(Writer $writer, mixed $value) : void
Parameters
$writer : Writer

The writer to which the Bencodex data will be written. In order to get an in-memory string, use MemoryWriter.

$value : mixed

The value to be encoded in Bencodex.

Return values
void —

encodeBinary()

public encodeBinary(Writer $writer, mixed $binary) : mixed
Parameters
$writer : Writer
$binary : mixed
Return values
mixed —

encodeBoolean()

public encodeBoolean(Writer $writer, mixed $boolean) : mixed
Parameters
$writer : Writer
$boolean : mixed
Return values
mixed —

encodeDictionary()

public encodeDictionary(Writer $writer, mixed $dictionary) : mixed
Parameters
$writer : Writer
$dictionary : mixed
Return values
mixed —

encodeInteger()

public encodeInteger(Writer $writer, mixed $integer) : mixed
Parameters
$writer : Writer
$integer : mixed
Return values
mixed —

encodeList()

public encodeList(Writer $writer, mixed $list) : mixed
Parameters
$writer : Writer
$list : mixed
Return values
mixed —

encodeNull()

public encodeNull(Writer $writer) : mixed
Parameters
$writer : Writer
Return values
mixed —

encodeString()

public encodeString(Writer $writer, mixed $encoding, mixed $string) : mixed
Parameters
$writer : Writer
$encoding : mixed
$string : mixed
Return values
mixed —

encodeText()

public encodeText(Writer $writer, mixed $utf8) : mixed
Parameters
$writer : Writer
$utf8 : mixed
Return values
mixed —

getKeyEncoding()

Determines what text encoding the string keys of the PHP arrays you want to encode are in.

public getKeyEncoding() : string|null
Return values
string|null —

Determines what text encoding the string keys of the PHP arrays you want to encode are in.

getTextEncoding()

Determines what text encoding the PHP strings you want to encode are in.

public getTextEncoding() : string|null
Return values
string|null —

Determines what text encoding the PHP strings you want to encode are in.

setKeyEncoding()

Determines what text encoding the string keys of the PHP arrays you want to encode are in.

public setKeyEncoding(string|null $keyEncoding) : void
Parameters
$keyEncoding : string|null

Determines what text encoding the string keys of the PHP arrays you want to encode are in. If the PHP string keys are binary keys and not Unicode keys, they should be set to null. Note that it can be treated as binary data if a PHP string is not a valid sequence of the specified text encoding.

Tags
throws
TextEncodingError

Thrown when the given text encoding is invalid or unsupported by iconv.

Return values
void —

setTextEncoding()

Determines what text encoding the PHP strings you want to encode are in.

public setTextEncoding(string|null $textEncoding) : void
Parameters
$textEncoding : string|null

Determines what text encoding the PHP strings you want to encode are in. If the PHP strings are binary data and not Unicode text, then this should be set to null. Note that it can be treated as binary data if a PHP string is not a valid sequence of the specified text encoding.

Tags
throws
TextEncodingError

Thrown when the given text encoding is invalid or unsupported by iconv.

Return values
void —

Search results