本文整理匯總了PHP中Curl\Curl::setOpts方法的典型用法代碼示例。如果您正苦於以下問題:PHP Curl::setOpts方法的具體用法?PHP Curl::setOpts怎麽用?PHP Curl::setOpts使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Curl\Curl
的用法示例。
在下文中一共展示了Curl::setOpts方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testOptionSet
public function testOptionSet()
{
// Skip this test on 5.3, 5.4, and HHVM.
if (version_compare(PHP_VERSION, '5.5.0', '<') || defined('HHVM_VERSION')) {
$this->markTestSkipped();
}
$option = CURLOPT_ENCODING;
$value = 'gzip';
$null = chr(0);
// Ensure the option is stored when curl_setopt() succeeds.
$curl = new Curl();
$success = $curl->setOpt($option, $value);
$reflector = new ReflectionObject($curl);
$property = $reflector->getProperty('options');
$property->setAccessible(true);
$options = $property->getValue($curl);
$this->assertTrue($success);
$this->assertTrue(isset($options[$option]));
$this->assertEquals($value, $options[$option]);
// Ensure the option is not stored when curl_setopt() fails. Make curl_setopt() return false and suppress
// errors. Triggers warning: "curl_setopt(): Curl option contains invalid characters (\0)".
$curl = new Curl();
$success = @$curl->setOpt($option, $null);
$reflector = new ReflectionObject($curl);
$property = $reflector->getProperty('options');
$property->setAccessible(true);
$options = $property->getValue($curl);
$this->assertFalse($success);
$this->assertFalse(isset($options[$option]));
// Ensure options following a Curl::setOpt() failure are not set when using Curl::setOpts().
$options = array($option => $null, CURLOPT_COOKIE => 'a=b');
$curl = new Curl();
$success = @$curl->setOpts($options);
$reflector = new ReflectionObject($curl);
$property = $reflector->getProperty('options');
$property->setAccessible(true);
$options = $property->getValue($curl);
$this->assertFalse($success);
$this->assertFalse(isset($options[CURLOPT_COOKIE]));
// Ensure Curl::setOpts() returns true when all options are successfully set.
$options = array(CURLOPT_COOKIE => 'a=b', CURLOPT_FOLLOWLOCATION => true, CURLOPT_VERBOSE => true);
$curl = new Curl();
$success = $curl->setOpts($options);
$reflector = new ReflectionObject($curl);
$property = $reflector->getProperty('options');
$property->setAccessible(true);
$options = $property->getValue($curl);
$this->assertTrue($success);
$this->assertEquals('a=b', $options[CURLOPT_COOKIE]);
$this->assertTrue($options[CURLOPT_FOLLOWLOCATION]);
$this->assertTrue($options[CURLOPT_VERBOSE]);
}