PEAR_PackageFile::fromAnyFile PHP Метод

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

This method is able to extract information about a package from a .tgz archive or from a XML package definition file.
public fromAnyFile ( string $info, integer $state ) : PEAR_PackageFile_v1 | PEAR_PackageFile_v2
$info string file name
$state integer package state (one of PEAR_VALIDATE_* constants)
Результат PEAR_PackageFile_v1 | PEAR_PackageFile_v2
    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);
                }
            }
            return $info;
        }
        $info = PEAR::raiseError("Cannot open '{$info}' for parsing");
        return $info;
    }

Usage Example

Пример #1
1
 public function checkDownloads()
 {
     $pear = new Varien_Pear();
     $pkg = new PEAR_PackageFile($pear->getConfig(), false);
     $result = true;
     foreach ($this->getPackages() as $package) {
         $obj = $pkg->fromAnyFile($package, PEAR_VALIDATE_NORMAL);
         if (PEAR::isError($obj)) {
             $uinfo = $obj->getUserInfo();
             if (is_array($uinfo)) {
                 foreach ($uinfo as $message) {
                     if (is_array($message)) {
                         $message = $message['message'];
                     }
                     Mage::getSingleton('Mage_Install_Model_Session')->addError($message);
                 }
             } else {
                 print_r($obj->getUserInfo());
                 #Mage::getSingleton('Mage_Install_Model_Session')->addError($message);
             }
             $result = false;
         }
     }
     return $result;
 }
All Usage Examples Of PEAR_PackageFile::fromAnyFile