Index Documentation

Bencode
in package

FinalYes

Provides a Bencode serialiser.

Table of Contents

Constants

DEFAULT_DEPTH  = 512
Default maximum depth.

Methods

decode()  : mixed
Decodes a bencoded string.
encode()  : string
Returns the Bencoded representation of a value.

Constants

DEFAULT_DEPTH

Default maximum depth.

public int DEFAULT_DEPTH = 512

Methods

decode()

Decodes a bencoded string.

public static decode(mixed $bencoded[, int $depth = self::DEFAULT_DEPTH ][, bool $associative = true ]) : mixed
Parameters
$bencoded : mixed

The bencoded string being decoded. Can be a readable resource or a string.

$depth : int = self::DEFAULT_DEPTH

Maximum nesting depth of the structure being decoded. The value must be greater than 0.

$associative : bool = true

When true, Bencoded dictionaries will be returned as associative arrays; when false, Bencoded dictionaries will be returned as objects.

Tags
throws
InvalidArgumentException

If $bencoded string is not set to a valid type.

throws
InvalidArgumentException

If $depth is not greater than 0.

throws
RuntimeException

If the Bencoded stream is in an invalid state.

Return values
mixed

Returns the bencoded value as an appropriate PHP type.

encode()

Returns the Bencoded representation of a value.

public static encode(mixed $value[, int $depth = self::DEFAULT_DEPTH ]) : string
Parameters
$value : mixed

The value being encoded. Can by string, integer, array or an object.

$depth : int = self::DEFAULT_DEPTH

Set the maximum depth. Must be greater than zero.

Tags
throws
RuntimeException

If $depth is an invalid value.

Return values
string

Returns a Bencoded string.


        
On this page

Search results