1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: sdaoudi |
5
|
|
|
* Date: 25/03/18 |
6
|
|
|
* Time: 03:04 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace SfForward\Manager; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
use Psr\Http\Message\ResponseInterface; |
13
|
|
|
use SfForward\Util\PublicDirectory; |
14
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
15
|
|
|
use Symfony\Component\HttpFoundation\BinaryFileResponse; |
16
|
|
|
use Symfony\Component\HttpFoundation\Response; |
17
|
|
|
|
18
|
|
|
class ResponseManager |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var GuzzleResponse |
|
|
|
|
22
|
|
|
*/ |
23
|
|
|
protected $response; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected $projectDir; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* ResponseManager constructor. |
32
|
|
|
* |
33
|
|
|
* @param ResponseInterface $response |
34
|
|
|
* @param string $projectDir |
35
|
|
|
*/ |
36
|
|
|
public function __construct(ResponseInterface $response, $projectDir = __DIR__) |
37
|
|
|
{ |
38
|
|
|
$this->response = $response; |
|
|
|
|
39
|
|
|
$this->projectDir = $projectDir; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @return BinaryFileResponse|Response |
44
|
|
|
*/ |
45
|
|
|
public function getResponse() |
46
|
|
|
{ |
47
|
|
|
if ($this->response->hasHeader('Content-Disposition')) { |
48
|
|
|
return $this->getBinaryFileResponse(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return $this->getHttpResponse(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return BinaryFileResponse |
56
|
|
|
*/ |
57
|
|
|
protected function getBinaryFileResponse() |
58
|
|
|
{ |
59
|
|
|
$projectDir = PublicDirectory::getPublicDir($this->projectDir); |
60
|
|
|
$filename = $projectDir.mt_rand(); |
|
|
|
|
61
|
|
|
|
62
|
|
|
$fileSystem = new Filesystem(); |
63
|
|
|
$fileSystem->dumpFile( |
64
|
|
|
$filename, |
65
|
|
|
$this->response->getBody()->getContents() |
66
|
|
|
); |
67
|
|
|
|
68
|
|
|
return ( |
69
|
|
|
new BinaryFileResponse( |
70
|
|
|
$filename, |
71
|
|
|
$this->response->getStatusCode(), |
72
|
|
|
$this->response->getHeaders() |
73
|
|
|
) |
74
|
|
|
)->deleteFileAfterSend(true); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return Response |
79
|
|
|
*/ |
80
|
|
|
protected function getHttpResponse() |
81
|
|
|
{ |
82
|
|
|
$response = new Response($this->response->getBody()); |
83
|
|
|
$response->setStatusCode($this->response->getStatusCode()); |
84
|
|
|
|
85
|
|
|
return $response; |
86
|
|
|
} |
87
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths