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

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