Create a PEAR_PackageFile_v* from an XML string.
public fromXmlString ( string $data, integer $state, string $file, string $archive = false ) : PEAR_PackageFile_v1 | PEAR_PackageFile_v2 | ||
$data | string | contents of package.xml file |
$state | integer | package state (one of PEAR_VALIDATE_* constants) |
$file | string | full path to the package.xml file (and the files it references) |
$archive | string | optional name of the archive that the XML was extracted from, if any |
리턴 | PEAR_PackageFile_v1 | PEAR_PackageFile_v2 |
/** * Create a PEAR_PackageFile_v* from a package.xml file. * * @access public * @param string $descfile name of package xml file * @param int $state package state (one of PEAR_VALIDATE_* constants) * @param string|false $archive name of the archive this package.xml came * from, if any * @return PEAR_PackageFile_v1|PEAR_PackageFile_v2 * @uses PEAR_PackageFile::fromXmlString to create the oject after the * XML is loaded from the package.xml file. */ function &fromPackageFile($descfile, $state, $archive = false) { if (is_string($descfile) && strlen($descfile) < 255 && (!file_exists($descfile) || !is_file($descfile) || !is_readable($descfile) || !($fp = @fopen($descfile, 'r')))) { $a = PEAR::raiseError("Unable to open {$descfile}"); return $a; } // read the whole thing so we only get one cdata callback // for each block of cdata fclose($fp); $data = file_get_contents($descfile); $ret =& PEAR_PackageFile::fromXmlString($data, $state, $descfile, $archive); return $ret; }
/** * 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 = '') { $config =& PEAR_Config::singleton(); $packagefile = new PEAR_PackageFile($config); PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); if (strpos($info, '<?xml') !== false) { $pf =& $packagefile->fromXmlString($info, PEAR_VALIDATE_NORMAL, ''); } 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; }
/** * Confirm release upload * * @param string Package name * @param string Package version * @param string Package state * @param string Release notes * @param string md5 * @param int Package id from database * @param string package contents * @static * @return string the file name of the upload or PEAR_Error object if problems */ static function confirmUpload($package, $version, $state, $relnotes, $md5sum, $package_id, $file, $pkg_info = false, $packagexml = false, $compatible = false) { require_once 'PEAR/Common.php'; global $dbh, $auth_user, $_PEAR_Common_dependency_types, $_PEAR_Common_dependency_relations; if (!$pkg_info) { require_once 'Archive/Tar.php'; $tar = new Archive_Tar($file); $oldpackagexml = $tar->extractInString('package.xml'); if (null === ($packagexml = $tar->extractInString('package2.xml'))) { if ($oldpackagexml === null) { return PEAR::raiseError('Archive uploaded does not appear to contain a package.xml!'); } $packagexml = $oldpackagexml; } $compatible = $oldpackagexml != $packagexml ? true : false; } // Update releases table $query = "INSERT INTO releases (id,package,version,state,doneby," . "releasedate,releasenotes) VALUES(?,?,?,?,?,NOW(),?)"; $sth = $dbh->prepare($query); $release_id = $dbh->nextId('releases'); $dbh->execute($sth, array($release_id, $package_id, $version, $state, $auth_user->handle, $relnotes)); // Update files table $query = "INSERT INTO files " . "(id,package,`release`,md5sum,basename,fullpath,packagexml) " . "VALUES(?,?,?,?,?,?,?)"; $sth = $dbh->prepare($query); $file_id = $dbh->nextId("files"); $ok = $dbh->execute($sth, array($file_id, $package_id, $release_id, $md5sum, basename($file), $file, $packagexml)); /* * Code duplication with deps error * Should be droped soon or later using transaction * (and add mysql4 as a pe(ar|cl)web requirement) */ if (PEAR::isError($ok)) { $dbh->query("DELETE FROM releases WHERE id = {$release_id}"); @unlink($file); return $ok; } // Update dependency table $query = "INSERT INTO deps " . "(package, `release`, type, relation, version, name, optional) " . "VALUES (?,?,?,?,?,?,?)"; $sth = $dbh->prepare($query); if (!$pkg_info) { require_once 'PEAR/PackageFile.php'; require_once 'PEAR/Config.php'; $config = PEAR_Config::singleton(); $pf = new PEAR_PackageFile($config); $pkg_info = $pf->fromXmlString($packagexml, PEAR_VALIDATE_DOWNLOADING, $compatible ? 'package2.xml' : 'package.xml'); } $deps = $pkg_info->getDeps(true); // get the package2.xml actual content $storedeps = $pkg_info->getDeps(); // get the BC-compatible content $pearused = false; if (isset($deps['required']['package'])) { if (!isset($deps['required']['package'][0])) { $deps['required']['package'] = array($deps['required']['package']); } foreach ($deps['required']['package'] as $pkgdep) { if ($pkgdep['channel'] == 'pear.php.net' && strtolower($pkgdep['name']) == 'pear') { $pearused = true; } } } if (is_array($storedeps)) { foreach ($storedeps as $dep) { $prob = array(); if (empty($dep['type']) || !in_array($dep['type'], $_PEAR_Common_dependency_types)) { $prob[] = 'type'; } if (empty($dep['name'])) { /* * NOTE from pajoye in ver 1.166: * This works for now. * This would require a 'cleaner' InfoFromXXX * which may return a defined set of data using * default values if required. */ if (strtolower($dep['type']) == 'php') { $dep['name'] = 'PHP'; } else { $prob[] = 'name'; } } elseif (strtolower($dep['name']) == 'pear') { if (!$pearused && $compatible) { // there is no need for a PEAR dependency here continue; } if (!$pearused && !$compatible) { $dep['name'] = 'PEAR Installer'; } } if (empty($dep['rel']) || !in_array($dep['rel'], $_PEAR_Common_dependency_relations)) { $prob[] = 'rel'; } if (empty($dep['optional'])) { $optional = 0; } else { if ($dep['optional'] != strtolower($dep['optional'])) { $prob[] = 'optional'; } $optional = $dep['optional'] == 'yes' ? 1 : 0; } if (count($prob)) { $res = PEAR::raiseError('The following attribute(s) ' . 'were missing or need proper values: ' . implode(', ', $prob)); } else { $res = $dbh->execute($sth, array($package_id, $release_id, $dep['type'], $dep['rel'], @$dep['version'], $dep['name'], $optional)); } if (PEAR::isError($res)) { $dbh->query('DELETE FROM deps WHERE `release` = ' . $release_id); $dbh->query('DELETE FROM releases WHERE id = ' . $release_id); @unlink($file); return $res; } } } include_once 'pear-database-package.php'; $n = package::info($package, 'name'); if (!in_array($n, array('pearweb', 'pearweb_phars'), true)) { // Add release archive file to API documentation queue $query = "INSERT INTO apidoc_queue (filename, queued) " . "VALUES ('" . $file . "', NOW())"; // Don't abort the release if something goes wrong. $dbh->pushErrorHandling(PEAR_ERROR_RETURN); $sth = $dbh->query($query); $dbh->popErrorHandling(); } // Update Cache include_once 'pear-rest.php'; $pear_rest = new pearweb_Channel_REST_Generator(PEAR_REST_PATH, $dbh); $pear_rest->saveAllReleasesREST($package); $pear_rest->saveReleaseREST($file, $packagexml, $pkg_info, $auth_user->handle, $release_id); $pear_rest->savePackagesCategoryREST(package::info($package, 'category')); return $file; }
/** * Returns information about a package file. Expects the name of * a package xml file as input. * * @param string $descfile name of package xml file * @return array array with package information * @access public * @static */ function &fromPackageFile($descfile, $state, $archive = false) { if (is_string($descfile) && strlen($descfile) < 255 && !@is_file($descfile) || !is_readable($descfile) || !($fp = @fopen($descfile, 'r'))) { return PEAR::raiseError("Unable to open {$descfile}"); } // read the whole thing so we only get one cdata callback // for each block of cdata $data = @fread($fp, filesize($descfile)); $ret =& PEAR_PackageFile::fromXmlString($data, $state, $descfile, $archive); return $ret; }
/** * Retrieve a package file based on a previous release * * @param string $pfcontents contents of the previous release's package.xml * @return PEAR_PackageFile_v2 */ function getPackageXmlV2($pfcontents) { require_once 'PEAR/PackageFile.php'; require_once 'PEAR/Config.php'; $config = PEAR_Config::singleton(); $pkg = new PEAR_PackageFile($config, false, PEAR_TMPDIR); PEAR::pushErrorHandling(PEAR_ERROR_RETURN); $pf = $pkg->fromXmlString($pfcontents, PEAR_VALIDATE_DOWNLOADING, 'package.xml'); PEAR::popErrorHandling(); if (PEAR::isError($pf)) { return $pf; } if ($pf->getPackagexmlVersion() != '1.0') { $pf2 = new PEAR_PackageFile_v2_rw(); $pf2->fromArray($pf->getArray()); } else { require_once 'PEAR/PackageFile/Generator/v1.php'; $gen = new PEAR_PackageFile_Generator_v1($pf); $pf2 = $gen->toV2('PEAR_PackageFile_v2_rw'); } require_once 'pear-database-package.php'; $info = package::info($pf2->getPackage()); $pf2->setPackage($this->_package); $pf2->setChannel('pear.php.net'); $pf2->setSummary($info['summary']); $pf2->setDescription($info['description']); $m = $pf2->getMaintainers(); foreach ($m as $maintainer) { $pf2->deleteMaintainer($maintainer['handle']); } $maintainers = package::info($this->_package, 'authors'); foreach ($maintainers as $maintainer) { $pf2->addMaintainer($maintainer['role'], $maintainer['handle'], $maintainer['name'], $maintainer['email'], $maintainer['active'] ? 'yes' : 'no'); } return $pf2; }