[ Index ]
 

Code source de PHP PEAR 1.4.5

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/PEAR/PackageFileManager/ -> SimpleGenerator.php (source)

   1  <?php
   2  //
   3  // +------------------------------------------------------------------------+
   4  // | PEAR :: Package File Manager                                           |
   5  // +------------------------------------------------------------------------+
   6  // | Copyright (c) 2004 Gregory Beaver                                      |
   7  // | Email         cellog@phpdoc.org                                        |
   8  // +------------------------------------------------------------------------+
   9  // | This source file is subject to version 3.00 of the PHP License,        |
  10  // | that is available at http://www.php.net/license/3_0.txt.               |
  11  // | If you did not receive a copy of the PHP license and are unable to     |
  12  // | obtain it through the world-wide-web, please send a note to            |
  13  // | license@php.net so we can mail you a copy immediately.                 |
  14  // +------------------------------------------------------------------------+
  15  // | Portions of this code based on phpDocumentor                           |
  16  // | Web           http://www.phpdoc.org                                    |
  17  // | Mirror        http://phpdocu.sourceforge.net/                          |
  18  // +------------------------------------------------------------------------+
  19  // $Id: SimpleGenerator.php,v 1.4 2005/05/20 22:42:59 cellog Exp $
  20  //
  21  
  22  require_once  'PEAR/PackageFile/Generator/v1.php';
  23  /**
  24   * Class for XML output
  25   *
  26   * @author Greg Beaver <cellog@php.net>
  27   * @since 1.2.0
  28   * @copyright 2003
  29   * @package PEAR_PackageFileManager
  30   */
  31  class PEAR_PackageFileManager_SimpleGenerator extends PEAR_PackageFile_Generator_v1
  32  {
  33      var $_options;
  34  
  35      /**
  36       * remove a warning about missing parameters - don't delete this
  37       */
  38      function PEAR_PackageFileManager_SimpleGenerator()
  39      {
  40      }
  41  
  42      /**
  43       * @param array
  44       */
  45      function setPackageFileManagerOptions($opts)
  46      {
  47          $this->_options = $opts;
  48      }
  49  
  50      /**
  51       * Return an XML document based on the package info (as returned
  52       * by the PEAR_Common::infoFrom* methods).
  53       *
  54       * @param array  $pkginfo  package info
  55       *
  56       * @return string XML data
  57       *
  58       * @access public
  59       * @deprecated use a PEAR_PackageFile_v* object's generator instead
  60       */
  61      function xmlFromInfo($pkginfo)
  62      {
  63          include_once  'PEAR/PackageFile.php';
  64          include_once  'PEAR/Config.php';
  65          $config = &PEAR_Config::singleton();
  66          $packagefile = &new PEAR_PackageFile($config);
  67          $pf = &$packagefile->fromArray($pkginfo);
  68          parent::PEAR_PackageFile_Generator_v1($pf);
  69          return $this->toXml();
  70      }
  71  
  72      function getFileRoles()
  73      {
  74          return PEAR_Common::getFileRoles();
  75      }
  76  
  77      function getReplacementTypes()
  78      {
  79          return PEAR_Common::getReplacementTypes();
  80      }
  81  
  82      /**
  83       * Validate XML package definition file.
  84       *
  85       * @param  string $info Filename of the package archive or of the
  86       *                package definition file
  87       * @param  array $errors Array that will contain the errors
  88       * @param  array $warnings Array that will contain the warnings
  89       * @param  string $dir_prefix (optional) directory where source files
  90       *                may be found, or empty if they are not available
  91       * @access public
  92       * @return boolean
  93       * @deprecated use the validation of PEAR_PackageFile objects
  94       */
  95      function validatePackageInfo($info, &$errors, &$warnings, $dir_prefix = '')
  96      {
  97          include_once  'PEAR/PackageFile.php';
  98          include_once  'PEAR/Config.php';
  99          $config = &PEAR_Config::singleton();
 100          $packagefile = &new PEAR_PackageFile($config);
 101          PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
 102          if (is_array($info)) {
 103              $pf = &$packagefile->fromArray($info);
 104              if (!$pf->validate(PEAR_VALIDATE_NORMAL)) {
 105                  foreach ($pf->getValidationWarnings() as $err) {
 106                      if ($error['level'] == 'error') {
 107                          $errors[] = $error['message'];
 108                      } else {
 109                          $warnings[] = $error['message'];
 110                      }
 111                  }
 112                  return false;
 113              }
 114          } else {
 115              $pf = &$packagefile->fromAnyFile($info, PEAR_VALIDATE_NORMAL);
 116          }
 117          PEAR::staticPopErrorHandling();
 118          if (PEAR::isError($pf)) {
 119              $errs = $pf->getUserinfo();
 120              if (is_array($errs)) {
 121                  foreach ($errs as $error) {
 122                      if ($error['level'] == 'error') {
 123                          $errors[] = $error['message'];
 124                      } else {
 125                          $warnings[] = $error['message'];
 126                      }
 127                  }
 128              }
 129              return false;
 130          }
 131          return true;
 132      }
 133  
 134      /**
 135       * @param array
 136       * @access protected
 137       */
 138      function recursiveXmlFilelist($list)
 139      {
 140          $this->_dirs = array();
 141          foreach ($list as $file => $attributes) {
 142              $this->_addDir($this->_dirs, explode('/', dirname($file)), $file, $attributes);
 143          }
 144          if (!isset($this->_dirs['dirs'])) {
 145              $this->_dirs['dirs'] = array();
 146          }
 147          if (count($this->_dirs['dirs']) != 1 || isset($this->_dirs['files'])) {
 148              $this->_dirs = array('dirs' => array('/' => $this->_dirs));
 149          }
 150          return $this->_formatDir($this->_dirs, '', '', true);
 151      }
 152  
 153      /**
 154       * @param array
 155       * @param array
 156       * @param string|null
 157       * @param array|null
 158       * @access private
 159       */
 160      function _addDir(&$dirs, $dir, $file = null, $attributes = null)
 161      {
 162          if ($dir == array() || $dir == array('.')) {
 163              $dirs['files'][basename($file)] = $attributes;
 164              return;
 165          }
 166          $curdir = array_shift($dir);
 167          if (!isset($dirs['dirs'][$curdir])) {
 168              $dirs['dirs'][$curdir] = array();
 169          }
 170          $this->_addDir($dirs['dirs'][$curdir], $dir, $file, $attributes);
 171      }
 172  
 173      /**
 174       * @param array
 175       * @param string
 176       * @param string
 177       * @access private
 178       */
 179      function _formatDir($dirs, $indent = '', $curdir = '', $toplevel = false)
 180      {
 181          $ret = '';
 182          if (!count($dirs)) {
 183              return '';
 184          }
 185          if (isset($dirs['dirs'])) {
 186              uksort($dirs['dirs'], 'strnatcasecmp');
 187              foreach ($dirs['dirs'] as $dir => $contents) {
 188                  if ($dir == '/') {
 189                      $usedir = '/';
 190                  } else {
 191                      if ($curdir == '/') {
 192                          $curdir = '';
 193                      }
 194                      $usedir = "$curdir/$dir";
 195                  }
 196                  $ret .= "$indent   <dir name=\"$dir\"";
 197                  if ($toplevel) {
 198                      $ret .= ' baseinstalldir="' . $this->_options['baseinstalldir'] . '"';
 199                  } else {
 200                      if (isset($this->_options['installexceptions'][$dir])) {
 201                          $ret .= ' baseinstalldir="' . $this->_options['installexceptions'][$dir] . '"';
 202                      }
 203                  }
 204                  $ret .= ">\n";
 205                  $ret .= $this->_formatDir($contents, "$indent ", $usedir);
 206                  $ret .= "$indent   </dir> <!-- $usedir -->\n";
 207              }
 208          }
 209          if (isset($dirs['files'])) {
 210              uksort($dirs['files'], 'strnatcasecmp');
 211              foreach ($dirs['files'] as $file => $attribs) {
 212                  $ret .= $this->_formatFile($file, $attribs, $indent);
 213              }
 214          }
 215          return $ret;
 216      }
 217  
 218      /**
 219       * @param string
 220       * @param array
 221       * @param string
 222       * @access private
 223       */
 224      function _formatFile($file, $attributes, $indent)
 225      {
 226          $ret = "$indent   <file role=\"$attributes[role]\"";
 227          if (isset($this->_options['installexceptions'][$file])) {
 228              $ret .= ' baseinstalldir="' . $this->_options['installexceptions'][$file] . '"';
 229          }
 230          if (isset($attributes['md5sum'])) {
 231              $ret .= " md5sum=\"$attributes[md5sum]\"";
 232          }
 233          if (isset($attributes['platform'])) {
 234              $ret .= " platform=\"$attributes[platform]\"";
 235          }
 236          if (!empty($attributes['install-as'])) {
 237              $ret .= ' install-as="' .
 238                  htmlspecialchars($attributes['install-as']) . '"';
 239          }
 240          $ret .= ' name="' . htmlspecialchars($file) . '"';
 241          if (empty($attributes['replacements'])) {
 242              $ret .= "/>\n";
 243          } else {
 244              $ret .= ">\n";
 245              foreach ($attributes['replacements'] as $r) {
 246                  $ret .= "$indent    <replace";
 247                  foreach ($r as $k => $v) {
 248                      $ret .= " $k=\"" . htmlspecialchars($v) .'"';
 249                  }
 250                  $ret .= "/>\n";
 251              }
 252              $ret .= "$indent   </file>\n";
 253          }
 254          return $ret;
 255      }
 256  
 257      /**
 258       * Generate the <filelist> tag
 259       * @access private
 260       * @return string
 261       */
 262      function _doFileList($indent, $filelist, $curdir)
 263      {
 264          $ret = '';
 265          foreach ($filelist as $file => $fa) {
 266              if (isset($fa['##files'])) {
 267                  $ret .= "$indent      <dir";
 268              } else {
 269                  $ret .= "$indent      <file";
 270              }
 271  
 272              if (isset($fa['role'])) {
 273                  $ret .= " role=\"$fa[role]\"";
 274              }
 275              if (isset($fa['baseinstalldir'])) {
 276                  $ret .= ' baseinstalldir="' .
 277                      htmlspecialchars($fa['baseinstalldir']) . '"';
 278              }
 279              if (isset($fa['md5sum'])) {
 280                  $ret .= " md5sum=\"$fa[md5sum]\"";
 281              }
 282              if (isset($fa['platform'])) {
 283                  $ret .= " platform=\"$fa[platform]\"";
 284              }
 285              if (!empty($fa['install-as'])) {
 286                  $ret .= ' install-as="' .
 287                      htmlspecialchars($fa['install-as']) . '"';
 288              }
 289              $ret .= ' name="' . htmlspecialchars($file) . '"';
 290              if (isset($fa['##files'])) {
 291                  $ret .= ">\n";
 292                  $recurdir = $curdir;
 293                  if ($recurdir == '///') {
 294                      $recurdir = '';
 295                  }
 296                  $ret .= $this->_doFileList("$indent ", $fa['##files'], $recurdir . $file . '/');
 297                  $displaydir = $curdir;
 298                  if ($displaydir == '///' || $displaydir == '/') {
 299                      $displaydir = '';
 300                  }
 301                  $ret .= "$indent      </dir> <!-- $displaydir$file -->\n";
 302              } else {
 303                  if (empty($fa['replacements'])) {
 304                      $ret .= "/>\n";
 305                  } else {
 306                      $ret .= ">\n";
 307                      foreach ($fa['replacements'] as $r) {
 308                          $ret .= "$indent        <replace";
 309                          foreach ($r as $k => $v) {
 310                              $ret .= " $k=\"" . htmlspecialchars($v) .'"';
 311                          }
 312                          $ret .= "/>\n";
 313                      }
 314                      $ret .= "$indent      </file>\n";
 315                  }
 316              }
 317          }
 318          return $ret;
 319      }
 320      
 321  }
 322  
 323  ?>


Généré le : Sun Feb 25 14:08:00 2007 par Balluche grâce à PHPXref 0.7