From c0c827d3ad2c8364d35fff5546ab40ea76bbbbd9 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Tue, 28 Aug 2018 12:00:23 +0200 Subject: update composer libs and add ramsey/uuid --- .../src/Converter/Number/BigNumberConverter.php | 54 ++++++++++++++++++++ .../Converter/Number/DegradedNumberConverter.php | 58 ++++++++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 vendor/ramsey/uuid/src/Converter/Number/BigNumberConverter.php create mode 100644 vendor/ramsey/uuid/src/Converter/Number/DegradedNumberConverter.php (limited to 'vendor/ramsey/uuid/src/Converter/Number') diff --git a/vendor/ramsey/uuid/src/Converter/Number/BigNumberConverter.php b/vendor/ramsey/uuid/src/Converter/Number/BigNumberConverter.php new file mode 100644 index 000000000..d23512256 --- /dev/null +++ b/vendor/ramsey/uuid/src/Converter/Number/BigNumberConverter.php @@ -0,0 +1,54 @@ + + * @license http://opensource.org/licenses/MIT MIT + * @link https://benramsey.com/projects/ramsey-uuid/ Documentation + * @link https://packagist.org/packages/ramsey/uuid Packagist + * @link https://github.com/ramsey/uuid GitHub + */ + +namespace Ramsey\Uuid\Converter\Number; + +use Moontoast\Math\BigNumber; +use Ramsey\Uuid\Converter\NumberConverterInterface; + +/** + * BigNumberConverter converts UUIDs from hexadecimal characters into + * moontoast/math `BigNumber` representations of integers and vice versa + */ +class BigNumberConverter implements NumberConverterInterface +{ + /** + * Converts a hexadecimal number into a `Moontoast\Math\BigNumber` representation + * + * @param string $hex The hexadecimal string representation to convert + * @return BigNumber + */ + public function fromHex($hex) + { + $number = BigNumber::convertToBase10($hex, 16); + + return new BigNumber($number); + } + + /** + * Converts an integer or `Moontoast\Math\BigNumber` integer representation + * into a hexadecimal string representation + * + * @param int|string|BigNumber $integer An integer or `Moontoast\Math\BigNumber` + * @return string Hexadecimal string + */ + public function toHex($integer) + { + if (!$integer instanceof BigNumber) { + $integer = new BigNumber($integer); + } + + return BigNumber::convertFromBase10($integer, 16); + } +} diff --git a/vendor/ramsey/uuid/src/Converter/Number/DegradedNumberConverter.php b/vendor/ramsey/uuid/src/Converter/Number/DegradedNumberConverter.php new file mode 100644 index 000000000..96a011c65 --- /dev/null +++ b/vendor/ramsey/uuid/src/Converter/Number/DegradedNumberConverter.php @@ -0,0 +1,58 @@ + + * @license http://opensource.org/licenses/MIT MIT + * @link https://benramsey.com/projects/ramsey-uuid/ Documentation + * @link https://packagist.org/packages/ramsey/uuid Packagist + * @link https://github.com/ramsey/uuid GitHub + */ + +namespace Ramsey\Uuid\Converter\Number; + +use Ramsey\Uuid\Exception\UnsatisfiedDependencyException; +use Ramsey\Uuid\Converter\NumberConverterInterface; + +/** + * DegradedNumberConverter throws `UnsatisfiedDependencyException` exceptions + * if attempting to use number conversion functionality in an environment that + * does not support large integers (i.e. when moontoast/math is not available) + */ +class DegradedNumberConverter implements NumberConverterInterface +{ + /** + * Throws an `UnsatisfiedDependencyException` + * + * @param string $hex The hexadecimal string representation to convert + * @return void + * @throws UnsatisfiedDependencyException + */ + public function fromHex($hex) + { + throw new UnsatisfiedDependencyException( + 'Cannot call ' . __METHOD__ . ' without support for large ' + . 'integers, since integer is an unsigned ' + . '128-bit integer; Moontoast\Math\BigNumber is required.' + ); + } + + /** + * Throws an `UnsatisfiedDependencyException` + * + * @param mixed $integer An integer representation to convert + * @return void + * @throws UnsatisfiedDependencyException + */ + public function toHex($integer) + { + throw new UnsatisfiedDependencyException( + 'Cannot call ' . __METHOD__ . ' without support for large ' + . 'integers, since integer is an unsigned ' + . '128-bit integer; Moontoast\Math\BigNumber is required. ' + ); + } +} -- cgit v1.2.3