cvs: pear /XML_Indexing/Indexing Reader.php
| From: | Olivier Guilyardi | Date: | Sat, 15 Oct 2005 00:57:55 +0000 |
| Subject: | cvs: pear /XML_Indexing/Indexing Reader.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-35563@lists.php.net to get a copy of this message | ||
olivierg Fri Oct 14 20:57:55 2005 EDT
Modified files:
/pear/XML_Indexing/Indexing Reader.php
Log:
Added convenient fetchArray() method
http://cvs.php.net/diff.php/pear/XML_Indexing/Indexing/Reader.php?r1=1.1&r2=1.2&ty=u
Index: pear/XML_Indexing/Indexing/Reader.php
diff -u pear/XML_Indexing/Indexing/Reader.php:1.1 pear/XML_Indexing/Indexing/Reader.php:1.2
--- pear/XML_Indexing/Indexing/Reader.php:1.1 Thu Feb 17 11:37:29 2005
+++ pear/XML_Indexing/Indexing/Reader.php Fri Oct 14 20:57:53 2005
@@ -16,7 +16,7 @@
* @copyright 2004 Samalyse SARL corporation
* @author Olivier Guilyardi <olivier@samalyse.com>
* @license http://www.php.net/license/3_0.txt
PHP License
- * @version CVS: $Id: Reader.php,v 1.1 2005/02/17 16:37:29 olivierg Exp $
+ * @version CVS: $Id: Reader.php,v 1.2 2005/10/15 00:57:53 olivierg Exp $
* @link http://pear.php.net
* @since File available since Release 0.1
*/
@@ -187,8 +187,8 @@
* Needed by the fetchStrings() method when bypassing indexing
* @see XML_Indexing_Reader::fetchStrings()
* @see XML_Indexing_Reader::bypass()
- * var object
- * @access _private
+ * @var object
+ * @access private
*/
var $_domDocument;
@@ -198,7 +198,25 @@
* @access private
*/
var $_phpVersion;
-
+
+ /**
+ * Cached XML_Unserializer object
+ *
+ * @see XML_Indexing_Reader::fetchArray()
+ * @var object
+ * @access private
+ */
+ var $_unserializer;
+
+ /**
+ * Cached XML_Unserializer options
+ *
+ * @see XML_Indexing_Reader::fetchArray()
+ * @var array
+ * @access private
+ */
+ var $_unserializerOptions;
+
/**
* Constructor
*
@@ -487,6 +505,7 @@
*/
function _bypass($xpathStr)
{
+ $this->_enterSection('_bypass');
if ($this->_phpVersion == 5) {
$doc = DomDocument::load($this->_xmlFilename);
$xpath = new DomXpath($doc);
@@ -517,6 +536,7 @@
unset ($result);
unset ($xpath);
}
+ $this->_leaveSection('_bypass');
return $numResults;
}
@@ -665,6 +685,41 @@
$this->_leaveSection('fetchDomNodes');
return $result;
}
+
+ /**
+ * Fetch a set of XML matches as an unserialized Array
+ *
+ * This method use XML_Unserializer to turn the extracted strings into a
+ * familiar array structure. You may want to look at XML_Unserializer
+ * documentation, especially to learn about the options you can use when
+ * calling this method.
+ *
+ * @param int $offset The n match to start fetching from
+ * (zero based, default : 0)
+ * @param int $limit How many matches to fetch (default : all)
+ * @param array $options Options passed to XML_Unserializer's constructor
+ * @return array DomElements
+ * @access public
+ */
+ function fetchArray($offset = 0, $limit = null, $options = array())
+ {
+ $this->_enterSection('fetchArray');
+ if (!isset ($this->_unserializer)
+ or $options != $this->_unserializerOptions) {
+ include_once ('XML/Unserializer.php');
+ $this->_unserializer =& new XML_Unserializer ($options);
+ $this->_unserializerOptions = $options;
+ }
+ $strings = $this->fetchStrings ($offset, $limit);
+ $reconstructed = '<root>' . join ('', $strings) .
'</root>';
+ $status = $this->_unserializer->unserialize($reconstructed);
+ if (PEAR::isError ($status)) {
+ $this->_leaveSection('fetchArray');
+ return $status;
+ }
+ $this->_leaveSection('fetchArray');
+ return $this->_unserializer->getUnserializedData();
+ }
/**
* Return namespaces declared in the XML file