From 888f02687e787522bd2989ef9fa462d154655276 Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Fri, 22 Jun 2018 18:12:51 +0300 Subject: [PATCH] Torrent::getInfoHashAsHex() bug fixed. Now info-hash HEX value is cached in the entity property after first read. --- src/Entity/Torrent.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Entity/Torrent.php b/src/Entity/Torrent.php index 054edb9..7d58d7b 100644 --- a/src/Entity/Torrent.php +++ b/src/Entity/Torrent.php @@ -23,12 +23,17 @@ class Torrent private $id; /** - * @var string + * @var resource * * @ORM\Column(name="info_hash", type="blob", nullable=false) */ private $infoHash; + /** + * @var string Cached value of self::infoHash in HEX string + */ + private $infoHashHexCache; + /** * @var string * @@ -69,7 +74,12 @@ class Torrent public function getInfoHashAsHex(): string { - return bin2hex(stream_get_contents($this->infoHash)); + if (null === $this->infoHashHexCache) { + $this->infoHashHexCache = bin2hex(stream_get_contents($this->infoHash)); + rewind($this->infoHash); + } + + return $this->infoHashHexCache; } public function getName(): string