本文整理汇总了PHP中Zend_Feed_Reader::setHttpClient方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Feed_Reader::setHttpClient方法的具体用法?PHP Zend_Feed_Reader::setHttpClient怎么用?PHP Zend_Feed_Reader::setHttpClient使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Feed_Reader
的用法示例。
在下文中一共展示了Zend_Feed_Reader::setHttpClient方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例2: synchronise
public function synchronise(Zend_Feed_Reader_FeedAbstract $feed = null)
{
if (is_null($feed)) {
Zend_Feed_Reader::setHttpClient($this->getHttpClient());
try {
$feed = Zend_Feed_Reader::import($this->uri);
} catch (Exception $e) {
$message = 'Failed Feed Import (' . $this->uri . '): ' . get_class($e) . ': ' . $e->getMessage() . PHP_EOL . 'Stack Trace: ' . PHP_EOL . $e->getTraceAsString();
$this->getLogger()->log($message, Zend_Log::ERR);
return;
}
}
if ($this->uri !== $feed->getFeedLink() && !is_null($feed->getFeedLink())) {
$this->uri = $feed->getFeedLink();
$this->save();
}
foreach ($feed as $entry) {
$entryHash = md5(trim($entry->getTitle()) . trim($entry->getDescription()) . trim($entry->getContent()));
$currentEntry = Doctrine_Query::create()->from('Zfplanet_Model_Entry')->where('feedId = ?', $this->id)->andWhere('id = ?', $entry->getId())->fetchone();
if ($currentEntry && $entryHash == $currentEntry->signatureHash) {
continue;
} elseif ($currentEntry) {
$this->_setCommonData($currentEntry, $entry, $entryHash);
$currentEntry->save();
if ($lindexer = $this->getLuceneIndexer()) {
try {
$lindexer->update($currentEntry);
} catch (Exception $e) {
$message = 'Failed Lucene Indexing (' . $this->uri . '): ' . get_class($e) . ': ' . $e->getMessage() . PHP_EOL . 'Stack Trace: ' . PHP_EOL . $e->getTraceAsString();
$this->getLogger()->log($message, Zend_Log::ERR);
return;
}
}
} else {
$newEntry = new Zfplanet_Model_Entry();
$newEntry->id = $entry->getId();
$newEntry->feedId = $this->id;
$newEntry->uri = $entry->getLink();
$this->_setCommonData($newEntry, $entry, $entryHash);
$newEntry->publishedDate = $entry->getDateCreated()->get(Zend_Date::ISO_8601);
$newEntry->isActive = 1;
$newEntry->save();
if ($tnotifier = $this->getTwitterNotifier()) {
try {
$tnotifier->notify($newEntry);
} catch (Exception $e) {
$message = 'Failed Twitter Notification: ' . get_class($e) . ': ' . $e->getMessage() . PHP_EOL . 'Stack Trace: ' . PHP_EOL . $e->getTraceAsString();
$this->getLogger()->log($message, Zend_Log::ERR);
}
}
if ($lindexer = $this->getLuceneIndexer()) {
try {
$lindexer->index($newEntry);
} catch (Exception $e) {
$message = 'Failed Lucene Indexing (' . $this->uri . '): ' . get_class($e) . ': ' . $e->getMessage() . PHP_EOL . 'Stack Trace: ' . PHP_EOL . $e->getTraceAsString();
$this->getLogger()->log($message, Zend_Log::ERR);
return;
}
}
}
}
}
示例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');
}