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 * @link http://pear.php.net/package/PEAR
13 * @since File available since Release 1.4.0a1
16 * base xml parser class
18 require_once 'PEAR/XMLParser.php';
19 require_once 'PEAR/PackageFile/v2.php';
21 * Parser for package.xml version 2.0
24 * @author Greg Beaver <cellog@php.net>
25 * @copyright 1997-2009 The Authors
26 * @license http://opensource.org/licenses/bsd-license.php New BSD License
27 * @version Release: @PEAR-VER@
28 * @link http://pear.php.net/package/PEAR
29 * @since Class available since Release 1.4.0a1
31 class PEAR_PackageFile_Parser_v2 extends PEAR_XMLParser
37 function setConfig(&$c)
40 $this->_registry = &$c->getRegistry();
43 function setLogger(&$l)
48 * Unindent given string
50 * @param string $str The string that has to be unindented.
54 function _unIndent($str)
56 // remove leading newlines
57 $str = preg_replace('/^[\r\n]+/', '', $str);
58 // find whitespace at the beginning of the first line
59 $indent_len = strspn($str, " \t");
60 $indent = substr($str, 0, $indent_len);
62 // remove the same amount of whitespace from following lines
63 foreach (explode("\n", $str) as $line) {
64 if (substr($line, 0, $indent_len) == $indent) {
65 $data .= substr($line, $indent_len) . "\n";
67 $data .= $line . "\n";
77 * @param string $element element name
79 function postProcess($data, $element)
81 if ($element == 'notes') {
82 return trim($this->_unIndent($data));
89 * @param string file name of the package.xml
90 * @param string|false name of the archive this package.xml came from, if any
91 * @param string class name to instantiate and return. This must be PEAR_PackageFile_v2 or
93 * @return PEAR_PackageFile_v2
95 function parse($data, $file = null, $archive = false, $class = 'PEAR_PackageFile_v2')
97 if (PEAR::isError($err = parent::parse($data))) {
102 $ret->encoding = $this->encoding;
103 $ret->setConfig($this->_config);
104 if (isset($this->_logger)) {
105 $ret->setLogger($this->_logger);
108 $ret->fromArray($this->_unserializedData);
109 $ret->setPackagefile($file, $archive);