| 94 |
jpm |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* package.xml parsing class, package.xml version 2.0
|
|
|
4 |
*
|
|
|
5 |
* PHP versions 4 and 5
|
|
|
6 |
*
|
|
|
7 |
* LICENSE: This source file is subject to version 3.0 of the PHP license
|
|
|
8 |
* that is available through the world-wide-web at the following URI:
|
|
|
9 |
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
|
|
|
10 |
* the PHP License and are unable to obtain it through the web, please
|
|
|
11 |
* send a note to license@php.net so we can mail you a copy immediately.
|
|
|
12 |
*
|
|
|
13 |
* @category pear
|
|
|
14 |
* @package PEAR
|
|
|
15 |
* @author Greg Beaver <cellog@php.net>
|
|
|
16 |
* @copyright 1997-2006 The PHP Group
|
|
|
17 |
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
|
|
18 |
* @version CVS: $Id: v2.php,v 1.19 2006/01/23 17:39:52 cellog Exp $
|
|
|
19 |
* @link http://pear.php.net/package/PEAR
|
|
|
20 |
* @since File available since Release 1.4.0a1
|
|
|
21 |
*/
|
|
|
22 |
/**
|
|
|
23 |
* base xml parser class
|
|
|
24 |
*/
|
|
|
25 |
require_once 'PEAR/XMLParser.php';
|
|
|
26 |
require_once 'PEAR/PackageFile/v2.php';
|
|
|
27 |
/**
|
|
|
28 |
* Parser for package.xml version 2.0
|
|
|
29 |
* @category pear
|
|
|
30 |
* @package PEAR
|
|
|
31 |
* @author Greg Beaver <cellog@php.net>
|
|
|
32 |
* @copyright 1997-2006 The PHP Group
|
|
|
33 |
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
|
|
34 |
* @version Release: @PEAR-VER@
|
|
|
35 |
* @link http://pear.php.net/package/PEAR
|
|
|
36 |
* @since Class available since Release 1.4.0a1
|
|
|
37 |
*/
|
|
|
38 |
class PEAR_PackageFile_Parser_v2 extends PEAR_XMLParser
|
|
|
39 |
{
|
|
|
40 |
var $_config;
|
|
|
41 |
var $_logger;
|
|
|
42 |
var $_registry;
|
|
|
43 |
|
|
|
44 |
function setConfig(&$c)
|
|
|
45 |
{
|
|
|
46 |
$this->_config = &$c;
|
|
|
47 |
$this->_registry = &$c->getRegistry();
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
function setLogger(&$l)
|
|
|
51 |
{
|
|
|
52 |
$this->_logger = &$l;
|
|
|
53 |
}
|
|
|
54 |
/**
|
|
|
55 |
* Unindent given string
|
|
|
56 |
*
|
|
|
57 |
* @param string $str The string that has to be unindented.
|
|
|
58 |
* @return string
|
|
|
59 |
* @access private
|
|
|
60 |
*/
|
|
|
61 |
function _unIndent($str)
|
|
|
62 |
{
|
|
|
63 |
// remove leading newlines
|
|
|
64 |
$str = preg_replace('/^[\r\n]+/', '', $str);
|
|
|
65 |
// find whitespace at the beginning of the first line
|
|
|
66 |
$indent_len = strspn($str, " \t");
|
|
|
67 |
$indent = substr($str, 0, $indent_len);
|
|
|
68 |
$data = '';
|
|
|
69 |
// remove the same amount of whitespace from following lines
|
|
|
70 |
foreach (explode("\n", $str) as $line) {
|
|
|
71 |
if (substr($line, 0, $indent_len) == $indent) {
|
|
|
72 |
$data .= substr($line, $indent_len) . "\n";
|
|
|
73 |
}
|
|
|
74 |
}
|
|
|
75 |
return $data;
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
/**
|
|
|
79 |
* post-process data
|
|
|
80 |
*
|
|
|
81 |
* @param string $data
|
|
|
82 |
* @param string $element element name
|
|
|
83 |
*/
|
|
|
84 |
function postProcess($data, $element)
|
|
|
85 |
{
|
|
|
86 |
if ($element == 'notes') {
|
|
|
87 |
return trim($this->_unIndent($data));
|
|
|
88 |
}
|
|
|
89 |
return trim($data);
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
/**
|
|
|
93 |
* @param string
|
|
|
94 |
* @param string file name of the package.xml
|
|
|
95 |
* @param string|false name of the archive this package.xml came from, if any
|
|
|
96 |
* @param string class name to instantiate and return. This must be PEAR_PackageFile_v2 or
|
|
|
97 |
* a subclass
|
|
|
98 |
* @return PEAR_PackageFile_v2
|
|
|
99 |
*/
|
|
|
100 |
function &parse($data, $file, $archive = false, $class = 'PEAR_PackageFile_v2')
|
|
|
101 |
{
|
|
|
102 |
if (PEAR::isError($err = parent::parse($data, $file))) {
|
|
|
103 |
return $err;
|
|
|
104 |
}
|
|
|
105 |
$ret = new $class;
|
|
|
106 |
$ret->setConfig($this->_config);
|
|
|
107 |
if (isset($this->_logger)) {
|
|
|
108 |
$ret->setLogger($this->_logger);
|
|
|
109 |
}
|
|
|
110 |
$ret->fromArray($this->_unserializedData);
|
|
|
111 |
$ret->setPackagefile($file, $archive);
|
|
|
112 |
return $ret;
|
|
|
113 |
}
|
|
|
114 |
}
|
|
|
115 |
?>
|