PEAR_PackageFileManager
[ class tree: PEAR_PackageFileManager ] [ index: PEAR_PackageFileManager ] [ all elements ]

Source for file SimpleGenerator.php

Documentation is available at SimpleGenerator.php

  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.3 2005/02/20 21:21:09 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.     {
  39.     }
  40.  
  41.     /**
  42.      * @param array 
  43.      */
  44.     function setPackageFileManagerOptions($opts)
  45.     {
  46.         $this->_options $opts;
  47.     }
  48.  
  49.     /**
  50.      * Return an XML document based on the package info (as returned
  51.      * by the PEAR_Common::infoFrom* methods).
  52.      *
  53.      * @param array  $pkginfo  package info
  54.      *
  55.      * @return string XML data
  56.      *
  57.      * @access public
  58.      * @deprecated use a PEAR_PackageFile_v* object's generator instead
  59.      */
  60.     function xmlFromInfo($pkginfo)
  61.     {
  62.         include_once 'PEAR/PackageFile.php';
  63.         include_once 'PEAR/Config.php';
  64.         $config &PEAR_Config::singleton();
  65.         $packagefile &new PEAR_PackageFile($config);
  66.         $pf &$packagefile->fromArray($pkginfo);
  67.         parent::PEAR_PackageFile_Generator_v1($pf);
  68.         return $this->toXml();
  69.     }
  70.  
  71.     function getFileRoles()
  72.     {
  73.         return PEAR_Common::getFileRoles();
  74.     }
  75.  
  76.     function getReplacementTypes()
  77.     {
  78.         return PEAR_Common::getReplacementTypes();
  79.     }
  80.  
  81.     /**
  82.      * Validate XML package definition file.
  83.      *
  84.      * @param  string $info Filename of the package archive or of the
  85.      *                 package definition file
  86.      * @param  array $errors Array that will contain the errors
  87.      * @param  array $warnings Array that will contain the warnings
  88.      * @param  string $dir_prefix (optional) directory where source files
  89.      *                 may be found, or empty if they are not available
  90.      * @access public
  91.      * @return boolean 
  92.      * @deprecated use the validation of PEAR_PackageFile objects
  93.      */
  94.     function validatePackageInfo($info&$errors&$warnings$dir_prefix '')
  95.     {
  96.         include_once 'PEAR/PackageFile.php';
  97.         include_once 'PEAR/Config.php';
  98.         $config &PEAR_Config::singleton();
  99.         $packagefile &new PEAR_PackageFile($config);
  100.         PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
  101.         if (is_array($info)) {
  102.             $pf &$packagefile->fromArray($info);
  103.             if (!$pf->validate(PEAR_VALIDATE_NORMAL)) {
  104.                 foreach ($pf->getValidationWarnings(as $err{
  105.                     if ($error['level'== 'error'{
  106.                         $errors[$error['message'];
  107.                     else {
  108.                         $warnings[$error['message'];
  109.                     }
  110.                 }
  111.                 return false;
  112.             }
  113.         else {
  114.             $pf &$packagefile->fromAnyFile($infoPEAR_VALIDATE_NORMAL);
  115.         }
  116.         PEAR::staticPopErrorHandling();
  117.         if (PEAR::isError($pf)) {
  118.             $errs $pf->getUserinfo();
  119.             if (is_array($errs)) {
  120.                 foreach ($errs as $error{
  121.                     if ($error['level'== 'error'{
  122.                         $errors[$error['message'];
  123.                     else {
  124.                         $warnings[$error['message'];
  125.                     }
  126.                 }
  127.             }
  128.             return false;
  129.         }
  130.         return true;
  131.     }
  132.  
  133.     /**
  134.      * @param array 
  135.      * @access protected
  136.      */
  137.     function recursiveXmlFilelist($list)
  138.     {
  139.         $this->_dirs = array();
  140.         foreach ($list as $file => $attributes{
  141.             $this->_addDir($this->_dirsexplode('/'dirname($file))$file$attributes);
  142.         }
  143.         if (count($this->_dirs['dirs']!= 1 || isset($this->_dirs['files'])) {
  144.             $this->_dirs = array('dirs' => array('/' => $this->_dirs));
  145.         }
  146.         return $this->_formatDir($this->_dirs''''true);
  147.     }
  148.  
  149.     /**
  150.      * @param array 
  151.      * @param array 
  152.      * @param string|null
  153.      * @param array|null
  154.      * @access private
  155.      */
  156.     function _addDir(&$dirs$dir$file = null$attributes = null)
  157.     {
  158.         if ($dir == array(|| $dir == array('.')) {
  159.             $dirs['files'][basename($file)$attributes;
  160.             return;
  161.         }
  162.         $curdir array_shift($dir);
  163.         if (!isset($dirs['dirs'][$curdir])) {
  164.             $dirs['dirs'][$curdir= array();
  165.         }
  166.         $this->_addDir($dirs['dirs'][$curdir]$dir$file$attributes);
  167.     }
  168.  
  169.     /**
  170.      * @param array 
  171.      * @param string 
  172.      * @param string 
  173.      * @access private
  174.      */
  175.     function _formatDir($dirs$indent ''$curdir ''$toplevel = false)
  176.     {
  177.         $ret '';
  178.         if (!count($dirs)) {
  179.             return '';
  180.         }
  181.         if (isset($dirs['dirs'])) {
  182.             uksort($dirs['dirs']'strnatcasecmp');
  183.             foreach ($dirs['dirs'as $dir => $contents{
  184.                 if ($dir == '/'{
  185.                     $usedir '/';
  186.                 else {
  187.                     if ($curdir == '/'{
  188.                         $curdir '';
  189.                     }
  190.                     $usedir = "$curdir/$dir";
  191.                 }
  192.                 $ret .= "$indent   <dir name=\"$dir\"";
  193.                 if ($toplevel{
  194.                     $ret .= ' baseinstalldir="' $this->_options['baseinstalldir''"';
  195.                 else {
  196.                     if (isset($this->_options['installexceptions'][$dir])) {
  197.                         $ret .= ' baseinstalldir="' $this->_options['installexceptions'][$dir'"';
  198.                     }
  199.                 }
  200.                 $ret .= ">\n";
  201.                 $ret .= $this->_formatDir($contents"$indent "$usedir);
  202.                 $ret .= "$indent   </dir> <!-- $usedir -->\n";
  203.             }
  204.         }
  205.         if (isset($dirs['files'])) {
  206.             uksort($dirs['files']'strnatcasecmp');
  207.             foreach ($dirs['files'as $file => $attribs{
  208.                 $ret .= $this->_formatFile($file$attribs$indent);
  209.             }
  210.         }
  211.         return $ret;
  212.     }
  213.  
  214.     /**
  215.      * @param string 
  216.      * @param array 
  217.      * @param string 
  218.      * @access private
  219.      */
  220.     function _formatFile($file$attributes$indent)
  221.     {
  222.         $ret = "$indent   <file role=\"$attributes[role]\"";
  223.         if (isset($this->_options['installexceptions'][$file])) {
  224.             $ret .= ' baseinstalldir="' $this->_options['installexceptions'][$file'"';
  225.         }
  226.         if (isset($attributes['md5sum'])) {
  227.             $ret .= " md5sum=\"$attributes[md5sum]\"";
  228.         }
  229.         if (isset($attributes['platform'])) {
  230.             $ret .= " platform=\"$attributes[platform]\"";
  231.         }
  232.         if (!empty($attributes['install-as'])) {
  233.             $ret .= ' install-as="' .
  234.                 htmlspecialchars($attributes['install-as']'"';
  235.         }
  236.         $ret .= ' name="' htmlspecialchars($file'"';
  237.         if (empty($attributes['replacements'])) {
  238.             $ret .= "/>\n";
  239.         else {
  240.             $ret .= ">\n";
  241.             foreach ($attributes['replacements'as $r{
  242.                 $ret .= "$indent    <replace";
  243.                 foreach ($r as $k => $v{
  244.                     $ret .= " $k=\"" . htmlspecialchars($v.'"';
  245.                 }
  246.                 $ret .= "/>\n";
  247.             }
  248.             $ret .= "$indent   </file>\n";
  249.         }
  250.         return $ret;
  251.     }
  252.  
  253.     /**
  254.      * Generate the <filelist> tag
  255.      * @access private
  256.      * @return string 
  257.      */
  258.     function _doFileList($indent$filelist$curdir)
  259.     {
  260.         $ret '';
  261.         foreach ($filelist as $file => $fa{
  262.             if (isset($fa['##files'])) {
  263.                 $ret .= "$indent      <dir";
  264.             else {
  265.                 $ret .= "$indent      <file";
  266.             }
  267.  
  268.             if (isset($fa['role'])) {
  269.                 $ret .= " role=\"$fa[role]\"";
  270.             }
  271.             if (isset($fa['baseinstalldir'])) {
  272.                 $ret .= ' baseinstalldir="' .
  273.                     htmlspecialchars($fa['baseinstalldir']'"';
  274.             }
  275.             if (isset($fa['md5sum'])) {
  276.                 $ret .= " md5sum=\"$fa[md5sum]\"";
  277.             }
  278.             if (isset($fa['platform'])) {
  279.                 $ret .= " platform=\"$fa[platform]\"";
  280.             }
  281.             if (!empty($fa['install-as'])) {
  282.                 $ret .= ' install-as="' .
  283.                     htmlspecialchars($fa['install-as']'"';
  284.             }
  285.             $ret .= ' name="' htmlspecialchars($file'"';
  286.             if (isset($fa['##files'])) {
  287.                 $ret .= ">\n";
  288.                 $recurdir $curdir;
  289.                 if ($recurdir == '///'{
  290.                     $recurdir '';
  291.                 }
  292.                 $ret .= $this->_doFileList("$indent "$fa['##files']$recurdir $file '/');
  293.                 $displaydir $curdir;
  294.                 if ($displaydir == '///' || $displaydir == '/'{
  295.                     $displaydir '';
  296.                 }
  297.                 $ret .= "$indent      </dir> <!-- $displaydir$file -->\n";
  298.             else {
  299.                 if (empty($fa['replacements'])) {
  300.                     $ret .= "/>\n";
  301.                 else {
  302.                     $ret .= ">\n";
  303.                     foreach ($fa['replacements'as $r{
  304.                         $ret .= "$indent        <replace";
  305.                         foreach ($r as $k => $v{
  306.                             $ret .= " $k=\"" . htmlspecialchars($v.'"';
  307.                         }
  308.                         $ret .= "/>\n";
  309.                     }
  310.                     $ret .= "$indent      </file>\n";
  311.                 }
  312.             }
  313.         }
  314.         return $ret;
  315.     }
  316.     
  317. }
  318.  
  319. ?>

Documentation generated on Mon, 11 Mar 2019 14:30:55 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.