1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the php-phantomjs. |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace JonnyW\PhantomJs\IO; |
11
|
|
|
|
12
|
|
|
use JonnyW\PhantomJs\Page\Cookie; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* PHP PhantomJs. |
16
|
|
|
* |
17
|
|
|
* @author Jon Wenmoth <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
trait InputTrait |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Cookies. |
23
|
|
|
* |
24
|
|
|
* @var array |
25
|
|
|
*/ |
26
|
|
|
private $cookies = [ |
27
|
|
|
'add' => [], |
28
|
|
|
'remove' => [], |
29
|
|
|
]; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Settings. |
33
|
|
|
* |
34
|
|
|
* (default value: []) |
35
|
|
|
* |
36
|
|
|
* @var array |
37
|
|
|
*/ |
38
|
|
|
private $settings = []; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Custom input settings. |
42
|
|
|
* |
43
|
|
|
* (default value: []) |
44
|
|
|
* |
45
|
|
|
* @var array |
46
|
|
|
*/ |
47
|
|
|
private $custom = []; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Create new input with |
51
|
|
|
* added custom setting. |
52
|
|
|
* |
53
|
|
|
* @param string $name |
54
|
|
|
* @param mixed $value |
55
|
|
|
* |
56
|
|
|
* @return \JonnyW\PhantomJs\IO\InputInterface |
57
|
|
|
*/ |
58
|
|
|
public function withCustom($name, $value) |
59
|
|
|
{ |
60
|
|
|
$new = clone $this; |
61
|
|
|
$new->custom[$name] = $value; |
62
|
|
|
|
63
|
|
|
return $new; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Create new input with |
68
|
|
|
* custom setting removed. |
69
|
|
|
* |
70
|
|
|
* @param string $name |
71
|
|
|
* |
72
|
|
|
* @return \JonnyW\PhantomJs\IO\InputInterface |
73
|
|
|
*/ |
74
|
|
|
public function withoutCustom($name) |
75
|
|
|
{ |
76
|
|
|
$new = clone $this; |
77
|
|
|
|
78
|
|
|
unset($new->custom[$name]); |
79
|
|
|
|
80
|
|
|
return $new; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Get custom setting. |
85
|
|
|
* |
86
|
|
|
* @return array |
87
|
|
|
*/ |
88
|
|
|
public function getCustom() |
89
|
|
|
{ |
90
|
|
|
return $this->custom; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Get all cookies. |
95
|
|
|
* |
96
|
|
|
* @return array |
97
|
|
|
*/ |
98
|
|
|
public function getCookies() |
99
|
|
|
{ |
100
|
|
|
return $this->cookies; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Create new input with |
105
|
|
|
* added cookie. |
106
|
|
|
* |
107
|
|
|
* @param \JonnyW\PhantomJs\Page\Cookie $cookie |
108
|
|
|
* |
109
|
|
|
* @return \JonnyW\PhantomJs\IO\InputInterface |
110
|
|
|
*/ |
111
|
|
|
public function withCookie(Cookie $cookie) |
112
|
|
|
{ |
113
|
|
|
$new = clone $this; |
114
|
|
|
$new->cookies['add'][$cookie->getName()] = $cookie; |
|
|
|
|
115
|
|
|
|
116
|
|
|
return $new; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Create new input with cookie |
121
|
|
|
* removed and flagged for delete. |
122
|
|
|
* |
123
|
|
|
* @param string $cookie |
124
|
|
|
* |
125
|
|
|
* @return \JonnyW\PhantomJs\IO\InputInterface |
126
|
|
|
*/ |
127
|
|
|
public function withoutCookie($cookie) |
128
|
|
|
{ |
129
|
|
|
$new = clone $this; |
130
|
|
|
$new->cookies['remove'][] = $cookie; |
131
|
|
|
|
132
|
|
|
unset($new->cookies['add'][$cookie]); |
133
|
|
|
|
134
|
|
|
return $new; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Get all settings. |
139
|
|
|
* |
140
|
|
|
* @return array |
141
|
|
|
*/ |
142
|
|
|
public function getSettings() |
143
|
|
|
{ |
144
|
|
|
return $this->settings; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Create new input with |
149
|
|
|
* added setting. |
150
|
|
|
* |
151
|
|
|
* @param string $setting |
152
|
|
|
* @param mixed $value |
153
|
|
|
* |
154
|
|
|
* @return \JonnyW\PhantomJs\IO\InputInterface |
155
|
|
|
*/ |
156
|
|
|
public function withSetting($setting, $value) |
157
|
|
|
{ |
158
|
|
|
$new = clone $this; |
159
|
|
|
$new->settings[$setting] = $value; |
160
|
|
|
|
161
|
|
|
return $new; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* Create new input with setting |
166
|
|
|
* removed. |
167
|
|
|
* |
168
|
|
|
* @param string $setting |
169
|
|
|
* |
170
|
|
|
* @return \JonnyW\PhantomJs\IO\InputInterface |
171
|
|
|
*/ |
172
|
|
|
public function withoutSetting($setting) |
173
|
|
|
{ |
174
|
|
|
$new = clone $this; |
175
|
|
|
|
176
|
|
|
unset($new->settings[$setting]); |
177
|
|
|
|
178
|
|
|
return $new; |
179
|
|
|
} |
180
|
|
|
} |
181
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.