Can accept either a pre-existing stream context resource, or an array
of stream options, similar to the options array passed to the
stream_context_create() PHP function. In such case a new stream context
will be created using the passed options.
public setStreamContext ( mixed $context ) : Zend_Http_Client_Adapter_Socket | ||
$context | mixed | Stream context or array of context options |
리턴 | Zend_Http_Client_Adapter_Socket |
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; } }
/** * 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; }
/** * 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; }