Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: arokettu/bencode
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1.8.1
Choose a base ref
...
head repository: arokettu/bencode
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Loading
Showing with 3,224 additions and 1,577 deletions.
  1. +12 −5 .gitattributes
  2. +5 −0 .gitignore
  3. +31 −13 .gitlab-ci.yml
  4. +7 −2 .readthedocs.yaml
  5. +213 −0 CHANGELOG.md
  6. +0 −53 CODE_OF_MERIT.md
  7. +31 −18 README.md
  8. +0 −27 autoload.php
  9. +13 −15 composer.json
  10. +5 −0 docs/_templates/rtd-version.html
  11. +0 −22 docs/_templates/sidebar/brand.html
  12. +61 −3 docs/conf.py
  13. +3 −0 docs/conf_project.py
  14. +65 −75 docs/decoding.rst
  15. +69 −0 docs/decoding_callback.rst
  16. +52 −64 docs/encoding.rst
  17. +5 −8 docs/index.rst
  18. +1 −1 docs/requirements.txt
  19. +82 −0 docs/upgrade.rst
  20. +8 −1 phpcs.xml
  21. +22 −0 phpunit.dist.xml
  22. +0 −14 phpunit.xml
  23. +17 −0 psalm.xml
  24. +67 −39 src/Bencode.php
  25. +35 −7 src/Bencode/BigInt.php
  26. +21 −5 src/Bencode/Collection.php
  27. +74 −0 src/CallbackDecoder.php
  28. +44 −22 src/Decoder.php
  29. +18 −18 src/Encoder.php
  30. +231 −0 src/Engine/CallbackReader.php
  31. +0 −351 src/Engine/Decoder.php
  32. +0 −220 src/Engine/Encoder.php
  33. +240 −0 src/Engine/Reader.php
  34. +210 −0 src/Engine/Writer.php
  35. +1 −1 src/Exceptions/BencodeException.php
  36. +2 −2 src/Exceptions/FileNotReadableException.php
  37. +2 −2 src/Exceptions/FileNotWritableException.php
  38. +2 −2 src/Exceptions/InvalidArgumentException.php
  39. +4 −2 src/Exceptions/ParseErrorException.php
  40. +2 −2 src/Exceptions/RuntimeException.php
  41. +11 −0 src/Exceptions/ValueNotSerializableException.php
  42. +4 −5 src/Types/BencodeSerializable.php
  43. +32 −12 src/Types/BigIntType.php
  44. +13 −0 src/Types/CallbackHandler.php
  45. +8 −2 src/Types/DictType.php
  46. +17 −13 src/Types/IterableTypeTrait.php
  47. +8 −2 src/Types/ListType.php
  48. +1 −1 src/Util/IntUtil.php
  49. +0 −38 src/Util/Util.php
  50. +30 −18 tests/BigIntTypeTest.php
  51. +77 −0 tests/CallbackDecodeDictTest.php
  52. +94 −0 tests/CallbackDecodeIntegerTest.php
  53. +197 −0 tests/CallbackDecodeIntegrationTest.php
  54. +38 −0 tests/CallbackDecodeListTest.php
  55. +73 −0 tests/CallbackDecodeStringTest.php
  56. +81 −0 tests/CallbackDecodeTest.php
  57. +66 −14 tests/DecodeDictTest.php
  58. +21 −13 tests/DecodeIntegerTest.php
  59. +101 −9 tests/DecodeIntegrationTest.php
  60. +18 −30 tests/DecodeListTest.php
  61. +9 −9 tests/DecodeStringTest.php
  62. +11 −11 tests/DecodeTest.php
  63. +145 −0 tests/EncodeDictTest.php
  64. +20 −20 tests/EncodeEmptyTest.php
  65. +47 −0 tests/EncodeIntegrationTest.php
  66. +58 −0 tests/EncodeListTest.php
  67. +37 −0 tests/EncodeOptionsTest.php
  68. +50 −0 tests/EncodeScalarTest.php
  69. +91 −0 tests/EncodeSerializableTest.php
  70. +13 −325 tests/EncodeTest.php
  71. +48 −18 tests/FileTest.php
  72. +38 −0 tests/Helpers/CallbackCombiner.php
  73. +85 −43 tests/LargeIntegerTest.php
  74. +27 −0 tests/OptionsArrayTest.php
