* @since 1.2.0 * @copyright 2003 * @package PEAR_PackageFileManager */ class PEAR_PackageFileManager_SimpleGenerator extends PEAR_PackageFile_Generator_v1 { var $_options; /** * remove a warning about missing parameters - don't delete this */ function PEAR_PackageFileManager_SimpleGenerator() { } /** * @param array */ function setPackageFileManagerOptions($opts) { $this->_options = $opts; } /** * Return an XML document based on the package info (as returned * by the PEAR_Common::infoFrom* methods). * * @param array $pkginfo package info * * @return string XML data * * @access public * @deprecated use a PEAR_PackageFile_v* object's generator instead */ function xmlFromInfo($pkginfo) { include_once 'PEAR/PackageFile.php'; include_once 'PEAR/Config.php'; $config = &PEAR_Config::singleton(); $packagefile = &new PEAR_PackageFile($config); $pf = &$packagefile->fromArray($pkginfo); parent::PEAR_PackageFile_Generator_v1($pf); return $this->toXml(); } function getFileRoles() { return PEAR_Common::getFileRoles(); } function getReplacementTypes() { return PEAR_Common::getReplacementTypes(); } /** * Validate XML package definition file. * * @param string $info Filename of the package archive or of the * package definition file * @param array $errors Array that will contain the errors * @param array $warnings Array that will contain the warnings * @param string $dir_prefix (optional) directory where source files * may be found, or empty if they are not available * @access public * @return boolean * @deprecated use the validation of PEAR_PackageFile objects */ function validatePackageInfo($info, &$errors, &$warnings, $dir_prefix = '') { include_once 'PEAR/PackageFile.php'; include_once 'PEAR/Config.php'; $config = &PEAR_Config::singleton(); $packagefile = &new PEAR_PackageFile($config); PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); if (is_array($info)) { $pf = &$packagefile->fromArray($info); if (!$pf->validate(PEAR_VALIDATE_NORMAL)) { foreach ($pf->getValidationWarnings() as $err) { if ($error['level'] == 'error') { $errors[] = $error['message']; } else { $warnings[] = $error['message']; } } return false; } } else { $pf = &$packagefile->fromAnyFile($info, PEAR_VALIDATE_NORMAL); } PEAR::staticPopErrorHandling(); if (PEAR::isError($pf)) { $errs = $pf->getUserinfo(); if (is_array($errs)) { foreach ($errs as $error) { if ($error['level'] == 'error') { $errors[] = $error['message']; } else { $warnings[] = $error['message']; } } } return false; } return true; } /** * @param array * @access protected */ function recursiveXmlFilelist($list) { $this->_dirs = array(); foreach ($list as $file => $attributes) { $this->_addDir($this->_dirs, explode('/', dirname($file)), $file, $attributes); } if (!isset($this->_dirs['dirs'])) { $this->_dirs['dirs'] = array(); } if (count($this->_dirs['dirs']) != 1 || isset($this->_dirs['files'])) { $this->_dirs = array('dirs' => array('/' => $this->_dirs)); } return $this->_formatDir($this->_dirs, '', '', true); } /** * @param array * @param array * @param string|null * @param array|null * @access private */ function _addDir(&$dirs, $dir, $file = null, $attributes = null) { if ($dir == array() || $dir == array('.')) { $dirs['files'][basename($file)] = $attributes; return; } $curdir = array_shift($dir); if (!isset($dirs['dirs'][$curdir])) { $dirs['dirs'][$curdir] = array(); } $this->_addDir($dirs['dirs'][$curdir], $dir, $file, $attributes); } /** * @param array * @param string * @param string * @access private */ function _formatDir($dirs, $indent = '', $curdir = '', $toplevel = false) { $ret = ''; if (!count($dirs)) { return ''; } if (isset($dirs['dirs'])) { uksort($dirs['dirs'], 'strnatcasecmp'); foreach ($dirs['dirs'] as $dir => $contents) { if ($dir == '/') { $usedir = '/'; } else { if ($curdir == '/') { $curdir = ''; } $usedir = "$curdir/$dir"; } $ret .= "$indent