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