[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/lib/zend/Zend/Service/Technorati/ -> Result.php (source)

   1  <?php
   2  /**
   3   * Zend Framework
   4   *
   5   * LICENSE
   6   *
   7   * This source file is subject to the new BSD license that is bundled
   8   * with this package in the file LICENSE.txt.
   9   * It is also available through the world-wide-web at this URL:
  10   * http://framework.zend.com/license/new-bsd
  11   * If you did not receive a copy of the license and are unable to
  12   * obtain it through the world-wide-web, please send an email
  13   * to [email protected] so we can send you a copy immediately.
  14   *
  15   * @category   Zend
  16   * @package    Zend_Service
  17   * @subpackage Technorati
  18   * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  19   * @license    http://framework.zend.com/license/new-bsd     New BSD License
  20   * @version    $Id$
  21   */
  22  
  23  
  24  /**
  25   * Represents a single Technorati Search query result object.
  26   * It is never returned as a standalone object,
  27   * but it always belongs to a valid Zend_Service_Technorati_SearchResultSet object.
  28   *
  29   * @category   Zend
  30   * @package    Zend_Service
  31   * @subpackage Technorati
  32   * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  33   * @license    http://framework.zend.com/license/new-bsd     New BSD License
  34   * @abstract
  35   */
  36  abstract class Zend_Service_Technorati_Result
  37  {
  38      /**
  39       * An associative array of 'fieldName' => 'xmlfieldtag'
  40       *
  41       * @var     array
  42       * @access  protected
  43       */
  44      protected $_fields;
  45  
  46      /**
  47       * The ReST fragment for this result object
  48       *
  49       * @var     DomElement
  50       * @access  protected
  51       */
  52      protected $_dom;
  53  
  54      /**
  55       * Object for $this->_dom
  56       *
  57       * @var     DOMXpath
  58       * @access  protected
  59       */
  60      protected $_xpath;
  61  
  62  
  63      /**
  64       * Constructs a new object from DOM Element.
  65       * Properties are automatically fetched from XML
  66       * according to array of $_fields to be read.
  67       *
  68       * @param   DomElement $result  the ReST fragment for this object
  69       */
  70      public function __construct(DomElement $dom)
  71      {
  72          $this->_xpath = new DOMXPath($dom->ownerDocument);
  73          $this->_dom = $dom;
  74  
  75          // default fields for all search results
  76          $fields = array();
  77  
  78          // merge with child's object fields
  79          $this->_fields = array_merge($this->_fields, $fields);
  80  
  81          // add results to appropriate fields
  82          foreach($this->_fields as $phpName => $xmlName) {
  83              $query = "./$xmlName/text()";
  84              $node = $this->_xpath->query($query, $this->_dom);
  85              if ($node->length == 1) {
  86                  $this->{$phpName} = (string) $node->item(0)->data;
  87              }
  88          }
  89      }
  90  
  91      /**
  92       * Parses weblog node and sets weblog object.
  93       *
  94       * @return  void
  95       */
  96      protected function _parseWeblog()
  97      {
  98          // weblog object field
  99          $result = $this->_xpath->query('./weblog', $this->_dom);
 100          if ($result->length == 1) {
 101              /**
 102               * @see Zend_Service_Technorati_Weblog
 103               */
 104              require_once 'Zend/Service/Technorati/Weblog.php';
 105              $this->_weblog = new Zend_Service_Technorati_Weblog($result->item(0));
 106          } else {
 107              $this->_weblog = null;
 108          }
 109      }
 110  
 111      /**
 112       * Returns the document fragment for this object as XML string.
 113       *
 114       * @return string   the document fragment for this object
 115       *                  converted into XML format
 116       */
 117      public function getXml()
 118      {
 119          return $this->_dom->ownerDocument->saveXML($this->_dom);
 120      }
 121  }


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1