1
|
|
|
<?php |
2
|
|
|
// +---------------------------------------------------------------------- |
3
|
|
|
// | SwooleResponse.php [ WE CAN DO IT JUST THINK IT ] |
4
|
|
|
// +---------------------------------------------------------------------- |
5
|
|
|
// | Copyright (c) 2016-2017 limingxinleo All rights reserved. |
6
|
|
|
// +---------------------------------------------------------------------- |
7
|
|
|
// | Author: limx <[email protected]> <https://github.com/limingxinleo> |
8
|
|
|
// +---------------------------------------------------------------------- |
9
|
|
|
|
10
|
|
|
namespace Gewaer\Http; |
11
|
|
|
|
12
|
|
|
use Phalcon\Http\Cookie; |
13
|
|
|
use Phalcon\Http\Response as PhResponse; |
14
|
|
|
use swoole_http_response; |
|
|
|
|
15
|
|
|
use Exception; |
16
|
|
|
|
17
|
|
|
class SwooleResponse extends Response |
18
|
|
|
{ |
19
|
|
|
protected $response; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Set the swoole response object |
23
|
|
|
* |
24
|
|
|
* @param swoole_http_response $response |
25
|
|
|
* @return void |
26
|
|
|
*/ |
27
|
|
|
public function init(swoole_http_response $response) |
28
|
|
|
{ |
29
|
|
|
$this->response = $response; |
30
|
|
|
$this->_sent = false; |
31
|
|
|
$this->_content = null; |
32
|
|
|
$this->setStatusCode(200); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Send the response |
37
|
|
|
* |
38
|
|
|
* @return PhResponse |
39
|
|
|
*/ |
40
|
|
|
public function send(): PhResponse |
41
|
|
|
{ |
42
|
|
|
if ($this->_sent) { |
43
|
|
|
throw new Exception('Response was already sent'); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
$this->_sent = true; |
47
|
|
|
// get phalcon headers |
48
|
|
|
$headers = $this->getHeaders(); |
49
|
|
|
|
50
|
|
|
foreach ($headers->toArray() as $key => $val) { |
51
|
|
|
//if the key has spaces this breaks postman, so we remove this headers |
52
|
|
|
//example: HTTP/1.1 200 OK || HTTP/1.1 401 Unauthorized |
53
|
|
|
if (!preg_match('/\s/', $key)) { |
54
|
|
|
$this->response->header($key, $val); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** @var Cookies $cookies */ |
59
|
|
|
$cookies = $this->getCookies(); |
60
|
|
|
if ($cookies) { |
|
|
|
|
61
|
|
|
/** @var Cookie $cookie */ |
62
|
|
|
foreach ($cookies->getCookies() as $cookie) { |
63
|
|
|
$this->response->cookie( |
64
|
|
|
$cookie->getName(), |
65
|
|
|
$cookie->getValue(), |
66
|
|
|
$cookie->getExpiration(), |
67
|
|
|
$cookie->getPath(), |
68
|
|
|
$cookie->getDomain(), |
69
|
|
|
$cookie->getSecure(), |
70
|
|
|
$cookie->getHttpOnly() |
71
|
|
|
); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
//set swoole response |
76
|
|
|
$this->response->status($this->getStatusCode()); |
77
|
|
|
$this->response->end($this->_content); |
78
|
|
|
|
79
|
|
|
//reest di |
80
|
|
|
$this->_sent = false; |
81
|
|
|
$this->getDi()->get('db')->close(); |
82
|
|
|
$this->getDi()->reset(); |
83
|
|
|
|
84
|
|
|
return $this; |
85
|
|
|
} |
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