Blame view

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