-
Notifications
You must be signed in to change notification settings - Fork 0
/
BrowserOptions.php
135 lines (113 loc) · 3.12 KB
/
BrowserOptions.php
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 Poirot\HttpAgent;
use Poirot\Std\Interfaces\Struct\iDataStruct;
use Poirot\Std\Struct\OpenOptionsData;
use Poirot\Std\Traits\CloneTrait;
use Poirot\HttpAgent\Transporter\HttpTransporterOptions;
use Poirot\PathUri\HttpUri;
use Poirot\PathUri\Interfaces\iHttpUri;
use Poirot\PathUri\Psr\UriInterface;
/**
* This is open options because may contains options for attached plugins
*/
class BrowserOptions extends OpenOptionsData
{
use CloneTrait;
/** @var string|iHttpUri|UriInterface Base Url to Server */
protected $baseUrl = VOID;
protected $userAgent = VOID;
# default element options
/** @var HttpTransporterOptions */
protected $connection;
/** @var BrowserRequestOptions */
protected $request;
/**
* @param iHttpUri|UriInterface|string $baseUrl
* @return $this
*/
public function setBaseUrl($baseUrl)
{
if (is_string($baseUrl) || $baseUrl instanceof UriInterface)
$baseUrl = new HttpUri($baseUrl);
if (!$baseUrl instanceof iHttpUri)
throw new \InvalidArgumentException(sprintf(
'BaseUrl must instance of iHttpUri, UriInterface or string. given: "%s"'
, \Poirot\Std\flatten($baseUrl)
));
$this->baseUrl = $baseUrl;
return $this;
}
/**
* @return iHttpUri|VOID
*/
public function getBaseUrl()
{
return $this->baseUrl;
}
/**
* @param mixed $userAgent
* @return $this
*/
public function setUserAgent($userAgent)
{
$this->userAgent = (string) $userAgent;
return $this;
}
/**
* @return mixed
*/
public function getUserAgent()
{
if (!$this->userAgent || $this->userAgent === VOID) {
$userAgent = '';
if (!$userAgent) {
$userAgent = 'PoirotBrowser';
$userAgent .= '-PHP/' . PHP_VERSION;
}
$this->setUserAgent($userAgent);
}
return $this->userAgent;
}
// ...
/**
* Set Connection Options
*
* @param array|iDataStruct|HttpTransporterOptions $connection
* @return $this
*/
public function setConnection($connection)
{
// TODO catch exception for bright exception message
$this->getConnection()->from($connection);
return $this;
}
/**
* @return HttpTransporterOptions
*/
public function getConnection()
{
if (!$this->connection || $this->connection === VOID)
$this->connection = new HttpTransporterOptions;
return $this->connection;
}
/**
* Set Request Options Params
* @param mixed $request
* @return $this
*/
public function setRequest($request)
{
// TODO catch exception for bright exception message
$this->getRequest()->from($request);
return $this;
}
/**
* @return BrowserRequestOptions
*/
public function getRequest()
{
if (!$this->request || $this->request === VOID)
$this->request = new BrowserRequestOptions;
return $this->request;
}
}