本文整理匯總了PHP中PEAR_PackageFile::fromXmlString方法的典型用法代碼示例。如果您正苦於以下問題:PHP PEAR_PackageFile::fromXmlString方法的具體用法?PHP PEAR_PackageFile::fromXmlString怎麽用?PHP PEAR_PackageFile::fromXmlString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PEAR_PackageFile
的用法示例。
在下文中一共展示了PEAR_PackageFile::fromXmlString方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: fclose
/**
* 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;
}
示例2: validatePackageInfo
/**
* 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;
}
示例3: confirmUpload
/**
* 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';
//.........這裏部分代碼省略.........
示例4: filesize
/**
* 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;
}
示例5: foreach
/**
* 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;
}