From 18cbfa1d540428bc2e5f14e7ab69cf73a9c9e6fc Mon Sep 17 00:00:00 2001 From: Rhilip Date: Thu, 23 Jan 2020 10:44:27 +0800 Subject: [PATCH] style(Bencode): Separate Bencode library to `Rhilip/Bencode` --- application/Controllers/TrackerController.php | 3 +- application/Libraries/Bencode/Bencode.php | 149 ------------------ .../Libraries/Bencode/ParseErrorException.php | 13 -- application/Middleware/AuthMiddleware.php | 8 +- .../Models/Form/Torrent/DownloadForm.php | 3 +- .../Models/Form/Torrent/StructureForm.php | 3 +- .../Models/Form/Torrent/UploadForm.php | 5 +- composer.json | 3 +- composer.lock | 46 +++++- templates/torrent/structure.php | 2 +- 10 files changed, 61 insertions(+), 174 deletions(-) delete mode 100644 application/Libraries/Bencode/Bencode.php delete mode 100644 application/Libraries/Bencode/ParseErrorException.php diff --git a/application/Controllers/TrackerController.php b/application/Controllers/TrackerController.php index 45aa600..3ff628a 100644 --- a/application/Controllers/TrackerController.php +++ b/application/Controllers/TrackerController.php @@ -10,11 +10,12 @@ use App\Libraries\Constant; use App\Repository\User\UserRole; -use App\Libraries\Bencode\Bencode; use App\Exceptions\TrackerException; use Rid\Utils\IpUtils; +use Rhilip\Bencode\Bencode; + /** @noinspection PhpUnused */ class TrackerController { diff --git a/application/Libraries/Bencode/Bencode.php b/application/Libraries/Bencode/Bencode.php deleted file mode 100644 index 8bdee13..0000000 --- a/application/Libraries/Bencode/Bencode.php +++ /dev/null @@ -1,149 +0,0 @@ - $value) { - if ($key !== ++$check) { - $list = false; - break; - } - } - if ($list) { - $return .= 'l'; - foreach ($data as $value) { - $return .= self::encode($value); - } - } else { - $return .= 'd'; - ksort($data, SORT_STRING); - foreach ($data as $key => $value) { - $return .= self::encode(strval($key)); - $return .= self::encode($value); - } - } - $return .= 'e'; - } elseif (is_integer($data)) { - $return = 'i' . $data . 'e'; - } else { - $return = strlen($data) . ':' . $data; - } - return $return; - } - - /** - * Given a path to a file, decode the contents of it - * - * @param string $path - * @return mixed - * @throws ParseErrorException - */ - public static function load(string $path) - { - return self::decode(file_get_contents($path, FILE_BINARY)); - } - - /** - * Given a path for a file, encode the contents of it - * - * @param string $path - * @param $data - * @return mixed - */ - public static function dump(string $path, $data) - { - return file_put_contents($path, self::encode($data)); - } -} diff --git a/application/Libraries/Bencode/ParseErrorException.php b/application/Libraries/Bencode/ParseErrorException.php deleted file mode 100644 index b46f2d7..0000000 --- a/application/Libraries/Bencode/ParseErrorException.php +++ /dev/null @@ -1,13 +0,0 @@ -