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 = $this->_instance($this->_classes['request'], (array) $data + $this->_config);
}
$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(array(CURLOPT_POST => true, CURLOPT_POSTFIELDS => $data->body()));
}
if (isset($data->method) && in_array($data->method,array('PUT','PATCH','DELETE'))) {
$this->set(array(
CURLOPT_CUSTOMREQUEST => $data->method,
CURLOPT_POSTFIELDS => $data->body()
));
}
}
return (boolean) curl_setopt_array($this->_resource, $this->options);
}