src/PEAR/PackageFile.php
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;
    }
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;
    }
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