Loading docs/decoding.rst +11 −28 Original line number Diff line number Diff line Decoding ######## .. highlight:: php .. versionchanged:: 2.0 options array is replaced with named parameters .. note:: Parameter order is not guaranteed for options, use named parameters Scalars ======= Scalars will be converted to their respective types. .. code-block:: php Scalars will be converted to their respective types:: <?php Loading Loading @@ -40,9 +39,7 @@ Lists and Dictionaries Dictionaries and lists will be arrays by default. You can change this behavior with options. Use ``Collection`` enum for built in behaviors: .. code-block:: php Use ``Collection`` enum for built in behaviors:: <?php Loading @@ -60,9 +57,7 @@ Use ``Collection`` enum for built in behaviors: // dictType: Bencode\Collection::STDCLASS, ); Or use advanced control with callbacks: .. code-block:: php Or use advanced control with callbacks:: <?php Loading Loading @@ -105,7 +100,7 @@ Supported libraries: * `brick/math`_ * PEAR's `Math_BigInteger`_ .. code-block:: php :: <?php Loading Loading @@ -148,9 +143,7 @@ Internal Type .. versionadded:: 1.6/2.6 The library also has built in ``BigIntType``. It does not require any external dependencies but also does not allow any manipulation. .. code-block:: php It does not require any external dependencies but also does not allow any manipulation:: <?php Loading @@ -164,9 +157,7 @@ It does not require any external dependencies but also does not allow any manipu // '79228162514264337593543950336' // )] BigIntType is a value object with several getters: .. code-block:: php BigIntType is a value object with several getters:: <?php Loading @@ -185,9 +176,7 @@ Custom Handling .. versionadded:: 1.6/2.6 .. versionchanged:: 4.0 Passing class names as handlers was removed Like listType and dictType you can use a callable: .. code-block:: php Like listType and dictType you can use a callable:: <?php Loading @@ -201,9 +190,7 @@ Like listType and dictType you can use a callable: Working with files ================== Load data from a file: .. code-block:: php Load data from a file:: <?php Loading @@ -216,9 +203,7 @@ Working with streams .. versionadded:: 1.5/2.5 Load data from a seekable readable stream: .. code-block:: php Load data from a seekable readable stream:: <?php Loading @@ -231,9 +216,7 @@ Decoder object .. versionadded:: 1.7/2.7/3.0 Decoder object can be configured on creation and used multiple times: .. code-block:: php Decoder object can be configured on creation and used multiple times:: <?php Loading docs/encoding.rst +12 −31 Original line number Diff line number Diff line Encoding ######## .. highlight:: php .. versionchanged:: 2.0 options array is replaced with named parameters .. note:: Parameter order is not guaranteed for options, use named parameters Loading @@ -9,7 +10,7 @@ Scalars and arrays .. versionchanged:: 4.1 floats now throw an exception instead of becoming strings .. code-block:: php :: <?php Loading Loading @@ -43,9 +44,7 @@ ArrayObject and stdClass .. versionchanged:: 3.0 ``Traversable`` objects no longer become dictionaries automatically ArrayObject and stdClass become dictionaries: .. code-block:: php ArrayObject and stdClass become dictionaries:: <?php Loading @@ -70,9 +69,7 @@ Big integer support .. note:: More in the :ref:`decoding section <bencode_decoding_bigint>` GMP object, Pear's Math_BigInteger, brick/math BigInteger, and internal type BigIntType (simple numeric string wrapper) will become integers: .. code-block:: php will become integers:: <?php Loading @@ -92,9 +89,7 @@ Stringable .. versionchanged:: 3.0 ``Stringable`` objects no longer become strings automatically You can convert ``Stringable`` objects to strings using ``useStringable`` option: .. code-block:: php You can convert ``Stringable`` objects to strings using ``useStringable`` option:: <?php Loading @@ -119,9 +114,7 @@ Object Wrappers .. versionadded:: 1.7/2.7/3.0 ``DictType`` You can use any traversable as a list by wrapping it with ``ListType``. Keys will be discarded in that case. .. code-block:: php Keys will be discarded in that case:: <?php Loading @@ -133,9 +126,7 @@ Keys will be discarded in that case. ); // "li1ei2ei3ee" You can use any traversable as a dictionary by wrapping it with ``DictType``. Keys will be cast to string and must be unique. .. code-block:: php Keys will be cast to string and must be unique:: <?php Loading @@ -156,9 +147,7 @@ BencodeSerializable .. versionadded:: 1.7/2.7/3.0 ``JsonSerializable`` handling You can also force object representation by implementing BencodeSerializable interface. This will work exactly like JsonSerializable_ interface. .. code-block:: php This will work exactly like JsonSerializable_ interface:: <?php Loading @@ -182,9 +171,7 @@ This will work exactly like JsonSerializable_ interface. $encoded = Bencode::encode($file); // "d5:class6:MyFile4:name14:myfile.torrent4:sizei5242880ee" Optionally you can use JsonSerializable_ itself too: .. code-block:: php Optionally you can use JsonSerializable_ itself too:: <?php Loading Loading @@ -214,9 +201,7 @@ Working with files .. versionchanged:: 3.0 ``($filename, $data)`` → ``($data, $filename)`` Save data to file: .. code-block:: php Save data to file:: <?php Loading @@ -229,9 +214,7 @@ Working with streams .. versionadded:: 1.5/2.5 Save data to a writable stream or to a new php://temp if no stream is specified .. code-block:: php Save data to a writable stream or to a new php://temp if no stream is specified:: <?php Loading @@ -244,9 +227,7 @@ Encoder object .. versionadded:: 1.7/2.7/3.0 Encoder object can be configured on creation and used multiple times. .. code-block:: php Encoder object can be configured on creation and used multiple times:: <?php Loading docs/upgrade.rst +4 −2 Original line number Diff line number Diff line Upgrade Notes ############# .. highlight:: php Upgrade from 3.x to 4.x ======================= Loading @@ -13,7 +15,7 @@ Upgrade from 3.x to 4.x * Closures passed to ``listType``, ``dictType``, and ``bigInt`` must handle iterables instead of arrays now * Class names can no longer be passed to ``listType``, ``dictType``, and ``bigInt`` .. code-block:: php :: <?php Loading Loading @@ -53,7 +55,7 @@ Main breaking changes: Use ``useStringable: true`` to return old behavior. * ``Bencode::dump($filename, $data)`` became ``Bencode::dump($data, $filename)`` for consistency with streams. .. code-block:: php :: <?php Loading Loading
docs/decoding.rst +11 −28 Original line number Diff line number Diff line Decoding ######## .. highlight:: php .. versionchanged:: 2.0 options array is replaced with named parameters .. note:: Parameter order is not guaranteed for options, use named parameters Scalars ======= Scalars will be converted to their respective types. .. code-block:: php Scalars will be converted to their respective types:: <?php Loading Loading @@ -40,9 +39,7 @@ Lists and Dictionaries Dictionaries and lists will be arrays by default. You can change this behavior with options. Use ``Collection`` enum for built in behaviors: .. code-block:: php Use ``Collection`` enum for built in behaviors:: <?php Loading @@ -60,9 +57,7 @@ Use ``Collection`` enum for built in behaviors: // dictType: Bencode\Collection::STDCLASS, ); Or use advanced control with callbacks: .. code-block:: php Or use advanced control with callbacks:: <?php Loading Loading @@ -105,7 +100,7 @@ Supported libraries: * `brick/math`_ * PEAR's `Math_BigInteger`_ .. code-block:: php :: <?php Loading Loading @@ -148,9 +143,7 @@ Internal Type .. versionadded:: 1.6/2.6 The library also has built in ``BigIntType``. It does not require any external dependencies but also does not allow any manipulation. .. code-block:: php It does not require any external dependencies but also does not allow any manipulation:: <?php Loading @@ -164,9 +157,7 @@ It does not require any external dependencies but also does not allow any manipu // '79228162514264337593543950336' // )] BigIntType is a value object with several getters: .. code-block:: php BigIntType is a value object with several getters:: <?php Loading @@ -185,9 +176,7 @@ Custom Handling .. versionadded:: 1.6/2.6 .. versionchanged:: 4.0 Passing class names as handlers was removed Like listType and dictType you can use a callable: .. code-block:: php Like listType and dictType you can use a callable:: <?php Loading @@ -201,9 +190,7 @@ Like listType and dictType you can use a callable: Working with files ================== Load data from a file: .. code-block:: php Load data from a file:: <?php Loading @@ -216,9 +203,7 @@ Working with streams .. versionadded:: 1.5/2.5 Load data from a seekable readable stream: .. code-block:: php Load data from a seekable readable stream:: <?php Loading @@ -231,9 +216,7 @@ Decoder object .. versionadded:: 1.7/2.7/3.0 Decoder object can be configured on creation and used multiple times: .. code-block:: php Decoder object can be configured on creation and used multiple times:: <?php Loading
docs/encoding.rst +12 −31 Original line number Diff line number Diff line Encoding ######## .. highlight:: php .. versionchanged:: 2.0 options array is replaced with named parameters .. note:: Parameter order is not guaranteed for options, use named parameters Loading @@ -9,7 +10,7 @@ Scalars and arrays .. versionchanged:: 4.1 floats now throw an exception instead of becoming strings .. code-block:: php :: <?php Loading Loading @@ -43,9 +44,7 @@ ArrayObject and stdClass .. versionchanged:: 3.0 ``Traversable`` objects no longer become dictionaries automatically ArrayObject and stdClass become dictionaries: .. code-block:: php ArrayObject and stdClass become dictionaries:: <?php Loading @@ -70,9 +69,7 @@ Big integer support .. note:: More in the :ref:`decoding section <bencode_decoding_bigint>` GMP object, Pear's Math_BigInteger, brick/math BigInteger, and internal type BigIntType (simple numeric string wrapper) will become integers: .. code-block:: php will become integers:: <?php Loading @@ -92,9 +89,7 @@ Stringable .. versionchanged:: 3.0 ``Stringable`` objects no longer become strings automatically You can convert ``Stringable`` objects to strings using ``useStringable`` option: .. code-block:: php You can convert ``Stringable`` objects to strings using ``useStringable`` option:: <?php Loading @@ -119,9 +114,7 @@ Object Wrappers .. versionadded:: 1.7/2.7/3.0 ``DictType`` You can use any traversable as a list by wrapping it with ``ListType``. Keys will be discarded in that case. .. code-block:: php Keys will be discarded in that case:: <?php Loading @@ -133,9 +126,7 @@ Keys will be discarded in that case. ); // "li1ei2ei3ee" You can use any traversable as a dictionary by wrapping it with ``DictType``. Keys will be cast to string and must be unique. .. code-block:: php Keys will be cast to string and must be unique:: <?php Loading @@ -156,9 +147,7 @@ BencodeSerializable .. versionadded:: 1.7/2.7/3.0 ``JsonSerializable`` handling You can also force object representation by implementing BencodeSerializable interface. This will work exactly like JsonSerializable_ interface. .. code-block:: php This will work exactly like JsonSerializable_ interface:: <?php Loading @@ -182,9 +171,7 @@ This will work exactly like JsonSerializable_ interface. $encoded = Bencode::encode($file); // "d5:class6:MyFile4:name14:myfile.torrent4:sizei5242880ee" Optionally you can use JsonSerializable_ itself too: .. code-block:: php Optionally you can use JsonSerializable_ itself too:: <?php Loading Loading @@ -214,9 +201,7 @@ Working with files .. versionchanged:: 3.0 ``($filename, $data)`` → ``($data, $filename)`` Save data to file: .. code-block:: php Save data to file:: <?php Loading @@ -229,9 +214,7 @@ Working with streams .. versionadded:: 1.5/2.5 Save data to a writable stream or to a new php://temp if no stream is specified .. code-block:: php Save data to a writable stream or to a new php://temp if no stream is specified:: <?php Loading @@ -244,9 +227,7 @@ Encoder object .. versionadded:: 1.7/2.7/3.0 Encoder object can be configured on creation and used multiple times. .. code-block:: php Encoder object can be configured on creation and used multiple times:: <?php Loading
docs/upgrade.rst +4 −2 Original line number Diff line number Diff line Upgrade Notes ############# .. highlight:: php Upgrade from 3.x to 4.x ======================= Loading @@ -13,7 +15,7 @@ Upgrade from 3.x to 4.x * Closures passed to ``listType``, ``dictType``, and ``bigInt`` must handle iterables instead of arrays now * Class names can no longer be passed to ``listType``, ``dictType``, and ``bigInt`` .. code-block:: php :: <?php Loading Loading @@ -53,7 +55,7 @@ Main breaking changes: Use ``useStringable: true`` to return old behavior. * ``Bencode::dump($filename, $data)`` became ``Bencode::dump($data, $filename)`` for consistency with streams. .. code-block:: php :: <?php Loading