1 | <?php |
||
22 | abstract class AbstractRequest extends AbstractMessage |
||
23 | { |
||
24 | //Compatible SCHEME |
||
25 | const HTTP = '/^http/'; |
||
26 | const FTP = '/^ftp/'; |
||
27 | const SSH = '/sftp|scp/'; |
||
28 | |||
29 | /** |
||
30 | * Request UserAgent |
||
31 | * Allow to identify the request initiator |
||
32 | * @var string |
||
33 | */ |
||
34 | protected $ua = "Bee4/Transport"; |
||
35 | |||
36 | /** |
||
37 | * Current client instance |
||
38 | * @var Client |
||
39 | */ |
||
40 | protected $client; |
||
41 | |||
42 | /** |
||
43 | * specific cURL options for the current request |
||
44 | * @var array |
||
45 | */ |
||
46 | protected $options; |
||
47 | |||
48 | /** |
||
49 | * @var Url |
||
50 | */ |
||
51 | protected $url; |
||
52 | |||
53 | /** |
||
54 | * Construct a new request object |
||
55 | * @param Url $url |
||
56 | * @param array $headers |
||
57 | */ |
||
58 | 16 | public function __construct(Url $url, array $headers = []) |
|
64 | |||
65 | /** |
||
66 | * Set the linked client |
||
67 | * @param Client $client |
||
68 | * @return AbstractRequest |
||
69 | */ |
||
70 | 11 | public function setClient(Client $client) |
|
75 | |||
76 | /** |
||
77 | * URL accessor |
||
78 | * @return Url |
||
79 | */ |
||
80 | 12 | public function getUrl() |
|
84 | |||
85 | /** |
||
86 | * cURL option collection accessor |
||
87 | * @return array |
||
88 | */ |
||
89 | 12 | public function getOptions() |
|
93 | |||
94 | /** |
||
95 | * Add specifically curl option list to current request |
||
96 | * @param array $options |
||
97 | * @return AbstractRequest |
||
98 | */ |
||
99 | 2 | public function addOptions(array $options) |
|
107 | |||
108 | /** |
||
109 | * Add an option for current request |
||
110 | * @param int $name |
||
111 | * @param mixed $value |
||
112 | * @return AbstractRequest |
||
113 | */ |
||
114 | 12 | public function addOption($name, $value) |
|
124 | |||
125 | /** |
||
126 | * Check if an option exists |
||
127 | * @param mixed $name |
||
128 | * @return boolean |
||
129 | */ |
||
130 | 11 | public function hasOption($name) |
|
134 | |||
135 | /** |
||
136 | * Prepare the request execution by adding specific cURL parameters |
||
137 | */ |
||
138 | abstract protected function prepare(); |
||
139 | |||
140 | /** |
||
141 | * Send method. |
||
142 | * To send a request, a client must be linked |
||
143 | * @return \Bee4\Transport\Message\Response |
||
144 | */ |
||
145 | 12 | public function send() |
|
158 | |||
159 | /** |
||
160 | * Retrieve the status message for the current request based on STATUS_XXX constants |
||
161 | * @param string $status |
||
162 | * @return string |
||
163 | */ |
||
164 | public function getStatusMessage($status) |
||
169 | |||
170 | /** |
||
171 | * Get the client UA for all requests |
||
172 | * @return string |
||
173 | */ |
||
174 | 9 | public function getUserAgent() |
|
178 | |||
179 | /** |
||
180 | * Set the client UA for current request |
||
181 | * @param string $ua |
||
182 | * @return AbstractRequest |
||
183 | */ |
||
184 | 1 | public function setUserAgent($ua) |
|
190 | } |
||
191 |