Torrent::getInfoHashAsHex() bug fixed. Now info-hash HEX value is cached in the entity property after first read.

This commit is contained in:
Alexey Skobkin 2018-06-22 18:12:51 +03:00
parent d1a4df53e7
commit 888f02687e

View file

@ -23,12 +23,17 @@ class Torrent
private $id; private $id;
/** /**
* @var string * @var resource
* *
* @ORM\Column(name="info_hash", type="blob", nullable=false) * @ORM\Column(name="info_hash", type="blob", nullable=false)
*/ */
private $infoHash; private $infoHash;
/**
* @var string Cached value of self::infoHash in HEX string
*/
private $infoHashHexCache;
/** /**
* @var string * @var string
* *
@ -69,7 +74,12 @@ class Torrent
public function getInfoHashAsHex(): string 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 public function getName(): string