NNTmux /
newznab-tmux
| 1 | <?php |
||
| 2 | |||
| 3 | namespace App\Services\TvProcessing; |
||
| 4 | |||
| 5 | /** |
||
| 6 | * Value object containing release information for TV processing. |
||
| 7 | */ |
||
| 8 | class TvReleaseContext |
||
| 9 | { |
||
| 10 | public function __construct( |
||
| 11 | public readonly int $releaseId, |
||
| 12 | public readonly string $searchName, |
||
| 13 | public readonly int $groupsId, |
||
| 14 | public readonly int $categoriesId, |
||
| 15 | public readonly int $videosId = 0, |
||
| 16 | public readonly int $tvEpisodesId = 0, |
||
| 17 | public readonly ?string $guid = null, |
||
| 18 | public readonly ?string $leftGuid = null, |
||
| 19 | ) {} |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Create from a Release model array/object. |
||
| 23 | */ |
||
| 24 | public static function fromRelease(array|object $release): self |
||
| 25 | { |
||
| 26 | // Handle Eloquent models properly - use toArray() instead of casting |
||
| 27 | if ($release instanceof \Illuminate\Database\Eloquent\Model) { |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 28 | $data = $release->toArray(); |
||
| 29 | } else { |
||
| 30 | $data = is_array($release) ? $release : (array) $release; |
||
|
0 ignored issues
–
show
|
|||
| 31 | } |
||
| 32 | |||
| 33 | return new self( |
||
| 34 | releaseId: (int) ($data['id'] ?? 0), |
||
| 35 | searchName: $data['searchname'] ?? '', |
||
| 36 | groupsId: (int) ($data['groups_id'] ?? 0), |
||
| 37 | categoriesId: (int) ($data['categories_id'] ?? 0), |
||
| 38 | videosId: (int) ($data['videos_id'] ?? 0), |
||
| 39 | tvEpisodesId: (int) ($data['tv_episodes_id'] ?? 0), |
||
| 40 | guid: $data['guid'] ?? null, |
||
| 41 | leftGuid: $data['leftguid'] ?? null, |
||
| 42 | ); |
||
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Check if the release name matches a pattern. |
||
| 47 | */ |
||
| 48 | public function matchesPattern(string $pattern): bool |
||
| 49 | { |
||
| 50 | return (bool) preg_match($pattern, $this->searchName); |
||
| 51 | } |
||
| 52 | } |
||
| 53 | |||
| 54 |