PEAR_PackageFile::fromPackageFile PHP Метод

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

Create a PEAR_PackageFile_v* from a package.xml file.
public fromPackageFile ( string $descfile, integer $state, string | false $archive = false ) : PEAR_PackageFile_v1 | PEAR_PackageFile_v2
$descfile string name of package xml file
$state integer package state (one of PEAR_VALIDATE_* constants)
$archive string | false name of the archive this package.xml came from, if any
Результат PEAR_PackageFile_v1 | PEAR_PackageFile_v2
    function &fromPackageFile($descfile, $state, $archive = false)
    {
        $fp = 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;
    }

Usage Example

Пример #1
0
 /**
  * Constructor.
  *
  * Searches all installed applications and libraries for migration
  * directories and builds lists of migrateable modules and directories.
  *
  * @param string $basedir   Base directory of a Git checkout. If provided
  *                          a framework/ sub directory is searched for
  *                          migration scripts too.
  * @param string $pearconf  Path to a PEAR configuration file.
  */
 public function __construct($basedir = null, $pearconf = null)
 {
     // Loop through all applications.
     foreach ($GLOBALS['registry']->listAllApps() as $app) {
         $dir = $GLOBALS['registry']->get('fileroot', $app) . '/migration';
         if (is_dir($dir)) {
             $this->apps[] = $app;
             $this->_lower[] = Horde_String::lower($app);
             $this->dirs[] = realpath($dir);
         }
     }
     // Silence PEAR errors.
     $old_error_reporting = error_reporting();
     error_reporting($old_error_reporting & ~E_DEPRECATED);
     $pear = new PEAR_Config($pearconf);
     // Loop through local framework checkout.
     if ($basedir) {
         $packageFile = new PEAR_PackageFile($pear);
         foreach (glob($basedir . '/framework/*/migration') as $dir) {
             $package = $packageFile->fromPackageFile(dirname($dir) . '/package.xml', PEAR_VALIDATE_NORMAL);
             if ($package instanceof PEAR_Error) {
                 Horde::log(sprintf('%s: %s', $package->getMessage(), print_r($package->getUserInfo(), true)), Horde_Log::ERR);
                 continue;
             }
             $this->apps[] = $package->getName();
             $this->_lower[] = Horde_String::lower($package->getName());
             $this->dirs[] = realpath($dir);
         }
     }
     // Loop through installed PEAR packages.
     $registry = $pear->getRegistry();
     foreach (glob($pear->get('data_dir') . '/*/migration') as $dir) {
         $package = $registry->getPackage(basename(dirname($dir)), 'pear.horde.org');
         if ($package == false) {
             Horde::log("Ignoring package in directory {$dir}", Horde_Log::WARN);
             continue;
         }
         $app = $package->getName();
         if (!in_array($app, $this->apps)) {
             $this->apps[] = $app;
             $this->_lower[] = Horde_String::lower($app);
             $this->dirs[] = realpath($dir);
         }
     }
     error_reporting($old_error_reporting);
 }
All Usage Examples Of PEAR_PackageFile::fromPackageFile