| // | | // +----------------------------------------------------------------------+ // // $Id$ require_once "Experimental/System.php"; /** * Administration class used to maintain the installed package database. */ class PEAR_Registry { // {{{ properties var $statedir; // }}} // {{{ PEAR_Registry function PEAR_Registry() { $this->statedir = PHP_LOCALSTATEDIR . "/pear/registry"; } // }}} // {{{ _assertStateDir() function _assertStateDir() { if (!@is_dir($this->statedir)) { System::mkdir("-p {$this->statedir}"); } } // }}} // {{{ _packageFileName() function _packageFileName($package) { return "{$this->statedir}/{$package}.inf"; } // }}} // {{{ _openPackageFile() function _openPackageFile($package, $mode) { $this->_assertStateDir(); $file = $this->_packageFileName($package); $fp = @fopen($file, $mode); if (!$fp) { return null; } return $fp; } // }}} // {{{ _closePackageFile() function _closePackageFile($fp) { fclose($fp); } // }}} // {{{ packageExists() function packageExists($package) { return file_exists($this->_packageFileName($package)); } // }}} // {{{ addPackage() function addPackage($package, $info) { if ($this->packageExists($package)) { return false; } return $this->upgradePackage($package, $info); } // }}} // {{{ packageInfo() function packageInfo($package = null) { if ($package === null) { return array_map(array($this, "packageInfo"), $this->listPackages()); } $fp = $this->_openPackageFile($package, "r"); $data = fread($fp, filesize($this->_packageFileName($package))); $this->_closePackageFile($fp); return unserialize($data); } // }}} // {{{ deletePackage() function deletePackage($package) { $file = $this->_packageFileName($package); unlink($file); } // }}} // {{{ upgradePackage() function upgradePackage($package, $info) { $fp = $this->_openPackageFile($package, "w"); if ($fp === null) { return false; } fwrite($fp, serialize($info)); $this->_closePackageFile($fp); return true; } // }}} // {{{ listPackages() function listPackages() { $dp = opendir($this->statedir); $pkglist = array(); while ($ent = readdir($dp)) { if ($ent{0} == "." || substr($ent, -4) != ".inf") { continue; } $pkglist[] = substr($entry, 0, -4); } return $pkglist; } // }}} } ?>