2022-06-10 10:47:46 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Values;
|
|
|
|
|
|
|
|
use App\Http\Requests\API\SongUpdateRequest;
|
|
|
|
use Illuminate\Contracts\Support\Arrayable;
|
|
|
|
|
|
|
|
final class SongUpdateData implements Arrayable
|
|
|
|
{
|
|
|
|
private function __construct(
|
|
|
|
public ?string $title,
|
|
|
|
public ?string $artistName,
|
|
|
|
public ?string $albumName,
|
|
|
|
public ?string $albumArtistName,
|
|
|
|
public ?int $track,
|
|
|
|
public ?int $disc,
|
2022-09-23 06:21:29 +00:00
|
|
|
public ?string $genre,
|
|
|
|
public ?int $year,
|
2022-06-10 10:47:46 +00:00
|
|
|
public ?string $lyrics,
|
|
|
|
) {
|
|
|
|
$this->albumArtistName = $this->albumArtistName ?: $this->artistName;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function fromRequest(SongUpdateRequest $request): self
|
|
|
|
{
|
|
|
|
return new self(
|
|
|
|
title: $request->input('data.title'),
|
|
|
|
artistName: $request->input('data.artist_name'),
|
|
|
|
albumName: $request->input('data.album_name'),
|
|
|
|
albumArtistName: $request->input('data.album_artist_name'),
|
2022-07-21 08:08:17 +00:00
|
|
|
track: (int) $request->input('data.track'),
|
|
|
|
disc: (int) $request->input('data.disc'),
|
2022-09-23 06:21:29 +00:00
|
|
|
genre: $request->input('data.genre'),
|
2022-11-29 12:16:43 +00:00
|
|
|
year: (int) $request->input('data.year'),
|
2022-06-10 10:47:46 +00:00
|
|
|
lyrics: $request->input('data.lyrics'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function make(
|
|
|
|
?string $title,
|
|
|
|
?string $artistName,
|
|
|
|
?string $albumName,
|
|
|
|
?string $albumArtistName,
|
|
|
|
?int $track,
|
|
|
|
?int $disc,
|
2022-09-23 06:21:29 +00:00
|
|
|
?string $genre,
|
|
|
|
?int $year,
|
2022-06-10 10:47:46 +00:00
|
|
|
?string $lyrics
|
|
|
|
): self {
|
|
|
|
return new self(
|
|
|
|
$title,
|
|
|
|
$artistName,
|
|
|
|
$albumName,
|
|
|
|
$albumArtistName,
|
|
|
|
$track,
|
|
|
|
$disc,
|
2022-09-23 06:21:29 +00:00
|
|
|
$genre,
|
|
|
|
$year,
|
2022-06-10 10:47:46 +00:00
|
|
|
$lyrics,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @return array<string, mixed> */
|
|
|
|
public function toArray(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'title' => $this->title,
|
|
|
|
'artist' => $this->artistName,
|
|
|
|
'album' => $this->albumName,
|
|
|
|
'album_artist' => $this->albumArtistName,
|
|
|
|
'track' => $this->track,
|
|
|
|
'disc' => $this->disc,
|
2022-09-23 06:21:29 +00:00
|
|
|
'genre' => $this->genre,
|
|
|
|
'year' => $this->year,
|
2022-06-10 10:47:46 +00:00
|
|
|
'lyrics' => $this->lyrics,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|