-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathPsr7DataQuery.php
More file actions
135 lines (117 loc) · 3.49 KB
/
Psr7DataQuery.php
File metadata and controls
135 lines (117 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
namespace exface\UrlDataConnector;
use exface\Core\CommonLogic\DataQueries\AbstractDataQuery;
use exface\UrlDataConnector\Interfaces\Psr7DataQueryInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use GuzzleHttp\Psr7\Request;
use Psr\Http\Message\UriInterface;
use Psr\Http\Message\StreamInterface;
use exface\Core\Widgets\DebugMessage;
use exface\Core\DataTypes\BooleanDataType;
use exface\Core\CommonLogic\Debugger\HttpMessageDebugger;
class Psr7DataQuery extends AbstractDataQuery implements Psr7DataQueryInterface
{
private $request;
private $response;
private $fixedUrl = false;
/**
* Returns a fully instantiated data query with a PSR-7 request.
* This is a shortcut for "new Psr7DataQuery(new Request)".
*
* @param string $method
* @param string|UriInterface $uri
* @param array $headers
* @param string|StreamInterface $body
* @param string $version
* @return \exface\UrlDataConnector\Psr7DataQuery
*/
public static function createRequest($method, $uri, array $headers = [], $body = null, $version = '1.1')
{
$request = new Request($method, $uri, $headers, $body, $version);
return new self($request);
}
/**
* Wraps a PSR-7 request in a data query, which can be used with the HttpDataConnector
*
* @param RequestInterface $request
*/
public function __construct(RequestInterface $request)
{
$this->setRequest($request);
}
/**
* {@inheritDoc}
* @see Psr7DataQueryInterface::getRequest()
*/
public function getRequest() : RequestInterface
{
return $this->request;
}
/**
*
* @param RequestInterface $value
* @return \exface\UrlDataConnector\Psr7DataQuery
*/
public function setRequest(RequestInterface $value)
{
$this->request = $value;
return $this;
}
/**
* {@inheritDoc}
* @see Psr7DataQueryInterface::getResponse()
*/
public function getResponse() : ?ResponseInterface
{
return $this->response;
}
/**
*
* @param ResponseInterface $value
* @return \exface\UrlDataConnector\Psr7DataQuery
*/
public function setResponse(ResponseInterface $value)
{
$this->response = $value;
return $this;
}
/**
*
* {@inheritDoc}
* @see \exface\Core\CommonLogic\DataQueries\AbstractDataQuery::createDebugWidget()
*/
public function createDebugWidget(DebugMessage $debug_widget)
{
if (null !== $request = $this->getRequest()) {
$renderer = new HttpMessageDebugger($request, $this->getResponse(), 'Data request', 'Data response');
$debug_widget = $renderer->createDebugWidget($debug_widget);
}
return $debug_widget;
}
/**
* @return boolean
*/
public function isUriFixed()
{
return $this->fixedUrl;
}
/**
* @param boolean $fixedUrl
* @return Psr7DataQuery
*/
public function setUriFixed($true_or_false)
{
$this->fixedUrl = BooleanDataType::cast($true_or_false);
return $this;
}
/**
*
* {@inheritDoc}
* @see \exface\Core\CommonLogic\DataQueries\AbstractDataQuery::toString()
*/
public function toString($prettify = true)
{
return $this->getRequest()->getUri()->__toString();
}
}