1 | <?php |
||
2 | /** |
||
3 | * This file is part of the Divergence package. |
||
4 | * |
||
5 | * (c) Henry Paradiz <[email protected]> |
||
6 | * |
||
7 | * For the full copyright and license information, please view the LICENSE |
||
8 | * file that was distributed with this source code. |
||
9 | */ |
||
10 | |||
11 | namespace Divergence\Responders; |
||
12 | |||
13 | use GuzzleHttp\Psr7\Utils; |
||
14 | use Psr\Http\Message\StreamInterface; |
||
15 | |||
16 | class MediaBuilder extends ResponseBuilder |
||
17 | { |
||
18 | private ?int $start; |
||
19 | private ?int $end; |
||
20 | private ?int $length; |
||
21 | |||
22 | 5 | public function setRange($start, $end, $length) |
|
23 | { |
||
24 | 5 | $this->start = $start; |
|
25 | 5 | $this->end = $end; |
|
26 | 5 | $this->length = $length; |
|
27 | } |
||
28 | |||
29 | 12 | public function setContentType(string $contentType): void |
|
30 | { |
||
31 | 12 | $this->contentType = $contentType; |
|
32 | } |
||
33 | |||
34 | 10 | public function getBody(): StreamInterface |
|
35 | { |
||
36 | 10 | if (isset($this->start)) { |
|
37 | 5 | $fp = fopen($this->template, 'r'); |
|
38 | 5 | fseek($fp, $this->start); |
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
39 | 5 | $stream = Utils::streamFor($fp); |
|
40 | 5 | return Utils::streamFor($stream->getContents()); |
|
41 | } |
||
42 | 5 | return Utils::streamFor(fopen($this->template, 'r')); |
|
43 | } |
||
44 | } |
||
45 |