1 | <?php |
||
2 | |||
3 | namespace App\Services\Streamers; |
||
4 | |||
5 | use App\Models\Song; |
||
6 | |||
7 | class Streamer |
||
8 | { |
||
9 | /** |
||
10 | * @var Song|string |
||
11 | */ |
||
12 | protected $song; |
||
13 | |||
14 | /** |
||
15 | * @var string |
||
16 | */ |
||
17 | protected $contentType; |
||
18 | |||
19 | 11 | public function __construct() |
|
20 | { |
||
21 | // Turn off error reporting to make sure our stream isn't interfered. |
||
22 | 11 | @error_reporting(0); |
|
0 ignored issues
–
show
|
|||
23 | 11 | } |
|
24 | |||
25 | 6 | public function setSong(Song $song): void |
|
26 | { |
||
27 | 6 | $this->song = $song; |
|
28 | |||
29 | 6 | abort_unless($this->song->s3_params || file_exists($this->song->path), 404); |
|
30 | |||
31 | // Hard code the content type instead of relying on PHP's fileinfo() |
||
32 | // or even Symfony's MIMETypeGuesser, since they appear to be wrong sometimes. |
||
33 | 6 | if (!$this->song->s3_params) { |
|
34 | 5 | $this->contentType = 'audio/'.pathinfo($this->song->path, PATHINFO_EXTENSION); |
|
35 | } |
||
36 | 6 | } |
|
37 | } |
||
38 |
If you suppress an error, we recommend checking for the error condition explicitly: