|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the bugloos/export-bundle project. |
|
5
|
|
|
* (c) Bugloos <https://bugloos.com/> |
|
6
|
|
|
* For the full copyright and license information, please view |
|
7
|
|
|
* the LICENSE file that was distributed with this source code. |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Bugloos\ExportBundle\Response; |
|
11
|
|
|
|
|
12
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
13
|
|
|
use Symfony\Component\HttpFoundation\ResponseHeaderBag; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @author Mojtaba Gheytasi <[email protected] | [email protected]> |
|
17
|
|
|
*/ |
|
18
|
|
|
class GeneralResponse extends Response |
|
19
|
|
|
{ |
|
20
|
|
|
public function __construct( |
|
21
|
|
|
$content, |
|
22
|
|
|
$fileName, |
|
23
|
|
|
$contentType, |
|
24
|
|
|
$contentDisposition = 'attachment', |
|
25
|
|
|
$status = self::HTTP_OK, |
|
26
|
|
|
$headers = [] |
|
27
|
|
|
) { |
|
28
|
|
|
$contentDispositionDirectives = [ |
|
29
|
|
|
ResponseHeaderBag::DISPOSITION_INLINE, |
|
30
|
|
|
ResponseHeaderBag::DISPOSITION_ATTACHMENT, |
|
31
|
|
|
]; |
|
32
|
|
|
|
|
33
|
|
|
if (!\in_array($contentDisposition, $contentDispositionDirectives)) { |
|
34
|
|
|
throw new \InvalidArgumentException( |
|
35
|
|
|
sprintf('Expected one of the following directives: "%s", but "%s" given.', |
|
36
|
|
|
implode('", "', $contentDispositionDirectives), $contentDisposition) |
|
37
|
|
|
); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
parent::__construct($content, $status, $headers); |
|
41
|
|
|
|
|
42
|
|
|
$this->headers->add(['Content-Type' => $contentType]); |
|
43
|
|
|
|
|
44
|
|
|
$this->headers->add([ |
|
45
|
|
|
'Content-Disposition' => $this->headers->makeDisposition($contentDisposition, $fileName), |
|
46
|
|
|
]); |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|