XAccelRedirectStreamer   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 1
eloc 7
c 0
b 0
f 0
dl 0
loc 18
ccs 0
cts 7
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A stream() 0 13 1
1
<?php
2
3
namespace App\Services\Streamers;
4
5
use App\Models\Setting;
6
7
class XAccelRedirectStreamer extends Streamer implements DirectStreamerInterface
8
{
9
    /**
10
     * Stream the current song using nginx's X-Accel-Redirect.
11
     */
12
    public function stream(): void
13
    {
14
        $relativePath = str_replace(Setting::get('media_path'), '', $this->song->path);
15
16
        // We send our media_path value as a 'X-Media-Root' header to downstream (nginx)
17
        // It will then be use as `alias` in X-Accel config location block.
18
        // See nginx.conf.example.
19
        header('X-Media-Root: '.Setting::get('media_path'));
20
        header("X-Accel-Redirect: /media/$relativePath");
21
        header("Content-Type: {$this->contentType}");
22
        header('Content-Disposition: inline; filename="'.basename($this->song->path).'"');
23
24
        exit;
25
    }
26
}
27