Passed
Pull Request — master (#262)
by Pascal
02:52
created

InteractsWithHttpHeaders::mergeBeforePathInput()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 5
rs 10
1
<?php
2
3
namespace ProtoneMedia\LaravelFFMpeg\FFMpeg;
4
5
use Illuminate\Support\Collection;
6
7
trait InteractsWithHttpHeaders
8
{
9
    use InteractsWithInputPath;
10
11
    /**
12
     * @var array
13
     */
14
    protected $headers = [];
15
16
    public function getHeaders(): array
17
    {
18
        return $this->headers;
19
    }
20
21
    public function setHeaders(array $headers = []): self
22
    {
23
        $this->headers = $headers;
24
25
        return $this;
26
    }
27
28
    /**
29
     * Maps the headers into a key-value string for FFmpeg. Returns
30
     * an array of arguments to pass into the command.
31
     *
32
     * @param array $headers
33
     * @return array
34
     */
35
    public static function compileHeaders(array $headers = []): array
36
    {
37
        if (empty($headers)) {
38
            return [];
39
        }
40
41
        $headers = Collection::make($headers)->map(function ($value, $key) {
42
            return "{$key}: {$value}";
43
        })->filter()->push("")->implode("\r\n");
44
45
        return ['-headers', $headers];
46
    }
47
}
48