17 changes: 12 additions & 5 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
/tests export-ignore
/.git* export-ignore
/*.yml export-ignore
/*.yaml export-ignore
/*.xml export-ignore
# template
/docs/*.py export-ignore
/docs/*.txt export-ignore
/docs/_* export-ignore
/tests export-ignore
/.git* export-ignore
/*.yml export-ignore
/*.yaml export-ignore
/*.xml export-ignore
/*.xml.dist export-ignore

# project
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# ide
/.idea
/.vscode

# composer
/vendor/
@@ -8,7 +9,11 @@
# docs
/docs/*.html
/docs/build
/venv

# tests
/reports
/.phpunit.result.cache

# dev
/debug
44 changes: 31 additions & 13 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
stages:
- test
- report
- report-upload

cache:
key: composer-cache
@@ -14,8 +15,8 @@ cache:
# install system packages
- apt-get update && apt-get install -y git unzip libgmp-dev
# install extensions
- docker-php-ext-install gmp
- if [ "$INSTALL_XDEBUG" -eq 1 ]; then curl --location https://github.com/FriendsOfPHP/pickle/releases/latest/download/pickle.phar --output pickle.phar; php pickle.phar install --defaults xdebug; docker-php-ext-enable xdebug; fi
- docker-php-ext-install gmp bcmath
- if [ "$INSTALL_XDEBUG" -eq 1 ]; then pecl install xdebug; docker-php-ext-enable xdebug; fi
# install composer
- php -r "copy('https://composer.github.io/installer.sig', '/tmp/composer.sig');"
- php -r "copy('https://getcomposer.org/installer', '/tmp/composer-setup.php');"
@@ -27,7 +28,7 @@ cache:
- composer config -g cache-dir "$(pwd)/.composer-cache"
script:
- composer update
- vendor/bin/phpunit
- vendor/bin/phpunit --fail-on-deprecation --fail-on-notice --fail-on-warning

# coverage
coverage:
@@ -36,25 +37,42 @@ coverage:
extends: .test
stage: report
only:
- 1.x
- 2.x
image: php:8.0
- master
image: php:8.1 # todo: php:8.4
artifacts:
paths:
- reports
expire_in: 1h
script:
- composer update
- XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-clover coverage.xml
- bash <(curl -s https://codecov.io/bash)
- XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-clover reports/coverage.xml --log-junit reports/junit.xml

coverage-upload:
stage: report-upload
image: python:3.12
only:
- master
before_script:
- pip install codecov-cli
script:
- codecovcli do-upload --report-type test_results --file reports/junit.xml --token $CODECOV_TOKEN
- codecovcli upload-process --file reports/coverage.xml --token $CODECOV_TOKEN

# lowest version
test-7.0:
test-8.1:
extends: .test
stage: test
image: php:7.0
image: php:8.1

# latest PHP 7
test-7:
# lowest bcmath
test-8.4:
extends: .test
stage: test
image: php:7
image: php:8.4-rc
script:
- composer config platform.php '8.3.99' # fake version for now
- composer update
- vendor/bin/phpunit --fail-on-deprecation --fail-on-notice --fail-on-warning

# latest PHP 8
test-8:
9 changes: 7 additions & 2 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
version: 2

build:
os: 'ubuntu-24.04'
tools:
python: '3.12'

sphinx:
configuration: docs/conf.py
configuration: 'docs/conf.py'

python:
install:
- requirements: docs/requirements.txt
- requirements: 'docs/requirements.txt'
213 changes: 213 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,218 @@
# Changelog

## 4.x

### 4.3.0

*Sep 25, 2024*

* BcMath\Number support for encoding and decoding
* Encoder now throws instances of `ValueNotSerializableException` (subclass of `UnexpectedValueException`)

### 4.2.1

*Jul 28, 2024*

* Exception fixes:
* Using $options array now throws `BadFunctionCallException`
* `ParseErrorException` reclassified to `UnexpectedValueException` (runtime instead of logic)

### 4.2.0

*Mar 9, 2024*

* Callback Decoder (proposed in [gitlab#2])

[gitlab#2]: https://gitlab.com/sandfox/bencode/-/issues/2

### 4.1.0

*Jul 14, 2023*

* Removed implicit conversion of floats to strings.
Since it was unreliable, it's not considered a BC break.

### 4.0.0

*Dec 14, 2022*

4.0.0 was branched from 3.1.0

* The package is now `arokettu/bencode`
* The namespace is now `Arokettu\Bencode\ `
* New class names can be used with old branches (1.8+, 2.8+, 3.1+)
* $options arrays now generate an exception if they are not empty
* The parameters are kept for param order compatibility
* Passing class names to `listType`, `dictType`, and `bigInt` generates a TypeError
* `listType`, `dictType`, and `bigInt` callbacks receive `iterable` instead of `array`
* Dictionaries are converted to ArrayObject by default

## 3.x

### 3.1.1

*Dec 14, 2022*

* `sandfoxme/bencode` is now provided by the package

### 3.1.0

*Dec 13, 2022*

* $options arrays are deprecated
* Passing class names to `listType`, `dictType`, and `bigInt` is deprecated
* Aliased all classes in `SandFox\Bencode\*` to `Arokettu\Bencode\*` in preparation for 4.0

### 3.0.3

*Oct 24, 2021*

* dump() now throws exception if the file is not writable
* load() now throws exception if the file is not readable

### 3.0.2

*Oct 23, 2021*

* Objects serialized to empty values are now allowed on non-root levels

### 3.0.1

*Sep 25, 2021*

* Future compatible stream check

### 3.0.0

*Sep 17, 2021*

3.0.0 was branched from 2.6.1

* PHP 8.1 is required
* Decoding:
* Removed deprecated options: ``dictionaryType`` (use ``dictType``), ``useGMP`` (use ``bigInt: Bencode\BigInt::GMP``)
* ``Bencode\BigInt`` and ``Bencode\Collection`` are now enums,
therefore ``dictType``, ``listType``, ``bigInt`` params no longer accept bare string values
(like ``'array'`` or ``'object'`` or ``'gmp'``).
* Encoding:
* Traversables no longer become dictionaries by default.
You need to wrap them with ``DictType``.
* Stringables no longer become strings by default.
Use ``useStringable: true`` to return old behavior.
* ``dump($filename, $data)`` became ``dump($data, $filename)`` for consistency with streams.
* `Decoder` and `Encoder` objects that can be pre-configured and then used with consistent options.
* `bencodeSerialize` now declares `mixed` return type

## 2.x

### 2.8.1

*Dec 14, 2022*

* `sandfoxme/bencode` is now provided by the package

### 2.8.0

*Dec 13, 2022*

* Alias all classes in `SandFox\Bencode\*` to `Arokettu\Bencode\*` in preparation for 4.0

### 2.7.4

*Nov 30, 2021*

* symfony/contracts v3 is now allowed

### 2.7.3

*Oct 24, 2021*

* dump() now throws exception if the file is not writable
* load() now throws exception if the file is not readable

### 2.7.2

*Oct 23, 2021*

* Objects serialized to empty values are now allowed on non-root levels

### 2.7.1

*Sep 25, 2021*

* Future compatible stream check

### 2.7.0

*Sep 17, 2021*

* Decoder and Encoder are backported from 3.x
* `DictType` backported from 3.x
* `useJsonSerializable` backported from 3.x
* `useGMP` is marked as deprecated
* Fixed `'useGMP'` in options array causing crash

### 2.6.1

*Sep 10, 2021*

* Fixed possible invalid dictionary encoding when traversable returns non unique keys

### 2.6.0

*Feb 14, 2021*

* Expanded big integer support:
* `brick/math`
* `Math_BigInteger`
* Custom BigIntType numeric string wrapper
* Callback and custom class name

### 2.5.0

*Feb 3, 2021*

* Added stream API
* Added GMP support

### 2.4.0

*Nov 10, 2020*

* Make spec compliant BitTorrent code simpler: `null` and `false` values are now skipped on encoding
* Remove deprecation warning for options array

### 2.3.0

*Oct 4, 2020*

* Shorten `dictionaryType` to `dictType`. `dictionaryType` will be removed in 3.0
* Trigger silent deprecations for deprecated stuff

### 2.2.0

*Oct 3, 2020*

* Update `dump()` and `load()` signatures to match `encode()` and `decode()`

### 2.1.0

*Aug 5, 2020*

* Replace Becnode::decode() options array with named parameters.
Options array is now deprecated and will be removed in 3.0
* Engine optimizations

### 2.0.0

*Jun 30, 2020*

2.0.0 was branched from 1.3.0

* PHP 8 is required
* Legacy namespace `SandFoxMe\Bencode` is removed
* Encode now throws an error if it encounters a value that cannot be serialized

## 1.x

### 1.8.1
Loading