lithium\net\socket\Curl::write PHP Method

write() public method

Writes data to curl options
public write ( array | Message $data = null ) : boolean
$data array | lithium\net\Message
return boolean
    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 (bool) curl_setopt_array($this->_resource, $this->options);
    }

Usage Example

Example #1
0
 public function testWriteAndRead()
 {
     $stream = new Curl($this->_testConfig);
     $this->assertTrue(is_resource($stream->open()));
     $this->assertTrue(is_resource($stream->resource()));
     $this->assertEqual(1, $stream->write());
     $this->assertPattern("/^HTTP/", (string) $stream->read());
 }
All Usage Examples Of lithium\net\socket\Curl::write