home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / tmp / PEAR-1.7.1 / PEAR / PackageFile / Parser / v2.php < prev   
Encoding:
PHP Script  |  2008-02-15  |  3.4 KB  |  117 lines

  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-2008 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.21 2008/01/03 20:26:37 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-2008 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.             } else {
  74.                 $data .= $line . "\n";
  75.             }
  76.         }
  77.         return $data;
  78.     }
  79.  
  80.     /**
  81.      * post-process data
  82.      *
  83.      * @param string $data
  84.      * @param string $element element name
  85.      */
  86.     function postProcess($data, $element)
  87.     {
  88.         if ($element == 'notes') {
  89.             return trim($this->_unIndent($data));
  90.         }
  91.         return trim($data);
  92.     }
  93.  
  94.     /**
  95.      * @param string
  96.      * @param string file name of the package.xml
  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
  99.      *               a subclass
  100.      * @return PEAR_PackageFile_v2
  101.      */
  102.     function &parse($data, $file, $archive = false, $class = 'PEAR_PackageFile_v2')
  103.     {
  104.         if (PEAR::isError($err = parent::parse($data, $file))) {
  105.             return $err;
  106.         }
  107.         $ret = new $class;
  108.         $ret->setConfig($this->_config);
  109.         if (isset($this->_logger)) {
  110.             $ret->setLogger($this->_logger);
  111.         }
  112.         $ret->fromArray($this->_unserializedData);
  113.         $ret->setPackagefile($file, $archive);
  114.         return $ret;
  115.     }
  116. }
  117. ?>