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.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.     {
  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 (!isset($this->_dirs['dirs'])) {
  144.             $this->_dirs['dirs'= array();
  145.         }
  146.         if (count($this->_dirs['dirs']!= 1 || isset($this->_dirs['files'])) {
  147.             $this->_dirs = array('dirs' => array('/' => $this->_dirs));
  148.         }
  149.         return $this->_formatDir($this->_dirs''''true);
  150.     }
  151.  
  152.     /**
  153.      * @param array 
  154.      * @param array 
  155.      * @param string|null
  156.      * @param array|null
  157.      * @access private
  158.      */
  159.     function _addDir(&$dirs$dir$file = null$attributes = null)
  160.     {
  161.         if ($dir == array(|| $dir == array('.')) {
  162.             $dirs['files'][basename($file)$attributes;
  163.             return;
  164.         }
  165.         $curdir array_shift($dir);
  166.         if (!isset($dirs['dirs'][$curdir])) {
  167.             $dirs['dirs'][$curdir= array();
  168.         }
  169.         $this->_addDir($dirs['dirs'][$curdir]$dir$file$attributes);
  170.     }
  171.  
  172.     /**
  173.      * @param array 
  174.      * @param string 
  175.      * @param string 
  176.      * @access private
  177.      */
  178.     function _formatDir($dirs$indent ''$curdir ''$toplevel = false)
  179.     {
  180.         $ret '';
  181.         if (!count($dirs)) {
  182.             return '';
  183.         }
  184.         if (isset($dirs['dirs'])) {
  185.             uksort($dirs['dirs']'strnatcasecmp');
  186.             foreach ($dirs['dirs'as $dir => $contents{
  187.                 if ($dir == '/'{
  188.                     $usedir '/';
  189.                 else {
  190.                     if ($curdir == '/'{
  191.                         $curdir '';
  192.                     }
  193.                     $usedir = "$curdir/$dir";
  194.                 }
  195.                 $ret .= "$indent   <dir name=\"$dir\"";
  196.                 if ($toplevel{
  197.                     $ret .= ' baseinstalldir="' $this->_options['baseinstalldir''"';
  198.                 else {
  199.                     if (isset($this->_options['installexceptions'][$dir])) {
  200.                         $ret .= ' baseinstalldir="' $this->_options['installexceptions'][$dir'"';
  201.                     }
  202.                 }
  203.                 $ret .= ">\n";
  204.                 $ret .= $this->_formatDir($contents"$indent "$usedir);
  205.                 $ret .= "$indent   </dir> <!-- $usedir -->\n";
  206.             }
  207.         }
  208.         if (isset($dirs['files'])) {
  209.             uksort($dirs['files']'strnatcasecmp');
  210.             foreach ($dirs['files'as $file => $attribs{
  211.                 $ret .= $this->_formatFile($file$attribs$indent);
  212.             }
  213.         }
  214.         return $ret;
  215.     }
  216.  
  217.     /**
  218.      * @param string 
  219.      * @param array 
  220.      * @param string 
  221.      * @access private
  222.      */
  223.     function _formatFile($file$attributes$indent)
  224.     {
  225.         $ret = "$indent   <file role=\"$attributes[role]\"";
  226.         if (isset($this->_options['installexceptions'][$file])) {
  227.             $ret .= ' baseinstalldir="' $this->_options['installexceptions'][$file'"';
  228.         }
  229.         if (isset($attributes['md5sum'])) {
  230.             $ret .= " md5sum=\"$attributes[md5sum]\"";
  231.         }
  232.         if (isset($attributes['platform'])) {
  233.             $ret .= " platform=\"$attributes[platform]\"";
  234.         }
  235.         if (!empty($attributes['install-as'])) {
  236.             $ret .= ' install-as="' .
  237.                 htmlspecialchars($attributes['install-as']'"';
  238.         }
  239.         $ret .= ' name="' htmlspecialchars($file'"';
  240.         if (empty($attributes['replacements'])) {
  241.             $ret .= "/>\n";
  242.         else {
  243.             $ret .= ">\n";
  244.             foreach ($attributes['replacements'as $r{
  245.                 $ret .= "$indent    <replace";
  246.                 foreach ($r as $k => $v{
  247.                     $ret .= " $k=\"" . htmlspecialchars($v.'"';
  248.                 }
  249.                 $ret .= "/>\n";
  250.             }
  251.             $ret .= "$indent   </file>\n";
  252.         }
  253.         return $ret;
  254.     }
  255.  
  256.     /**
  257.      * Generate the <filelist> tag
  258.      * @access private
  259.      * @return string 
  260.      */
  261.     function _doFileList($indent$filelist$curdir)
  262.     {
  263.         $ret '';
  264.         foreach ($filelist as $file => $fa{
  265.             if (isset($fa['##files'])) {
  266.                 $ret .= "$indent      <dir";
  267.             else {
  268.                 $ret .= "$indent      <file";
  269.             }
  270.  
  271.             if (isset($fa['role'])) {
  272.                 $ret .= " role=\"$fa[role]\"";
  273.             }
  274.             if (isset($fa['baseinstalldir'])) {
  275.                 $ret .= ' baseinstalldir="' .
  276.                     htmlspecialchars($fa['baseinstalldir']'"';
  277.             }
  278.             if (isset($fa['md5sum'])) {
  279.                 $ret .= " md5sum=\"$fa[md5sum]\"";
  280.             }
  281.             if (isset($fa['platform'])) {
  282.                 $ret .= " platform=\"$fa[platform]\"";
  283.             }
  284.             if (!empty($fa['install-as'])) {
  285.                 $ret .= ' install-as="' .
  286.                     htmlspecialchars($fa['install-as']'"';
  287.             }
  288.             $ret .= ' name="' htmlspecialchars($file'"';
  289.             if (isset($fa['##files'])) {
  290.                 $ret .= ">\n";
  291.                 $recurdir $curdir;
  292.                 if ($recurdir == '///'{
  293.                     $recurdir '';
  294.                 }
  295.                 $ret .= $this->_doFileList("$indent "$fa['##files']$recurdir $file '/');
  296.                 $displaydir $curdir;
  297.                 if ($displaydir == '///' || $displaydir == '/'{
  298.                     $displaydir '';
  299.                 }
  300.                 $ret .= "$indent      </dir> <!-- $displaydir$file -->\n";
  301.             else {
  302.                 if (empty($fa['replacements'])) {
  303.                     $ret .= "/>\n";
  304.                 else {
  305.                     $ret .= ">\n";
  306.                     foreach ($fa['replacements'as $r{
  307.                         $ret .= "$indent        <replace";
  308.                         foreach ($r as $k => $v{
  309.                             $ret .= " $k=\"" . htmlspecialchars($v.'"';
  310.                         }
  311.                         $ret .= "/>\n";
  312.                     }
  313.                     $ret .= "$indent      </file>\n";
  314.                 }
  315.             }
  316.         }
  317.         return $ret;
  318.     }
  319.     
  320. }
  321.  
  322. ?>

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