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

82 lines
1.7 KiB
PHP
Raw Normal View History

<?php
namespace Slovocast\Domain\Entity\Episode;
2024-11-14 01:49:15 +00:00
use Slovocast\Domain\Entity as EntityTrait;
/**
2024-11-14 02:10:47 +00:00
* Represents the data about the specific file that is used for the episode.
*/
class File
{
2024-11-14 01:49:15 +00:00
use EntityTrait;
/**
* We should also be able to buffer the raw binary data of the buffer to
* the class. Fuck it, we ball.
*/
2024-11-14 01:49:15 +00:00
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;
}
2024-11-14 01:49:15 +00:00
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;
}
}