lithium\net\socket\Curl::write()
Implements
lithium\net\Socket::write()
Writes data to curl options
Parameters
-
array|\lithium\net\Message
$data
Returns
booleanSource
public function write($data = null) {
if (!is_resource($this->_resource)) {
return false;
}
if (!is_object($data)) {
$data = Libraries::instance(
null, 'request', (array) $data + $this->_config, $this->_classes
);
}
$this->set(CURLOPT_URL, $data->to('url'));
if ($data instanceof Message) {
if (!empty($this->_config['ignoreExpect'])) {
$data->headers('Expect', ' ');
}
if (isset($data->headers)) {
$this->set(CURLOPT_HTTPHEADER, $data->headers());
}
if (isset($data->method) && $data->method === 'POST') {
$this->set([CURLOPT_POST => true, CURLOPT_POSTFIELDS => $data->body()]);
}
if (isset($data->method) && in_array($data->method,['PUT','PATCH','DELETE'])) {
$this->set([
CURLOPT_CUSTOMREQUEST => $data->method,
CURLOPT_POSTFIELDS => $data->body()
]);
}
}
return (boolean) curl_setopt_array($this->_resource, $this->options);
}