Create a PEAR_PackageFile_v* from a compresed Tar or Tgz file.
public fromTgzFile ( $file, $state ) : PEAR_PackageFile_v1 | PEAR_PackageFile_v2 | ||
return | PEAR_PackageFile_v1 | PEAR_PackageFile_v2 |
/** * Returns information about a package file. Expects the name of * a gzipped tar file as input. * * @param string $file name of .tgz file * * @return array array with package information * * @access public * @deprecated use PEAR_PackageFile->fromTgzFile() instead * */ function infoFromTgzFile($file) { $config =& PEAR_Config::singleton(); $packagefile = new PEAR_PackageFile($config); $pf =& $packagefile->fromTgzFile($file, PEAR_VALIDATE_NORMAL); if (PEAR::isError($pf)) { $errs = $pf->getUserinfo(); if (is_array($errs)) { foreach ($errs as $error) { $e = $this->raiseError($error['message'], $error['code'], null, null, $error); } } return $pf; } return $this->_postProcessValidPackagexml($pf); }
/** * Create a PEAR_PackageFile_v* from a .tgz archive or package.xml file. * * This method is able to extract information about a package from a .tgz * archive or from a XML package definition file. * * @access public * @param string $info file name * @param int $state package state (one of PEAR_VALIDATE_* constants) * @return PEAR_PackageFile_v1|PEAR_PackageFile_v2 * @uses fromPackageFile() if the file appears to be XML * @uses fromTgzFile() to load all non-XML files */ function &fromAnyFile($info, $state) { if (is_dir($info)) { $dir_name = realpath($info); if (file_exists($dir_name . '/package.xml')) { $info = PEAR_PackageFile::fromPackageFile($dir_name . '/package.xml', $state); } elseif (file_exists($dir_name . '/package2.xml')) { $info = PEAR_PackageFile::fromPackageFile($dir_name . '/package2.xml', $state); } else { $info = PEAR::raiseError("No package definition found in '{$info}' directory"); } return $info; } $fp = false; if (is_string($info) && strlen($info) < 255 && (file_exists($info) || ($fp = @fopen($info, 'r')))) { if ($fp) { fclose($fp); } $tmp = substr($info, -4); if ($tmp == '.xml') { $info =& PEAR_PackageFile::fromPackageFile($info, $state); } elseif ($tmp == '.tar' || $tmp == '.tgz') { $info =& PEAR_PackageFile::fromTgzFile($info, $state); } else { $fp = fopen($info, "r"); $test = fread($fp, 5); fclose($fp); if ($test == "<?xml") { $info =& PEAR_PackageFile::fromPackageFile($info, $state); } else { $info =& PEAR_PackageFile::fromTgzFile($info, $state); } } } else { $info = PEAR::raiseError("Cannot open '{$info}' for parsing"); return $info; } return $info; }
/** * Returns package information from different sources * * This method is able to extract information about a package * from a .tgz archive or from a XML package definition file. * * @access public * @return string * @static */ function &fromAnyFile($info, $state) { $fp = false; if (is_string($info) && strlen($info) < 255 && (file_exists($info) || ($fp = @fopen($info, 'r')))) { if ($fp) { fclose($fp); } $tmp = substr($info, -4); if ($tmp == '.xml') { $info =& PEAR_PackageFile::fromPackageFile($info, $state); } elseif ($tmp == '.tar' || $tmp == '.tgz') { $info =& PEAR_PackageFile::fromTgzFile($info, $state); } else { $fp = fopen($info, "r"); $test = fread($fp, 5); fclose($fp); if ($test == "<?xml") { $info =& PEAR_PackageFile::fromPackageFile($info, $state); } else { $info =& PEAR_PackageFile::fromTgzFile($info, $state); } } } else { return PEAR::raiseError("Cannot open '{$info}' for parsing"); } return $info; }
/** * Return the PEAR Package representation based on a local *.tgz archive. * * @param string $package_tgz_path Path to the *.tgz file. * @param Components_Pear_Environment $environment The PEAR environment. * * @return PEAR_PackageFile */ public function getPackageFileFromTgz($package_tgz_path, Components_Pear_Environment $environment) { $pkg = new PEAR_PackageFile($environment->getPearConfig()); return Components_Exception_Pear::catchError($pkg->fromTgzFile($package_tgz_path, PEAR_VALIDATE_NORMAL)); }
/** * get package info from tar/tgz file. * * @param string $filename package file name. * @return string package name * @access public * @static */ public function getPackageNameFromTgz($filename) { $config = PEAR_Config::singleton(); $packagefile = new PEAR_PackageFile($config); $info = $packagefile->fromTgzFile($filename, PEAR_VALIDATE_NORMAL); if (PEAR::isError($info)) { return $info; } $info_array = $info->toArray(); return $info_array['name']; }
/** * Returns information about a package file. Expects the name of * a gzipped tar file as input. * * @param string $file name of .tgz file * * @return array array with package information * * @access public * @deprecated use PEAR_PackageFile->fromTgzFile() instead * */ function infoFromTgzFile($file) { $packagefile = new PEAR_PackageFile($this->config); $pf =& $packagefile->fromTgzFile($file, PEAR_VALIDATE_NORMAL); return $this->_postProcessChecks($pf); }
/** * Create a PEAR_PackageFile_v* from a .tgz archive or package.xml file. * * This method is able to extract information about a package from a .tgz * archive or from a XML package definition file. * * @access public * @param string $info file name * @param int $state package state (one of PEAR_VALIDATE_* constants) * @return PEAR_PackageFile_v1|PEAR_PackageFile_v2 * @uses fromPackageFile() if the file appears to be XML * @uses fromTgzFile() to load all non-XML files */ function &fromAnyFile($info, $state) { if (is_dir($info)) { $dir_name = realpath($info); if (file_exists($dir_name . '/package.xml')) { $fname = $dir_name . '/package.xml'; $info = PEAR_PackageFile::fromPackageFile($dir_name . '/package.xml', $state); } elseif (file_exists($dir_name . '/package2.xml')) { $fname = $dir_name . '/package2.xml'; $info = PEAR_PackageFile::fromPackageFile($dir_name . '/package2.xml', $state); } else { return PEAR::raiseError("No package definition found in '{$info}' directory"); } if (file_exists($dir_name . '/package.sig')) { require_once 'PEAR/Gnupg.php'; $gnupg = new PEAR_Gnupg($this->_config); $result = $gnupg->validateSig($fname, $dir_name . '/package.sig'); if (PEAR::isError($result)) { return $result; } } return $info; } $fp = false; if (is_string($info) && strlen($info) < 255 && (file_exists($info) || ($fp = @fopen($info, 'r')))) { if ($fp) { fclose($fp); } $tmp = substr($info, -4); if ($tmp == '.xml') { $info =& PEAR_PackageFile::fromPackageFile($info, $state); } elseif ($tmp == '.tar' || $tmp == '.tgz') { $info =& PEAR_PackageFile::fromTgzFile($info, $state); } else { $fp = fopen($info, 'r'); $test = fread($fp, 5); fclose($fp); if ($test == '<?xml') { $info =& PEAR_PackageFile::fromPackageFile($info, $state); } else { $info =& PEAR_PackageFile::fromTgzFile($info, $state); } } return $info; } $info = PEAR::raiseError("Cannot open '{$info}' for parsing"); return $info; }
$errors[] = $tmpfile->getMessage(); break; } $tmpsize = $file->getProp('size'); } elseif ($file->isMissing()) { $errors[] = 'No file has been uploaded.'; break; } elseif ($file->isError()) { $errors[] = $file->errorMsg(); break; } include_once 'PEAR/PackageFile.php'; include_once 'PEAR/Config.php'; $config = PEAR_Config::singleton(); $pkg = new PEAR_PackageFile($config); $info = $pkg->fromTgzFile(PEAR_UPLOAD_TMPDIR . '/' . $tmpfile, PEAR_VALIDATE_NORMAL); $errors = $warnings = array(); if (PEAR::isError($info)) { if (is_array($info->getUserInfo())) { foreach ($info->getUserInfo() as $err) { if ($err['level'] == 'error') { $errors[] = $err['message']; } else { $warnings[] = $err['message']; } } } $errors[] = $info->getMessage(); break; } if (version_compare($info->getPackageXmlVersion(), '2.0', '<')) {