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


PHP HttpResponse::body方法代码示例

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


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

示例1: _process

 /**
  * Processes the feed and rebuilds an array based on the feeds type (RSS, RDF, Atom).
  *
  * @param HttpResponse $response
  * @param array $query
  * @param string $source
  * @return bool
  */
 protected function _process(HttpResponse $response, $query, $source)
 {
     $feed = Converter::toArray($response->body());
     $clean = array();
     if (!empty($query['root']) && !empty($feed[$query['feed']['root']])) {
         $items = $feed[$query['feed']['root']];
     } else {
         // RSS
         if (isset($feed['channel']) && isset($feed['channel']['item'])) {
             $items = $feed['channel']['item'];
             // RDF
         } else {
             if (isset($feed['item'])) {
                 $items = $feed['item'];
                 // Atom
             } else {
                 if (isset($feed['entry'])) {
                     $items = $feed['entry'];
                     // XML
                 } else {
                     $items = $feed;
                 }
             }
         }
     }
     if (empty($items) || !is_array($items)) {
         return $clean;
     }
     // Gather elements
     $elements = array('title' => array('title'), 'guid' => array('guid', 'id'), 'date' => array('date', 'pubDate', 'published', 'updated'), 'link' => array('link', 'origLink'), 'image' => array('image', 'thumbnail'), 'author' => array('author', 'writer', 'editor', 'user'), 'source' => array('source'), 'description' => array('description', 'desc', 'summary', 'content', 'text'));
     if (is_array($query['fields'])) {
         $elements = array_merge_recursive($elements, $query['fields']);
     }
     // Loop the feed
     foreach ($items as $item) {
         $data = array();
         foreach ($elements as $element => $keys) {
             if (isset($keys['attributes'])) {
                 $attributes = $keys['attributes'];
                 unset($keys['attributes']);
             } else {
                 $attributes = array('value', 'href', 'src', 'name', 'label');
             }
             if (isset($keys['keys'])) {
                 $keys = $keys['keys'];
             }
             foreach ($keys as $key) {
                 if (isset($item[$key]) && empty($data[$element])) {
                     if ($value = $this->_extract($item[$key], $attributes)) {
                         $data[$element] = $value;
                         break;
                     }
                 }
             }
         }
         if (empty($data['link'])) {
             trigger_error(sprintf('Feed %s does not have a valid link element', $source), E_USER_NOTICE);
             continue;
         }
         if (empty($data['source']) && $source) {
             $data['source'] = (string) $source;
         }
         // Determine how to sort
         $sortBy = $query['feed']['sort'];
         if (isset($data[$sortBy])) {
             $sort = $data[$sortBy];
         } else {
             if (isset($data['date'])) {
                 $sort = $data['date'];
             } else {
                 $sort = null;
             }
         }
         if ($sortBy === 'date' && $sort) {
             $sort = strtotime($sort);
         } else {
             if (!$sort) {
                 $sort = microtime();
             }
         }
         if ($data) {
             $clean[$sort] = $data;
         }
     }
     return $clean;
 }
开发者ID:alescx,项目名称:cakephp-utils,代码行数:94,代码来源:FeedSource.php


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