Pop\Curl\Curl::setOption PHP Method

setOption() public method

Set cURL session option(s).
public setOption ( array | integer $opt, string $val = null ) : Curl
$opt array | integer
$val string
return Curl
    public function setOption($opt, $val = null)
    {
        // If an array of options is passed.
        if (is_array($opt)) {
            // Set the cURL options from the array.
            curl_setopt_array($this->curl, $opt);
            // Set the protected property to the cURL options.
            foreach ($opt as $k => $v) {
                $this->options[$k] = $v;
            }
            // Else, set the single option.
        } else {
            curl_setopt($this->curl, $opt, $val);
            $this->options[$opt] = $val;
        }
        return $this;
    }

Usage Example

Beispiel #1
0
 public function testSetAndGetOptions()
 {
     $c = new Curl('http://www.popphp.org/version', array(CURLOPT_RETURNTRANSFER => true));
     $c->setOption(CURLOPT_HEADER, false);
     $this->assertEquals(1, $c->getOption(CURLOPT_RETURNTRANSFER));
     $this->assertEquals(0, $c->getOption(CURLOPT_HEADER));
 }
All Usage Examples Of Pop\Curl\Curl::setOption