本文整理汇总了PHP中Zend_Http_Client_Adapter_Socket::setStreamContext方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Http_Client_Adapter_Socket::setStreamContext方法的具体用法?PHP Zend_Http_Client_Adapter_Socket::setStreamContext怎么用?PHP Zend_Http_Client_Adapter_Socket::setStreamContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Http_Client_Adapter_Socket
的用法示例。
在下文中一共展示了Zend_Http_Client_Adapter_Socket::setStreamContext方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate
public function validate($username, $password)
{
if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Options: ' . print_r($this->_options, true));
}
$url = isset($this->_options['url']) ? $this->_options['url'] : 'https://localhost/validate/check';
$adapter = new Zend_Http_Client_Adapter_Socket();
$adapter->setStreamContext($this->_options = array('ssl' => array('verify_peer' => isset($this->_options['ignorePeerName']) ? false : true, 'allow_self_signed' => isset($this->_options['allowSelfSigned']) ? true : false)));
$client = new Zend_Http_Client($url, array('maxredirects' => 0, 'timeout' => 30));
$client->setAdapter($adapter);
$params = array('user' => $username, 'pass' => $password);
$client->setParameterPost($params);
try {
$response = $client->request(Zend_Http_Client::POST);
} catch (Zend_Http_Client_Adapter_Exception $zhcae) {
Tinebase_Exception::log($zhcae);
return Tinebase_Auth::FAILURE;
}
$body = $response->getBody();
if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Request: ' . $client->getLastRequest());
}
if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Response: ' . $body);
}
if ($response->getStatus() !== 200) {
return Tinebase_Auth::FAILURE;
}
$result = Tinebase_Helper::jsonDecode($body);
if (isset($result['result']) && $result['result']['status'] === true && $result['result']['value'] === true) {
return Tinebase_Auth::SUCCESS;
} else {
return Tinebase_Auth::FAILURE;
}
}
示例2: __construct
/**
* Constructor
*
* Accepts a Zend_Http_Client argument enabling the implementer to use
* a custom client (custom stream context, etc). Unless specified, a
* default client is used with some common stream context options
*
* @param Zend_Http_Client $client
* @throws CheddarGetter_Client_Exception Throws an exception
* if Zend_Http_Client is not available.
*/
public function __construct(Zend_Http_Client $client = null)
{
if (!class_exists('Zend_Http_Client')) {
throw new CheddarGetter_Client_Exception('Zend_Http_Client is not available.', CheddarGetter_Client_Exception::USAGE_INVALID);
}
// default client
if (!$client) {
$userAgent = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] . ' - CheddarGetter_Client PHP' : 'CheddarGetter_Client PHP';
// socket adapter with custom stream context
$options = array('http' => array('follow_location' => 0, 'max_redirects' => 0, 'timeout' => 100, 'user_agent' => $userAgent), 'ssl' => array('verify_peer' => true, 'allow_self_signed' => false));
$adapter = new Zend_Http_Client_Adapter_Socket();
$adapter->setStreamContext($options);
$client = new Zend_Http_Client(null, array('userAgent' => $options['http']['user_agent'], 'timeout' => 120));
$client->setAdapter($adapter);
}
$this->_client = $client;
}
示例3: _getFeedData
/**
* reads the RSS feeds and extracts the 'description' field from each one.
* Uses caching and http conditional GET to ensure that the feed is only
* read if it has been updated
*
* @return array
*/
protected function _getFeedData()
{
//Get the feed url from the configuration options
$options = $this->_getConfigOptions();
$feed_url = $options['feed']['url'];
$cache_dir = $options['cache']['directory'];
// set cache - this allows us to check whether the feed has been updated
$cache = Zend_Cache::factory('Core', 'File', array('lifetime' => null), array('cache_dir' => $cache_dir));
Zend_Feed_Reader::setCache($cache);
// set Reader properties to allow Conditional GET Requests
Zend_Feed_Reader::useHttpConditionalGet();
// disable SSL peer verification as it can cause problems from some isp's
$options = array('ssl' => array('verify_peer' => false, 'allow_self_signed' => true));
$adapter = new Zend_Http_Client_Adapter_Socket();
$adapter->setStreamContext($options);
Zend_Feed_Reader::getHttpClient()->setAdapter($adapter);
// interrogate the RSS feed
try {
$rss_data = Zend_Feed_Reader::import($feed_url);
} catch (Zend_Feed_Exception $e) {
// feed import failed
Zend_Registry::get('logger')->log('Exception importing feed: ' . $e->getMessage(), Zend_Log::WARN);
return null;
} catch (Zend_Http_Client_Exception $e) {
Zend_Registry::get('logger')->log('Error with URL: ' . $e->getMessage(), Zend_Log::WARN);
return null;
} catch (Exception $e) {
Zend_Registry::get('logger')->log('Unknown error when reading feed: ' . $e->getMessage(), Zend_Log::WARN);
return null;
}
$entries = array();
// response status will be 200 if new data, 304 if not modified
$last_response = Zend_Feed_Reader::getHttpClient()->getLastResponse();
if ($last_response) {
$response_status = $last_response->getStatus();
// Only process if new data
if (200 === $response_status) {
foreach ($rss_data as $item) {
$entry['description'] = $item->getDescription();
$entries[] = $entry;
}
if ($this->_getVerbose()) {
$this->getResponse()->appendBody(new Zend_Date() . ': ' . count($entries) . ' new entries downloaded from rss feed' . PHP_EOL);
}
} else {
if ($this->_getVerbose()) {
$this->getResponse()->appendBody(new Zend_Date() . ': ' . 'No new data found' . PHP_EOL);
}
}
}
return $entries;
}