3 * package.xml parsing class, package.xml version 2.0
9 * @author Greg Beaver <cellog@php.net>
10 * @copyright 1997-2009 The Authors
11 * @license http://opensource.org/licenses/bsd-license.php New BSD License
12 * @version CVS: $Id: v2.php 313023 2011-07-06 19:17:11Z dufuz $
13 * @link http://pear.php.net/package/PEAR
14 * @since File available since Release 1.4.0a1
17 * base xml parser class
19 require_once 'PEAR/XMLParser.php';
20 require_once 'PEAR/PackageFile/v2.php';
22 * Parser for package.xml version 2.0
25 * @author Greg Beaver <cellog@php.net>
26 * @copyright 1997-2009 The Authors
27 * @license http://opensource.org/licenses/bsd-license.php New BSD License
28 * @version Release: @PEAR-VER@
29 * @link http://pear.php.net/package/PEAR
30 * @since Class available since Release 1.4.0a1
32 class PEAR_PackageFile_Parser_v2 extends PEAR_XMLParser
38 function setConfig(&$c)
41 $this->_registry = &$c->getRegistry();
44 function setLogger(&$l)
49 * Unindent given string
51 * @param string $str The string that has to be unindented.
55 function _unIndent($str)
57 // remove leading newlines
58 $str = preg_replace('/^[\r\n]+/', '', $str);
59 // find whitespace at the beginning of the first line
60 $indent_len = strspn($str, " \t");
61 $indent = substr($str, 0, $indent_len);
63 // remove the same amount of whitespace from following lines
64 foreach (explode("\n", $str) as $line) {
65 if (substr($line, 0, $indent_len) == $indent) {
66 $data .= substr($line, $indent_len) . "\n";
68 $data .= $line . "\n";
78 * @param string $element element name
80 function postProcess($data, $element)
82 if ($element == 'notes') {
83 return trim($this->_unIndent($data));
90 * @param string file name of the package.xml
91 * @param string|false name of the archive this package.xml came from, if any
92 * @param string class name to instantiate and return. This must be PEAR_PackageFile_v2 or
94 * @return PEAR_PackageFile_v2
96 function &parse($data, $file, $archive = false, $class = 'PEAR_PackageFile_v2')
98 if (PEAR::isError($err = parent::parse($data, $file))) {
103 $ret->encoding = $this->encoding;
104 $ret->setConfig($this->_config);
105 if (isset($this->_logger)) {
106 $ret->setLogger($this->_logger);
109 $ret->fromArray($this->_unserializedData);
110 $ret->setPackagefile($file, $archive);