slovocast/app/src/Domain/Entity/Episode/File.php

82 lines
1.7 KiB
PHP

<?php
namespace Slovocast\Domain\Entity\Episode;
use Slovocast\Domain\Entity as EntityTrait;
/**
* Represents the data about the specific file that is used for the episode.
*/
class File
{
use EntityTrait;
/**
* We should also be able to buffer the raw binary data of the buffer to
* the class. Fuck it, we ball.
*/
private string $buffer = "";
/**
* @param string $url The URL can be a full file location on the disk, or
* a remote URL. It does not matter
* @param int $length The length of the episode in seconds
* @param string $type The audio file type
*/
public function __construct(
private string $url,
private int $length,
private string $type
) { }
public function getUrl(): string
{
return $this->url;
}
public function getLength(): int
{
return $this->length;
}
public function getType(): string
{
return $this->type;
}
public function setBuffer(string $buffer): void
{
$this->buffer = $buffer;
}
public function getBuffer(): string
{
return $this->buffer;
}
/**
* @param array $props Properties and their values.
*/
public static function fromArray(array $props): File
{
$file = new self(
$props['url'],
(int) $props['length'],
$props['type']
);
if ($props['id']) {
$file->setId($props['id']);
}
if ($props['createAt']) {
$file->setCreatedAt($props['createdAt']);
}
if ($props['updatedAt']) {
$file->setUpdatedAt($props['updatedAt']);
}
return $file;
}
}