本文整理汇总了PHP中Zend_Feed::getHttpClient方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Feed::getHttpClient方法的具体用法?PHP Zend_Feed::getHttpClient怎么用?PHP Zend_Feed::getHttpClient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Feed
的用法示例。
在下文中一共展示了Zend_Feed::getHttpClient方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getFeed
/**
* Get a feed
*
* @param int $id
* @return Feed
*/
public function getFeed($url)
{
$feed = $this->dbService->getByField(array('url' => $url), 'Feed');
$update = $feed == null || strtotime($feed->updated) < time() - 60 * 15;
if ($feed == null) {
$feed = new Feed();
}
if ($update) {
$this->log->debug("Loading feed {$url}");
// make the request!
// $feed->content =
$content = null;
try {
$client = Zend_Feed::getHttpClient();
$client->setUri($url);
$response = $client->request('GET');
if ($response->getStatus() !== 200) {
throw new Zend_Feed_Exception('Feed failed to load, got response code ' . $response->getStatus());
}
$content = $response->getBody();
} catch (Exception $zfe) {
$this->log->err("Failed loading feed from {$url}");
return $content;
}
$feed->content = $content;
$feed->url = $url;
$this->dbService->saveObject($feed);
}
return $feed;
}
示例2: __construct
/**
* Feed constructor
*
* The Zend_Feed_Abstract constructor takes the URI of a feed or a
* feed represented as a string and loads it as XML.
*
* @param string $uri The full URI of the feed to load, or NULL if not retrieved via HTTP or as an array.
* @param string $string The feed as a string, or NULL if retrieved via HTTP or as an array.
* @param Zend_Feed_Builder_Interface $builder The feed as a builder instance or NULL if retrieved as a string or via HTTP.
* @return void
* @throws Zend_Feed_Exception If loading the feed failed.
*/
public function __construct($uri = null, $string = null, Zend_Feed_Builder_Interface $builder = null)
{
if ($uri !== null) {
// Retrieve the feed via HTTP
$client = Zend_Feed::getHttpClient();
$client->setUri($uri);
$response = $client->request('GET');
if ($response->getStatus() !== 200) {
/**
* @see Zend_Feed_Exception
*/
#require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception('Feed failed to load, got response code ' . $response->getStatus());
}
$this->_element = $response->getBody();
$this->__wakeup();
} elseif ($string !== null) {
// Retrieve the feed from $string
$this->_element = $string;
$this->__wakeup();
} else {
// Generate the feed from the array
$header = $builder->getHeader();
$this->_element = new DOMDocument('1.0', $header['charset']);
$root = $this->_mapFeedHeaders($header);
$this->_mapFeedEntries($root, $builder->getEntries());
$this->_element = $root;
$this->_buildEntryCache();
}
}
示例3: setUp
public function setUp()
{
$this->_adapter = new Zend_Http_Client_Adapter_Test();
Zend_Feed::setHttpClient(new Zend_Http_Client(null, array('adapter' => $this->_adapter)));
$this->_client = Zend_Feed::getHttpClient();
$this->_feedDir = dirname(__FILE__) . '/_files';
}
示例4: importData
public function importData()
{
$url = $this->getProperty('url');
try {
$feeds = Zend_Feed::findFeeds($url);
} catch (Zend_Feed_Exception $e) {
return 0;
}
if (!$feeds) {
try {
$items = Zend_Feed::import($url);
} catch (Zend_Feed_Exception $e) {
return 0;
}
$feed_url = $url;
} else {
$items = $feeds[0];
$feed_url = Zend_Feed::getHttpClient()->getUri(true);
}
$title = $items->title();
$this->setProperty('feed_title', $title);
$this->setProperty('feed_url', $feed_url);
$items = $this->updateData();
$this->setImported(true);
return $items;
}
示例5: importData
public function importData()
{
$username = $this->getProperty('username');
$url = "http://feeds.launchpad.net/~{$username}/revisions.atom";
try {
$feeds = Zend_Feed::findFeeds($url);
} catch (Zend_Feed_Exception $e) {
return 0;
}
if (!$feeds) {
try {
$items = Zend_Feed::import($url);
} catch (Zend_Feed_Exception $e) {
return 0;
}
$feed_url = $url;
} else {
$items = $feeds[0];
$feed_url = Zend_Feed::getHttpClient()->getUri(true);
}
$title = $items->title();
$this->setProperty('feed_title', $title);
$this->setProperty('feed_url', $feed_url);
$items = $this->updateData();
$this->setImported(true);
return $items;
}
示例6: importData
public function importData()
{
$url = $this->getProperty('url');
$feeds = Zend_Feed::findFeeds($url);
if (!$feeds) {
$items = Zend_Feed::import($url);
$feed_url = $url;
} else {
$items = $feeds[0];
$feed_url = Zend_Feed::getHttpClient()->getUri(true);
}
$this->setProperty('feed_url', $feed_url);
$items = $this->processItems($items, 'published');
$this->setImported(true);
return $items;
}
示例7: __construct
/**
* Feed constructor
*
* The Zend_Feed_Abstract constructor takes the URI of a feed or a
* feed represented as a string and loads it as XML.
*
* @throws Zend_Feed_Exception If loading the feed failed.
*
* @param string $uri The full URI of the feed to load, or NULL if not retrieved via HTTP.
* @param string $string The feed as a string, or NULL if retrieved via HTTP.
*/
public function __construct($uri = null, $string = null)
{
if ($uri !== null) {
// Retrieve the feed via HTTP
$client = Zend_Feed::getHttpClient();
$client->setUri($uri);
$response = $client->request('GET');
if ($response->getStatus() !== 200) {
throw new Zend_Feed_Exception('Feed failed to load, got response code ' . $response->getStatus());
}
$this->_element = $response->getBody();
} else {
// Retrieve the feed from $string
$this->_element = $string;
}
$this->__wakeup();
}
示例8: save
/**
* Save a new or updated Atom entry.
*
* Save is used to either create new entries or to save changes to
* existing ones. If we have a link rel="edit", we are changing
* an existing entry. In this case we re-serialize the entry and
* PUT it to the edit URI, checking for a 200 OK result.
*
* For posting new entries, you must specify the $postUri
* parameter to save() to tell the object where to post itself.
* We use $postUri and POST the serialized entry there, checking
* for a 201 Created response. If the insert is successful, we
* then parse the response from the POST to get any values that
* the server has generated: an id, an updated time, and its new
* link rel="edit".
*
* @param string $postUri Location to POST for creating new entries.
* @return void
* @throws Zend_Feed_Exception
*/
public function save($postUri = null)
{
if ($this->id()) {
// If id is set, look for link rel="edit" in the
// entry object and PUT.
$editUri = $this->link('edit');
if (!$editUri) {
/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception('Cannot edit entry; no link rel="edit" is present.');
}
$client = Zend_Feed::getHttpClient();
$client->setUri($editUri);
if (Zend_Feed::getHttpMethodOverride()) {
$client->setHeaders(array('X-HTTP-Method-Override: PUT', 'Content-Type: ' . self::CONTENT_TYPE));
$client->setRawData($this->saveXML());
$response = $client->request('POST');
} else {
$client->setHeaders('Content-Type', self::CONTENT_TYPE);
$client->setRawData($this->saveXML());
$response = $client->request('PUT');
}
if ($response->getStatus() !== 200) {
/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception('Expected response code 200, got ' . $response->getStatus());
}
} else {
if ($postUri === null) {
/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception('PostURI must be specified to save new entries.');
}
$client = Zend_Feed::getHttpClient();
$client->setUri($postUri);
$client->setHeaders('Content-Type', self::CONTENT_TYPE);
$client->setRawData($this->saveXML());
$response = $client->request('POST');
if ($response->getStatus() !== 201) {
/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception('Expected response code 201, got ' . $response->getStatus());
}
}
// Update internal properties using $client->responseBody;
@ini_set('track_errors', 1);
$newEntry = new DOMDocument();
$status = @$newEntry->loadXML($response->getBody());
@ini_restore('track_errors');
if (!$status) {
// prevent the class to generate an undefined variable notice (ZF-2590)
if (!isset($php_errormsg)) {
if (function_exists('xdebug_is_enabled')) {
$php_errormsg = '(error message not available, when XDebug is running)';
} else {
$php_errormsg = '(error message not available)';
}
}
/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception('XML cannot be parsed: ' . $php_errormsg);
}
$newEntry = $newEntry->getElementsByTagName($this->_rootElement)->item(0);
if (!$newEntry) {
/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception('No root <feed> element found in server response:' . "\n\n" . $client->responseBody);
}
//.........这里部分代码省略.........
示例9: save
/**
* Save a new or updated Atom entry.
*
* Save is used to either create new entries or to save changes to
* existing ones. If we have a link rel="edit", we are changing
* an existing entry. In this case we re-serialize the entry and
* PUT it to the edit URI, checking for a 200 OK result.
*
* For posting new entries, you must specify the $postUri
* parameter to save() to tell the object where to post itself.
* We use $postUri and POST the serialized entry there, checking
* for a 201 Created response. If the insert is successful, we
* then parse the response from the POST to get any values that
* the server has generated: an id, an updated time, and its new
* link rel="edit".
*
* @param string $postUri Location to POST for creating new entries.
* @throws Zend_Feed_Exception
* @return void
*/
public function save($postUri = null)
{
if ($this->id()) {
// If id is set, look for link rel="edit" in the
// entry object and PUT.
$editUri = $this->link('edit');
if (!$editUri) {
throw new Zend_Feed_Exception('Cannot edit entry; no link rel="edit" is present.');
}
$client = Zend_Feed::getHttpClient();
$client->setUri($editUri);
if (Zend_Feed::getHttpMethodOverride()) {
$client->setHeaders(array('X-HTTP-Method-Override: PUT', 'Content-Type: application/atom+xml'));
$client->setRawData($this->saveXML());
$response = $client->request('POST');
} else {
$client->setHeaders('Content-Type', 'application/atom+xml');
$client->setRawData($this->saveXML());
$response = $client->request('PUT');
}
if ($response->getStatus() !== 200) {
throw new Zend_Feed_Exception('Expected response code 200, got ' . $response->getStatus());
}
} else {
if ($postUri === null) {
throw new Zend_Feed_Exception('PostURI must be specified to save new entries.');
}
$client = Zend_Feed::getHttpClient();
$client->setUri($postUri);
$client->setRawData($this->saveXML());
$response = $client->request('POST');
if ($response->getStatus() !== 201) {
throw new Zend_Feed_Exception('Expected response code 201, got ' . $response->getStatus());
}
}
// Update internal properties using $client->responseBody;
@ini_set('track_errors', 1);
$newEntry = @DOMDocument::loadXML($response->getBody());
@ini_restore('track_errors');
if (!$newEntry) {
throw new Zend_Feed_Exception('XML cannot be parsed: ' . $php_errormsg);
}
$newEntry = $newEntry->getElementsByTagName($this->_rootElement)->item(0);
if (!$newEntry) {
throw new Zend_Feed_Exception('No root <feed> element found in server response:' . "\n\n" . $client->responseBody);
}
if ($this->_element->parentNode) {
$oldElement = $this->_element;
$this->_element = $oldElement->ownerDocument->importNode($newEntry, true);
$oldElement->parentNode->replaceChild($this->_element, $oldElement);
} else {
$this->_element = $newEntry;
}
}
示例10: setUp
public function setUp()
{
Zend_Feed::setHttpClient(new Zend_Http_Client_File());
$this->_client = Zend_Feed::getHttpClient();
$this->_feedDir = dirname(__FILE__) . '/_files';
}
示例11: setUp
public function setUp()
{
Zend_Feed::setHttpClient(new Zend_HttpClient_File());
$this->_client = Zend_Feed::getHttpClient();
$this->_feedDir = 'Zend/Feed/_files';
}
示例12: _getFeed
/**
* Requests an Atom feed from the Zotero API.
*
* @param string The Zotero API path for the desired action.
* @param array Additional parameters for the request.
* @return Zend_Feed_Atom
*/
protected function _getFeed($path, $params)
{
$client = Zend_Feed::getHttpClient();
$client->setHeaders('Accept-Encoding', '');
$client->setConfig(array('httpversion' => Zend_Http_Client::HTTP_0));
$uri = $this->_getUri($path, $this->_filterParams($params));
$attempt = 0;
while (true) {
try {
$attempt++;
return new Zend_Feed_Atom($uri);
} catch (Exception $e) {
if ($this->_requestAttempts > $attempt) {
continue;
}
throw $e;
}
}
}