1
0
mirror of https://github.com/php/php-src.git synced 2026-04-28 10:43:30 +02:00

* code for install/uninstall/upgrade complete, not yet tested

# uses a new, un-committed version of PEAR_Config
This commit is contained in:
Stig Bakken
2002-03-01 09:43:18 +00:00
parent 46bb7e0031
commit 8e0e7cd4ba
3 changed files with 132 additions and 53 deletions
+68 -17
View File
@@ -18,6 +18,15 @@
//
// $Id$
require_once "PEAR.php";
/**
* List of commands and what classes they are implemented in.
* @var array command => implementing class
*/
$GLOBALS['_PEAR_Command_commandlist'] = array();
/**
* PEAR command class, a simple factory class for administrative
* commands.
@@ -61,34 +70,59 @@
* classes do PEAR::raiseError(), from other classes do
* $this->raiseError().
*/
require_once "PEAR.php";
$GLOBALS['_PEAR_Command_commandlist'] = array();
class PEAR_Command
{
function factory($command)
/**
* Get the right object for executing a command.
*
* @param object Instance of PEAR_Config object
* @param string The name of the command
*
* @return object the command object or a PEAR error
*
* @access public
*/
function factory(&$config, $command)
{
static $command_classes = array(
'install' => 'PEAR_Command_Install':
'uninstall' => 'PEAR_Command_Install':
'upgrade' => 'PEAR_Command_Install':
);
if (isset($command_classes[$command])) {
$class = $command_classes[$command];
$obj =& new $class();
if (empty($GLOBALS['_PEAR_Command_commandlist'])) {
PEAR_Command::registerCommands();
}
if (isset($GLOBALS['_PEAR_Command_commandlist'][$command])) {
$class = $GLOBALS['_PEAR_Command_commandlist'][$command];
$obj =& new $class($config);
return $obj;
}
return PEAR::raiseError("unknown command: $command");
}
function registerAllCommands()
/**
* Scan through the Command directory looking for classes
* and see what commands they implement.
*
* @param bool (optional) if FALSE (default), the new list of
* commands should replace the current one. If TRUE,
* new entries will be merged with old.
*
* @param string (optional) where (what directory) to look for
* classes, defaults to the Command subdirectory of
* the directory from where this file (__FILE__) is
* included.
*
* @return bool TRUE on success, a PEAR error on failure
*
* @access public
*/
function registerCommands($merge = false, $dir = null)
{
$dir = dirname(__FILE__) . '/Command';
if ($dir === null) {
$dir = dirname(__FILE__) . '/Command';
}
$dp = @opendir($dir);
if (empty($dp)) {
return PEAR::raiseError("PEAR_Command::registerAllCommands: opendir($dir) failed");
return PEAR::raiseError("PEAR_Command::registerCommands: opendir($dir) failed");
}
if (!$merge) {
$GLOBALS['_PEAR_Command_commandlist'] = array();
}
while ($entry = readdir($dp)) {
if ($entry{0} == '.' || substr($entry, -4) != '.php' || $entry == 'Common.php') {
@@ -98,7 +132,24 @@ class PEAR_Command
$file = "$dir/$entry";
include_once $file;
$implements = call_user_func(array($class, "getCommands"));
foreach ($implements as $command) {
$GLOBALS['_PEAR_Command_commandlist'][$command] = $class;
}
}
return true;
}
/**
* Get the list of currently supported commands, and what
* classes implement them.
*
* @return array command => implementing class
*
* @access public
*/
function getCommands()
{
return $GLOBALS['_PEAR_Command_commandlist'];
}
}
+33 -2
View File
@@ -23,15 +23,46 @@ require_once "PEAR/CommandResponse.php";
class PEAR_Command_Common extends PEAR
{
/**
* PEAR_Config object used to pass user system and configuration
* on when executing commands
*
* @var object
*/
var $config;
/**
* PEAR_Command_Common constructor.
*
* @access public
*/
function PEAR_Command_Common()
{
parent::PEAR();
$this->config = PEAR_Config::singleton();
}
function &makeResponse($status, $message)
/**
* Return a PEAR_CommandResponse object with parameters
* filled in.
*
* @param int status code
* @param string message text
* @param string (optional) message character encoding
*
* @return object a PEAR_CommandResponse object
*
* @access public
*
* @see PEAR_CommandResponse
*/
function &makeResponse($status, $message, $encoding = null)
{
$obj =& new PEAR_CommandResponse($status, $message, $encoding);
return $obj;
}
}
?>
+31 -34
View File
@@ -39,7 +39,8 @@ class PEAR_Command_Install extends PEAR_Command_Common
var $command; // XXX UNUSED
/**
* PEAR_Command_Install constructor. Nothing to see here.
* PEAR_Command_Install constructor.
*
* @access public
*/
function PEAR_Command_Install()
@@ -59,44 +60,40 @@ class PEAR_Command_Install extends PEAR_Command_Common
function run($command, $options, $params)
{
$installer =& new PEAR_Installer($options['php_dir'],
$options['ext_dir'],
$options['doc_dir']);
$installer->debug = @$options['verbose'];
$status = PEAR_COMMAND_SUCCESS;
ob_start();
switch ($command) {
}
}
function doInstall($command, $options, $params)
{
$pkgfile = $cmdargs[0];
$installer =& new PEAR_Installer($script_dir, $ext_dir, $doc_dir);
$installer->setErrorHandling(PEAR_ERROR_DIE,
basename($pkgfile) . ": %s\n");
$installer->debug = $verbose;
$install_options = array();
if ($command == 'upgrade') {
$install_options['upgrade'] = true;
}
foreach ($cmdopts as $opt) {
switch ($opt[0]) {
case 'r':
// This option is for use by rpm and other package
// tools that can install files etc. by itself, but
// still needs to register the package as installed in
// PEAR's local registry.
$install_options['register_only'] = true;
break;
case 'f':
$install_options['force'] = true;
break;
case 'install':
case 'upgrade': {
if ($command == 'upgrade') {
$options['upgrade'] = true;
}
if ($installer->install($params[0], $options, $this->config)) {
print "install ok\n";
} else {
print "install failed\n";
$status = PEAR_COMMAND_FAILURE;
}
break;
}
if ($installer->install($pkgfile, $install_options, $config)) {
print "install ok\n";
} else {
print "install failed\n";
}
case 'uninstall': {
if ($installer->uninstall($params[0], $uninstall_options)) {
print "uninstall ok\n";
} else {
print "uninstall failed\n";
$status = PEAR_COMMAND_FAILURE;
}
break;
}
}
$output = ob_get_contents();
ob_end_clean();
return $this->makeResponse($status, $output);
}
function getStatus(
}
?>