2018-06-20 19:30:00 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Entity;
|
|
|
|
|
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ORM\Table(name="torrents", indexes={
|
|
|
|
* @ORM\Index(name="discovered_on_index", columns={"discovered_on"}),
|
|
|
|
* @ORM\Index(name="info_hash_index", columns={"info_hash"})
|
|
|
|
* })
|
2018-06-20 23:37:35 +00:00
|
|
|
* @ORM\Entity(readOnly=true, repositoryClass="App\Repository\TorrentRepository")
|
2018-06-20 19:30:00 +00:00
|
|
|
*/
|
|
|
|
class Torrent
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var int
|
|
|
|
*
|
|
|
|
* @ORM\Column(name="id", type="integer")
|
|
|
|
* @ORM\Id
|
|
|
|
*/
|
|
|
|
private $id;
|
|
|
|
|
|
|
|
/**
|
2018-06-22 15:21:10 +00:00
|
|
|
* @var resource Resource pointing to info-hash BLOB
|
2018-06-20 19:30:00 +00:00
|
|
|
*
|
|
|
|
* @ORM\Column(name="info_hash", type="blob", nullable=false)
|
|
|
|
*/
|
|
|
|
private $infoHash;
|
|
|
|
|
2018-06-22 15:12:51 +00:00
|
|
|
/**
|
|
|
|
* @var string Cached value of self::infoHash in HEX string
|
|
|
|
*/
|
|
|
|
private $infoHashHexCache;
|
|
|
|
|
2018-06-20 19:30:00 +00:00
|
|
|
/**
|
2018-06-22 15:21:10 +00:00
|
|
|
* @var string Torrent name
|
2018-06-20 19:30:00 +00:00
|
|
|
*
|
|
|
|
* @ORM\Column(name="name", type="text", nullable=false)
|
|
|
|
*/
|
|
|
|
private $name;
|
|
|
|
|
|
|
|
/**
|
2018-06-22 15:21:10 +00:00
|
|
|
* @var int Torrent files total size in bytes
|
2018-06-20 19:30:00 +00:00
|
|
|
*
|
|
|
|
* @ORM\Column(name="total_size", type="integer", nullable=false)
|
|
|
|
*/
|
|
|
|
private $totalSize;
|
|
|
|
|
|
|
|
/**
|
2018-06-22 15:21:10 +00:00
|
|
|
* @var int Torrent discovery timestamp
|
2018-06-20 19:30:00 +00:00
|
|
|
*
|
|
|
|
* @ORM\Column(name="discovered_on", type="integer", nullable=false)
|
|
|
|
*/
|
|
|
|
private $discoveredOn;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var File[]|ArrayCollection
|
|
|
|
*
|
|
|
|
* @ORM\OneToMany(targetEntity="App\Entity\File", fetch="EXTRA_LAZY", mappedBy="torrent")
|
|
|
|
*/
|
|
|
|
private $files;
|
|
|
|
|
|
|
|
public function getId(): int
|
|
|
|
{
|
|
|
|
return $this->id;
|
|
|
|
}
|
|
|
|
|
2018-06-22 15:21:10 +00:00
|
|
|
/**
|
|
|
|
* Returns torrent info hash BLOB resource
|
|
|
|
*
|
|
|
|
* @return resource
|
|
|
|
*/
|
2018-06-20 19:30:00 +00:00
|
|
|
public function getInfoHash()
|
|
|
|
{
|
|
|
|
return $this->infoHash;
|
|
|
|
}
|
|
|
|
|
2018-06-22 15:21:10 +00:00
|
|
|
/** Returns torrent info hash as HEX string */
|
2018-06-20 23:37:35 +00:00
|
|
|
public function getInfoHashAsHex(): string
|
2018-06-20 19:30:00 +00:00
|
|
|
{
|
2018-06-22 15:12:51 +00:00
|
|
|
if (null === $this->infoHashHexCache) {
|
|
|
|
$this->infoHashHexCache = bin2hex(stream_get_contents($this->infoHash));
|
|
|
|
rewind($this->infoHash);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->infoHashHexCache;
|
2018-06-20 19:30:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getName(): string
|
|
|
|
{
|
|
|
|
return $this->name;
|
|
|
|
}
|
|
|
|
|
2018-06-22 15:21:10 +00:00
|
|
|
/** Returns torrent files total size in bytes */
|
2018-06-20 19:30:00 +00:00
|
|
|
public function getTotalSize(): int
|
|
|
|
{
|
|
|
|
return $this->totalSize;
|
|
|
|
}
|
|
|
|
|
2018-06-22 15:21:10 +00:00
|
|
|
/** Returns torrent discovery timestamp */
|
2018-06-20 19:30:00 +00:00
|
|
|
public function getDiscoveredOn(): int
|
|
|
|
{
|
|
|
|
return $this->discoveredOn;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return File[]|ArrayCollection
|
|
|
|
*/
|
|
|
|
public function getFiles(): iterable
|
|
|
|
{
|
|
|
|
return $this->files;
|
|
|
|
}
|
|
|
|
}
|