⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 installer.php

📁 FP2 CRM code+Mysql DB
💻 PHP
📖 第 1 页 / 共 3 页
字号:
<?php//// +----------------------------------------------------------------------+// | PHP Version 5                                                        |// +----------------------------------------------------------------------+// | Copyright (c) 1997-2004 The PHP Group                                |// +----------------------------------------------------------------------+// | This source file is subject to version 3.0 of the PHP license,       |// | that is bundled with this package in the file LICENSE, and is        |// | available through the world-wide-web at the following url:           |// | 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 world-wide-web, please send a note to          |// | license@php.net so we can mail you a copy immediately.               |// +----------------------------------------------------------------------+// | Authors: Stig Bakken <ssb@php.net>                                   |// |          Tomas V.V.Cox <cox@idecnet.com>                             |// |          Martin Jansen <mj@php.net>                                  |// +----------------------------------------------------------------------+//// $Id: Installer.php,v 1.148 2004/02/29 15:58:17 avsm Exp $require_once 'PEAR/Common.php';require_once 'PEAR/Registry.php';require_once 'PEAR/Dependency.php';require_once 'PEAR/Downloader.php';require_once 'System.php';define('PEAR_INSTALLER_OK',       1);define('PEAR_INSTALLER_FAILED',   0);define('PEAR_INSTALLER_SKIPPED', -1);define('PEAR_INSTALLER_ERROR_NO_PREF_STATE', 2);/** * Administration class used to install PEAR packages and maintain the * installed package database. * * TODO: *   - Check dependencies break on package uninstall (when no force given) *   - add a guessInstallDest() method with the code from _installFile() and *     use that method in Registry::_rebuildFileMap() & Command_Registry::doList(), *     others.. * * @since PHP 4.0.2 * @author Stig Bakken <ssb@php.net> * @author Martin Jansen <mj@php.net> * @author Greg Beaver <cellog@php.net> */class PEAR_Installer extends PEAR_Downloader{    // {{{ properties    /** name of the package directory, for example Foo-1.0     * @var string     */    var $pkgdir;    /** directory where PHP code files go     * @var string     */    var $phpdir;    /** directory where PHP extension files go     * @var string     */    var $extdir;    /** directory where documentation goes     * @var string     */    var $docdir;    /** installation root directory (ala PHP's INSTALL_ROOT or     * automake's DESTDIR     * @var string     */    var $installroot = '';    /** debug level     * @var int     */    var $debug = 1;    /** temporary directory     * @var string     */    var $tmpdir;    /** PEAR_Registry object used by the installer     * @var object     */    var $registry;    /** List of file transactions queued for an install/upgrade/uninstall.     *     *  Format:     *    array(     *      0 => array("rename => array("from-file", "to-file")),     *      1 => array("delete" => array("file-to-delete")),     *      ...     *    )     *     * @var array     */    var $file_operations = array();    // }}}    // {{{ constructor    /**     * PEAR_Installer constructor.     *     * @param object $ui user interface object (instance of PEAR_Frontend_*)     *     * @access public     */    function PEAR_Installer(&$ui)    {        parent::PEAR_Common();        $this->setFrontendObject($ui);        $this->debug = $this->config->get('verbose');        //$this->registry = &new PEAR_Registry($this->config->get('php_dir'));    }    // }}}    // {{{ _deletePackageFiles()    /**     * Delete a package's installed files, does not remove empty directories.     *     * @param string $package package name     *     * @return bool TRUE on success, or a PEAR error on failure     *     * @access private     */    function _deletePackageFiles($package)    {        if (!strlen($package)) {            return $this->raiseError("No package to uninstall given");        }        $filelist = $this->registry->packageInfo($package, 'filelist');        if ($filelist == null) {            return $this->raiseError("$package not installed");        }        foreach ($filelist as $file => $props) {            if (empty($props['installed_as'])) {                continue;            }            $path = $this->_prependPath($props['installed_as'], $this->installroot);            $this->addFileOperation('delete', array($path));        }        return true;    }    // }}}    // {{{ _installFile()    /**     * @param string filename     * @param array attributes from <file> tag in package.xml     * @param string path to install the file in     * @param array options from command-line     * @access private     */    function _installFile($file, $atts, $tmp_path, $options)    {        // {{{ return if this file is meant for another platform        static $os;        if (isset($atts['platform'])) {            if (empty($os)) {                include_once "OS/Guess.php";                $os = new OS_Guess();            }            if (!$os->matchSignature($atts['platform'])) {                $this->log(3, "skipped $file (meant for $atts[platform], we are ".$os->getSignature().")");                return PEAR_INSTALLER_SKIPPED;            }        }        // }}}        // {{{ assemble the destination paths        switch ($atts['role']) {            case 'doc':            case 'data':            case 'test':                $dest_dir = $this->config->get($atts['role'] . '_dir') .                            DIRECTORY_SEPARATOR . $this->pkginfo['package'];                unset($atts['baseinstalldir']);                break;            case 'ext':            case 'php':                $dest_dir = $this->config->get($atts['role'] . '_dir');                break;            case 'script':                $dest_dir = $this->config->get('bin_dir');                break;            case 'src':            case 'extsrc':                $this->source_files++;                return;            default:                return $this->raiseError("Invalid role `$atts[role]' for file $file");        }        $save_destdir = $dest_dir;        if (!empty($atts['baseinstalldir'])) {            $dest_dir .= DIRECTORY_SEPARATOR . $atts['baseinstalldir'];        }        if (dirname($file) != '.' && empty($atts['install-as'])) {            $dest_dir .= DIRECTORY_SEPARATOR . dirname($file);        }        if (empty($atts['install-as'])) {            $dest_file = $dest_dir . DIRECTORY_SEPARATOR . basename($file);        } else {            $dest_file = $dest_dir . DIRECTORY_SEPARATOR . $atts['install-as'];        }        $orig_file = $tmp_path . DIRECTORY_SEPARATOR . $file;        // Clean up the DIRECTORY_SEPARATOR mess        $ds2 = DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR;        list($dest_file, $orig_file) = preg_replace(array('!\\\\+!', '!/!', "!$ds2+!"),                                                    DIRECTORY_SEPARATOR,                                                    array($dest_file, $orig_file));        $installed_as = $dest_file;        $final_dest_file = $this->_prependPath($dest_file, $this->installroot);        $dest_dir = dirname($final_dest_file);        $dest_file = $dest_dir . DIRECTORY_SEPARATOR . '.tmp' . basename($final_dest_file);        // }}}        if (!@is_dir($dest_dir)) {            if (!$this->mkDirHier($dest_dir)) {                return $this->raiseError("failed to mkdir $dest_dir",                                         PEAR_INSTALLER_FAILED);            }            $this->log(3, "+ mkdir $dest_dir");        }        if (empty($atts['replacements'])) {            if (!file_exists($orig_file)) {                return $this->raiseError("file does not exist",                                         PEAR_INSTALLER_FAILED);            }            if (!@copy($orig_file, $dest_file)) {                return $this->raiseError("failed to write $dest_file",                                         PEAR_INSTALLER_FAILED);            }            $this->log(3, "+ cp $orig_file $dest_file");            if (isset($atts['md5sum'])) {                $md5sum = md5_file($dest_file);            }        } else {            // {{{ file with replacements            if (!file_exists($orig_file)) {                return $this->raiseError("file does not exist",                                         PEAR_INSTALLER_FAILED);            }            $fp = fopen($orig_file, "r");            $contents = fread($fp, filesize($orig_file));            fclose($fp);            if (isset($atts['md5sum'])) {                $md5sum = md5($contents);            }            $subst_from = $subst_to = array();            foreach ($atts['replacements'] as $a) {                $to = '';                if ($a['type'] == 'php-const') {                    if (preg_match('/^[a-z0-9_]+$/i', $a['to'])) {                        eval("\$to = $a[to];");                    } else {                        $this->log(0, "invalid php-const replacement: $a[to]");                        continue;                    }                } elseif ($a['type'] == 'pear-config') {                    $to = $this->config->get($a['to']);                    if (is_null($to)) {                        $this->log(0, "invalid pear-config replacement: $a[to]");                        continue;                    }                } elseif ($a['type'] == 'package-info') {                    if (isset($this->pkginfo[$a['to']]) && is_string($this->pkginfo[$a['to']])) {                        $to = $this->pkginfo[$a['to']];                    } else {                        $this->log(0, "invalid package-info replacement: $a[to]");                        continue;                    }                }                if (!is_null($to)) {                    $subst_from[] = $a['from'];                    $subst_to[] = $to;                }            }            $this->log(3, "doing ".sizeof($subst_from)." substitution(s) for $final_dest_file");            if (sizeof($subst_from)) {                $contents = str_replace($subst_from, $subst_to, $contents);            }            $wp = @fopen($dest_file, "wb");            if (!is_resource($wp)) {                return $this->raiseError("failed to create $dest_file: $php_errormsg",                                         PEAR_INSTALLER_FAILED);            }            if (!fwrite($wp, $contents)) {                return $this->raiseError("failed writing to $dest_file: $php_errormsg",                                         PEAR_INSTALLER_FAILED);            }            fclose($wp);            // }}}        }        // {{{ check the md5        if (isset($md5sum)) {            if (strtolower($md5sum) == strtolower($atts['md5sum'])) {                $this->log(2, "md5sum ok: $final_dest_file");            } else {                if (empty($options['force'])) {                    // delete the file                    @unlink($dest_file);                    return $this->raiseError("bad md5sum for file $final_dest_file",                                             PEAR_INSTALLER_FAILED);                } else {                    $this->log(0, "warning : bad md5sum for file $final_dest_file");                }            }        }        // }}}        // {{{ set file permissions        if (!OS_WINDOWS) {            if ($atts['role'] == 'script') {                $mode = 0777 & ~(int)octdec($this->config->get('umask'));                $this->log(3, "+ chmod +x $dest_file");            } else {                $mode = 0666 & ~(int)octdec($this->config->get('umask'));            }            $this->addFileOperation("chmod", array($mode, $dest_file));            if (!@chmod($dest_file, $mode)) {                $this->log(0, "failed to change mode of $dest_file");            }        }        // }}}        $this->addFileOperation("rename", array($dest_file, $final_dest_file));        // Store the full path where the file was installed for easy unistall        $this->addFileOperation("installed_as", array($file, $installed_as,                                $save_destdir, dirname(substr($dest_file, strlen($save_destdir)))));        //$this->log(2, "installed: $dest_file");        return PEAR_INSTALLER_OK;    }    // }}}    // {{{ addFileOperation()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -