mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-29 09:18:54 +00:00
59 lines
1.7 KiB
PHP
59 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Services\TvProcessing;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* Value object containing release information for TV processing.
|
|
*/
|
|
class TvReleaseContext
|
|
{
|
|
public function __construct(
|
|
public readonly int $releaseId,
|
|
public readonly string $searchName,
|
|
public readonly int $groupsId,
|
|
public readonly int $categoriesId,
|
|
public readonly int $videosId = 0,
|
|
public readonly int $tvEpisodesId = 0,
|
|
public readonly ?string $guid = null,
|
|
public readonly ?string $leftGuid = null,
|
|
) {}
|
|
|
|
/**
|
|
* Create from a Release model array/object.
|
|
*
|
|
* @param array<string, mixed> $release
|
|
*/
|
|
public static function fromRelease(array|object $release): self
|
|
{
|
|
// Handle Eloquent models properly - use toArray() instead of casting
|
|
if ($release instanceof Model) {
|
|
$data = $release->toArray();
|
|
} else {
|
|
$data = is_array($release) ? $release : (array) $release;
|
|
}
|
|
|
|
return new self(
|
|
releaseId: (int) ($data['id'] ?? 0),
|
|
searchName: (string) ($data['searchname'] ?? ''),
|
|
groupsId: (int) ($data['groups_id'] ?? 0),
|
|
categoriesId: (int) ($data['categories_id'] ?? 0),
|
|
videosId: (int) ($data['videos_id'] ?? 0),
|
|
tvEpisodesId: (int) ($data['tv_episodes_id'] ?? 0),
|
|
guid: $data['guid'] ?? null,
|
|
leftGuid: $data['leftguid'] ?? null,
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Check if the release name matches a pattern.
|
|
*/
|
|
public function matchesPattern(string $pattern): bool
|
|
{
|
|
return (bool) preg_match($pattern, (string) $this->searchName);
|
|
}
|
|
}
|