📄 dependencydb.php
字号:
<?php/** * PEAR_DependencyDB, advanced installed packages dependency database * * PHP versions 4 and 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category pear * @package PEAR * @author Tomas V. V. Cox <cox@idecnet.com> * @author Greg Beaver <cellog@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version CVS: $Id: DependencyDB.php,v 1.6.2.2 2005/11/02 16:57:21 cellog Exp $ * @link http://pear.php.net/package/PEAR * @since File available since Release 1.4.0a1 *//** * Needed for error handling */require_once 'PEAR.php';require_once 'PEAR/Config.php';/** * Track dependency relationships between installed packages * @category pear * @package PEAR * @author Greg Beaver <cellog@php.net> * @author Tomas V.V.Cox <cox@idec.net.com> * @copyright 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/PEAR * @since Class available since Release 1.4.0a1 */class PEAR_DependencyDB{ // {{{ properties /** * This is initialized by {@link setConfig()} * @var PEAR_Config * @access private */ var $_config; /** * This is initialized by {@link setConfig()} * @var PEAR_Registry * @access private */ var $_registry; /** * Filename of the dependency DB (usually .depdb) * @var string * @access private */ var $_depdb = false; /** * File name of the lockfile (usually .depdblock) * @var string * @access private */ var $_lockfile = false; /** * Open file resource for locking the lockfile * @var resource|false * @access private */ var $_lockFp = false; /** * API version of this class, used to validate a file on-disk * @var string * @access private */ var $_version = '1.0'; /** * Cached dependency database file * @var array|null * @access private */ var $_cache; // }}} // {{{ & singleton() /** * Get a raw dependency database. Calls setConfig() and assertDepsDB() * @param PEAR_Config * @param string|false full path to the dependency database, or false to use default * @return PEAR_DependencyDB|PEAR_Error * @static */ function &singleton(&$config, $depdb = false) { if (!isset($GLOBALS['_PEAR_DEPENDENCYDB_INSTANCE'] [$config->get('php_dir', null, 'pear.php.net')])) { $a = new PEAR_DependencyDB; $GLOBALS['_PEAR_DEPENDENCYDB_INSTANCE'] [$config->get('php_dir', null, 'pear.php.net')] = &$a; $a->setConfig($config, $depdb); if (PEAR::isError($e = $a->assertDepsDB())) { return $e; } } return $GLOBALS['_PEAR_DEPENDENCYDB_INSTANCE'] [$config->get('php_dir', null, 'pear.php.net')]; } /** * Set up the registry/location of dependency DB * @param PEAR_Config|false * @param string|false full path to the dependency database, or false to use default */ function setConfig(&$config, $depdb = false) { if (!$config) { $this->_config = &PEAR_Config::singleton(); } else { $this->_config = &$config; } $this->_registry = &$this->_config->getRegistry(); if (!$depdb) { $this->_depdb = $this->_config->get('php_dir', null, 'pear.php.net') . DIRECTORY_SEPARATOR . '.depdb'; } else { $this->_depdb = $depdb; } $this->_lockfile = dirname($this->_depdb) . DIRECTORY_SEPARATOR . '.depdblock'; } // }}} function hasWriteAccess() { if (!@file_exists($this->_depdb)) { $dir = $this->_depdb; while ($dir && $dir != '.') { $dir = dirname($dir); // cd .. if ($dir != '.' && @file_exists($dir)) { if (@is_writeable($dir)) { return true; } else { return false; } } } return false; } return @is_writeable($this->_depdb); } // {{{ assertDepsDB() /** * Create the dependency database, if it doesn't exist. Error if the database is * newer than the code reading it. * @return void|PEAR_Error */ function assertDepsDB() { if (!is_file($this->_depdb)) { $this->rebuildDB(); } else { $depdb = $this->_getDepDB(); // Datatype format has been changed, rebuild the Deps DB if ($depdb['_version'] < $this->_version) { $this->rebuildDB(); } if ($depdb['_version']{0} > $this->_version{0}) { return PEAR::raiseError('Dependency database is version ' . $depdb['_version'] . ', and we are version ' . $this->_version . ', cannot continue'); } } } /** * Get a list of installed packages that depend on this package * @param PEAR_PackageFile_v1|PEAR_PackageFile_v2|array * @return array|false */ function getDependentPackages(&$pkg) { $data = $this->_getDepDB(); if (is_object($pkg)) { $channel = strtolower($pkg->getChannel()); $package = strtolower($pkg->getPackage()); } else { $channel = strtolower($pkg['channel']); $package = strtolower($pkg['package']); } if (isset($data['packages'][$channel][$package])) { return $data['packages'][$channel][$package]; } return false; } /** * Get a list of the actual dependencies of installed packages that depend on * a package. * @param PEAR_PackageFile_v1|PEAR_PackageFile_v2|array * @return array|false */ function getDependentPackageDependencies(&$pkg) { $data = $this->_getDepDB(); if (is_object($pkg)) { $channel = strtolower($pkg->getChannel()); $package = strtolower($pkg->getPackage()); } else { $channel = strtolower($pkg['channel']); $package = strtolower($pkg['package']); } $depend = $this->getDependentPackages($pkg); if (!$depend) { return false; } $dependencies = array(); foreach ($depend as $info) { $temp = $this->getDependencies($info); foreach ($temp as $dep) { if (strtolower($dep['dep']['channel']) == strtolower($channel) && strtolower($dep['dep']['name']) == strtolower($package)) { $dependencies[$info['channel']][$info['package']][] = $dep; } } } return $dependencies; } /** * Get a list of dependencies of this installed package * @param PEAR_PackageFile_v1|PEAR_PackageFile_v2|array * @return array|false */ function getDependencies(&$pkg) { if (is_object($pkg)) { $channel = strtolower($pkg->getChannel()); $package = strtolower($pkg->getPackage()); } else { $channel = strtolower($pkg['channel']); $package = strtolower($pkg['package']); } $data = $this->_getDepDB(); if (isset($data['dependencies'][$channel][$package])) { return $data['dependencies'][$channel][$package]; } return false; } /** * Determine whether $parent depends on $child, near or deep * @param array|PEAR_PackageFile_v2|PEAR_PackageFile_v2 * @param array|PEAR_PackageFile_v2|PEAR_PackageFile_v2 */ function dependsOn($parent, $child) { $c = array(); $this->_getDepDB(); return $this->_dependsOn($parent, $child, $c); } function _dependsOn($parent, $child, &$checked) { if (is_object($parent)) { $channel = strtolower($parent->getChannel()); $package = strtolower($parent->getPackage()); } else { $channel = strtolower($parent['channel']); $package = strtolower($parent['package']); } if (is_object($child)) { $depchannel = strtolower($child->getChannel()); $deppackage = strtolower($child->getPackage()); } else { $depchannel = strtolower($child['channel']); $deppackage = strtolower($child['package']); } if (isset($checked[$channel][$package][$depchannel][$deppackage])) { return false; // avoid endless recursion } $checked[$channel][$package][$depchannel][$deppackage] = true; if (!isset($this->_cache['dependencies'][$channel][$package])) { return false; } foreach ($this->_cache['dependencies'][$channel][$package] as $info) { if (strtolower($info['dep']['channel']) == strtolower($depchannel) && strtolower($info['dep']['name']) == strtolower($deppackage)) { return true; } } foreach ($this->_cache['dependencies'][$channel][$package] as $info) { if ($this->_dependsOn(array( 'channel' => $info['dep']['channel'], 'package' => $info['dep']['name']), $child, $checked)) { return true; } } return false; } /** * Register dependencies of a package that is being installed or upgraded * @param PEAR_PackageFile_v2|PEAR_PackageFile_v2 */ function installPackage(&$package) { $data = $this->_getDepDB(); unset($this->_cache); $this->_setPackageDeps($data, $package); $this->_writeDepDB($data); } /** * Remove dependencies of a package that is being uninstalled, or upgraded. * * Upgraded packages first uninstall, then install * @param PEAR_PackageFile_v1|PEAR_PackageFile_v2|array If an array, then it must have * indices 'channel' and 'package' */ function uninstallPackage(&$pkg) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -