2018-06-20 19:30:00 +00:00
|
|
|
<?php
|
2022-07-08 01:46:36 +00:00
|
|
|
declare(strict_types=1);
|
2018-06-20 19:30:00 +00:00
|
|
|
|
2018-06-23 14:57:10 +00:00
|
|
|
namespace App\Magnetico\Entity;
|
2018-06-20 19:30:00 +00:00
|
|
|
|
2022-07-08 01:46:36 +00:00
|
|
|
use App\Magnetico\Repository\TorrentRepository;
|
2018-06-20 19:30:00 +00:00
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
2018-06-22 19:45:17 +00:00
|
|
|
use Symfony\Component\Serializer\Annotation as Serializer;
|
2018-06-20 19:30:00 +00:00
|
|
|
|
2022-07-08 01:46:36 +00:00
|
|
|
#[ORM\Entity(repositoryClass: TorrentRepository::class, readOnly: true)]
|
|
|
|
#[ORM\Table(schema: 'magneticod', name: 'torrents')]
|
|
|
|
#[ORM\Index(name: 'discovered_on_index', columns: ['discovered_on'])]
|
|
|
|
#[ORM\Index(name: 'info_hash_index', columns: ['info_hash'])]
|
2018-06-20 19:30:00 +00:00
|
|
|
class Torrent
|
|
|
|
{
|
2022-07-08 01:46:36 +00:00
|
|
|
#[Serializer\Groups(['api_v1_search', 'api_v1_show'])]
|
|
|
|
#[ORM\Id]
|
|
|
|
#[ORM\Column(name: 'id', type: 'integer')]
|
|
|
|
private int $id;
|
|
|
|
|
|
|
|
/** @var resource Resource pointing to info-hash BLOB */
|
|
|
|
#[Serializer\Groups(['api_v1_search', 'api_v1_show'])]
|
|
|
|
#[ORM\Column(name: 'info_hash', type: 'blob', nullable: false)]
|
2018-06-20 19:30:00 +00:00
|
|
|
private $infoHash;
|
|
|
|
|
2022-07-08 01:46:36 +00:00
|
|
|
/** Cached value of self::infoHash in HEX string */
|
|
|
|
private string $infoHashHexCache;
|
2018-06-22 15:12:51 +00:00
|
|
|
|
2022-07-08 01:46:36 +00:00
|
|
|
#[Serializer\Groups(['api_v1_search', 'api_v1_show'])]
|
|
|
|
#[ORM\Column(name: 'name', type: 'text', nullable: false)]
|
|
|
|
private string $name;
|
2018-06-20 19:30:00 +00:00
|
|
|
|
2022-07-08 01:46:36 +00:00
|
|
|
/** Torrent files total size in bytes */
|
|
|
|
#[Serializer\Groups(['api_v1_search', 'api_v1_show'])]
|
|
|
|
#[ORM\Column(name: 'total_size', type: 'bigint', nullable: false)]
|
|
|
|
private int $totalSize;
|
2018-06-20 19:30:00 +00:00
|
|
|
|
2022-07-08 01:46:36 +00:00
|
|
|
/** Torrent discovery timestamp */
|
|
|
|
#[Serializer\Groups(['api_v1_search', 'api_v1_show'])]
|
|
|
|
#[ORM\Column(name: 'discovered_on', type: 'integer', nullable: false)]
|
2018-06-20 19:30:00 +00:00
|
|
|
private $discoveredOn;
|
|
|
|
|
2022-07-08 01:46:36 +00:00
|
|
|
/** @var File[]|ArrayCollection */
|
|
|
|
#[Serializer\Groups(['api_v1_show'])]
|
|
|
|
#[ORM\OneToMany(targetEntity: File::class, fetch: 'EXTRA_LAZY', mappedBy: 'torrent')]
|
2018-06-20 19:30:00 +00:00
|
|
|
private $files;
|
|
|
|
|
|
|
|
public function getId(): int
|
|
|
|
{
|
|
|
|
return $this->id;
|
|
|
|
}
|
|
|
|
|
2018-06-22 19:47:51 +00:00
|
|
|
/** Returns torrent info hash as HEX string */
|
2018-06-22 19:45:17 +00:00
|
|
|
public function getInfoHash(): 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;
|
|
|
|
}
|
|
|
|
}
|