Conditions | 7 |
Paths | 9 |
Total Lines | 28 |
Code Lines | 19 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
20 | public function sendContent() |
||
21 | { |
||
22 | /**@var File $file */ |
||
23 | $file = $this->laravelResponse->getFile(); |
||
24 | $this->swooleResponse->header('Content-Type', $file->getMimeType()); |
||
25 | if ($this->laravelResponse->getStatusCode() == BinaryFileResponse::HTTP_NOT_MODIFIED) { |
||
26 | $this->swooleResponse->end(); |
||
27 | } else { |
||
28 | $path = $file->getRealPath(); |
||
29 | if (filesize($path) > 0) { |
||
30 | if (version_compare(swoole_version(), '1.7.21', '<')) { |
||
31 | throw new \RuntimeException('sendfile() require Swoole >= 1.7.21'); |
||
32 | } |
||
33 | |||
34 | $this->swooleResponse->sendfile($path); |
||
35 | |||
36 | // Support deleteFileAfterSend: https://github.com/symfony/http-foundation/blob/5.0/BinaryFileResponse.php#L305 |
||
37 | $reflection = new \ReflectionObject($this->laravelResponse); |
||
38 | try { |
||
39 | $deleteFileAfterSend = $reflection->getProperty('deleteFileAfterSend'); |
||
40 | $deleteFileAfterSend->setAccessible(true); |
||
41 | if ($deleteFileAfterSend->getValue($this->laravelResponse) && file_exists($file->getPathname())) { |
||
42 | unlink($file->getPathname()); |
||
43 | } |
||
44 | } catch (\Exception $e) { |
||
|
|||
45 | } |
||
46 | } else { |
||
47 | $this->swooleResponse->end(); |
||
48 | } |
||
51 | } |