当前位置: 首页>>代码示例>>PHP>>正文


PHP Zend_Feed_Reader::getHttpClient方法代码示例

本文整理汇总了PHP中Zend_Feed_Reader::getHttpClient方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Feed_Reader::getHttpClient方法的具体用法?PHP Zend_Feed_Reader::getHttpClient怎么用?PHP Zend_Feed_Reader::getHttpClient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend_Feed_Reader的用法示例。


在下文中一共展示了Zend_Feed_Reader::getHttpClient方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testGetsFeedLinksAndNormalisesRelativeUrlsOnUriWithPath

 /**
  * @group ZF-8330
  */
 public function testGetsFeedLinksAndNormalisesRelativeUrlsOnUriWithPath()
 {
     try {
         $currClient = Zend_Feed_Reader::getHttpClient();
         $testAdapter = new Zend_Http_Client_Adapter_Test();
         $testAdapter->setResponse(new Zend_Http_Response(200, array(), '<!DOCTYPE html><html><head><link rel="alternate" type="application/rss+xml" href="../test.rss"><link rel="alternate" type="application/atom+xml" href="/test.atom"></head><body></body></html>'));
         Zend_Feed_Reader::setHttpClient(new Zend_Http_Client(null, array('adapter' => $testAdapter)));
         $links = Zend_Feed_Reader::findFeedLinks('http://foo/bar');
         Zend_Feed_Reader::setHttpClient($currClient);
     } catch (Exception $e) {
         $this->fail($e->getMessage());
     }
     $this->assertEquals('http://foo/test.rss', $links->rss);
     $this->assertEquals('http://foo/test.atom', $links->atom);
 }
开发者ID:SustainableCoastlines,项目名称:loveyourwater,代码行数:18,代码来源:ReaderTest.php

示例2: _processResources

 private static function _processResources(array $config)
 {
     if (self::$_lock) {
         /**
          * @see Conjoon_Log
          */
         require_once 'Conjoon/Log.php';
         Conjoon_Log::log("Conjoon_Modules_Groupware_Feeds_ImportHelper::_processResources " . "- possible race condition", Zend_Log::INFO);
     }
     self::$_lock = true;
     $uri = $config['uri'];
     $requestTimeout = $config['requestTimeout'];
     $useCache = $config['useCache'];
     $useConditionalGet = $config['useConditionalGet'];
     $callback = $config['callback'];
     /**
      * @see Zend_Feed_Reader
      */
     require_once 'Zend/Feed/Reader.php';
     if ($useCache !== false) {
         // set the reader's cache here
         /**
          * @see Conjoon_Cache_Factory
          */
         require_once 'Conjoon/Cache/Factory.php';
         /**
          * @see Conjoon_Keys
          */
         require_once 'Conjoon/Keys.php';
         $frCache = Conjoon_Cache_Factory::getCache(Conjoon_Keys::CACHE_FEED_READER, Zend_Registry::get(Conjoon_Keys::REGISTRY_CONFIG_OBJECT)->toArray());
         if ($frCache) {
             Zend_Feed_Reader::setCache($frCache);
             if ($useConditionalGet !== false) {
                 Zend_Feed_Reader::useHttpConditionalGet();
             }
         }
     }
     Zend_Feed_Reader::getHttpClient()->setConfig(array('timeout' => $requestTimeout));
     $result = self::$callback($uri);
     Zend_Feed_Reader::reset();
     self::$_lock = false;
     return $result;
 }
开发者ID:ThorstenSuckow,项目名称:conjoon,代码行数:43,代码来源:ImportHelper.php

示例3: testImportingUriWithEmptyResponseBodyTriggersException

 /**
  * @group ZF-11184
  */
 public function testImportingUriWithEmptyResponseBodyTriggersException()
 {
     $currClient = Zend_Feed_Reader::getHttpClient();
     $testAdapter = new Zend_Http_Client_Adapter_Test();
     $testAdapter->setResponse(new Zend_Http_Response(200, array(), ''));
     Zend_Feed_Reader::setHttpClient(new Zend_Http_Client(null, array('adapter' => $testAdapter)));
     $this->setExpectedException('Zend_Feed_Exception', 'Feed failed to load');
     $result = Zend_Feed_Reader::import('http://www.example.com');
 }
开发者ID:omusico,项目名称:logica,代码行数:12,代码来源:ReaderTest.php

示例4: _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;
 }
开发者ID:RobertoMalatesta,项目名称:trade-capture,代码行数:59,代码来源:CaptureController.php


注:本文中的Zend_Feed_Reader::getHttpClient方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。