PEAR_PackageFile::fromTgzFile PHP Метод

fromTgzFile() публичный Метод

Create a PEAR_PackageFile_v* from a compresed Tar or Tgz file.
public fromTgzFile ( $file, $state ) : PEAR_PackageFile_v1 | PEAR_PackageFile_v2
Результат PEAR_PackageFile_v1 | PEAR_PackageFile_v2
    function &fromTgzFile($file, $state)
    {
        if (!class_exists('Archive_Tar')) {
            require_once 'Archive/Tar.php';
        }
        $tar = new Archive_Tar($file);
        if ($this->_debug <= 1) {
            $tar->pushErrorHandling(PEAR_ERROR_RETURN);
        }
        $content = $tar->listContent();
        if ($this->_debug <= 1) {
            $tar->popErrorHandling();
        }
        if (!is_array($content)) {
            if (is_string($file) && strlen($file < 255) && (!file_exists($file) || !@is_file($file))) {
                $ret = PEAR::raiseError("could not open file \"{$file}\"");
                return $ret;
            }
            $file = realpath($file);
            $ret = PEAR::raiseError("Could not get contents of package \"{$file}\"" . '. Invalid tgz file.');
            return $ret;
        }
        if (!count($content) && !@is_file($file)) {
            $ret = PEAR::raiseError("could not open file \"{$file}\"");
            return $ret;
        }
        $xml = null;
        $origfile = $file;
        foreach ($content as $file) {
            $name = $file['filename'];
            if ($name == 'package2.xml') {
                // allow a .tgz to distribute both versions
                $xml = $name;
                break;
            }
            if ($name == 'package.xml') {
                $xml = $name;
                break;
            } elseif (preg_match('/package.xml$/', $name, $match)) {
                $xml = $name;
                break;
            }
        }
        $tmpdir = System::mktemp('-t ' . $this->_config->get('temp_dir') . ' -d pear');
        if ($tmpdir === false) {
            $ret = PEAR::raiseError("there was a problem with getting the configured temp directory");
            return $ret;
        }
        PEAR_PackageFile::addTempFile($tmpdir);
        $this->_extractErrors();
        PEAR::staticPushErrorHandling(PEAR_ERROR_CALLBACK, array($this, '_extractErrors'));
        if (!$xml || !$tar->extractList(array($xml), $tmpdir)) {
            $extra = implode("\n", $this->_extractErrors());
            if ($extra) {
                $extra = ' ' . $extra;
            }
            PEAR::staticPopErrorHandling();
            $ret = PEAR::raiseError('could not extract the package.xml file from "' . $origfile . '"' . $extra);
            return $ret;
        }
        PEAR::staticPopErrorHandling();
        $ret =& PEAR_PackageFile::fromPackageFile("{$tmpdir}/{$xml}", $state, $origfile);
        return $ret;
    }

Usage Example

Пример #1
0
 /**
  * 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);
 }
All Usage Examples Of PEAR_PackageFile::fromTgzFile