scripts/postfixadmin-cli.php:

- add myself to copyright header
- whitespace changes in dispatch()



git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@1576 a1433add-5e2c-0410-b055-b7f2511e0802
pull/2/head
Christian Boltz 11 years ago
parent c65e3293b6
commit 84b160bd8e

@ -11,7 +11,8 @@
* Copyright 2005-2008, Cake Software Foundation, Inc. * Copyright 2005-2008, Cake Software Foundation, Inc.
* 1785 E. Sahara Avenue, Suite 490-204 * 1785 E. Sahara Avenue, Suite 490-204
* Las Vegas, Nevada 89104 * Las Vegas, Nevada 89104
* Modified for Postfixadmin by Valkum * Modified for PostfixAdmin by Valkum 2011
* Modified for PostfixAdmin by Christian Boltz 2011-2013
* *
* Copyright 2010 * Copyright 2010
* *
@ -228,33 +229,31 @@ class PostfixAdmin {
function dispatch() { function dispatch() {
$CONF = Config::read('all'); $CONF = Config::read('all');
if (!isset($this->args[0])) { if (!isset($this->args[0])) {
$this->help(); $this->help();
return; return;
} }
$this->shell = $this->args[0]; $this->shell = $this->args[0];
$this->shiftArgs(); $this->shiftArgs();
$this->shellName = Inflector::camelize($this->shell); $this->shellName = Inflector::camelize($this->shell);
$this->shellClass = $this->shellName . 'Handler'; $this->shellClass = $this->shellName . 'Handler';
if ($this->shell == 'help') { if ($this->shell == 'help') {
$this->help(); $this->help();
return; return;
} }
# TODO: move shells/shell.php to model/ to enable autoloading # TODO: move shells/shell.php to model/ to enable autoloading
if (!class_exists('Shell')) { if (!class_exists('Shell')) {
require CORE_INCLUDE_PATH . DS . "shells" . DS . 'shell.php'; require CORE_INCLUDE_PATH . DS . "shells" . DS . 'shell.php';
} }
$command = 'help'; # not the worst default ;-) $command = 'help'; # not the worst default ;-)
if (isset($this->args[0])) { if (isset($this->args[0])) {
$command = $this->args[0]; $command = $this->args[0];
} }
$this->shellCommand = $command; $this->shellCommand = $command;
$this->shellClass = 'Cli' . Inflector::camelize($command); $this->shellClass = 'Cli' . Inflector::camelize($command);
if (ucfirst($command) == 'Add' || ucfirst($command) == 'Update') { if (ucfirst($command) == 'Add' || ucfirst($command) == 'Update') {
@ -284,62 +283,62 @@ class PostfixAdmin {
# TODO: add a way to Cli* to signal if the selected handler is supported (for example, not all *Handler support changing the password) # TODO: add a way to Cli* to signal if the selected handler is supported (for example, not all *Handler support changing the password)
if (strtolower(get_parent_class($shell)) == 'shell') { if (strtolower(get_parent_class($shell)) == 'shell') {
$shell->initialize(); $shell->initialize();
$handler = new $shell->handler_to_use; $handler = new $shell->handler_to_use;
if (in_array($task, $handler->taskNames)) { if (in_array($task, $handler->taskNames)) {
$this->shiftArgs(); $this->shiftArgs();
$shell->startup(); $shell->startup();
if (isset($this->args[0]) && $this->args[0] == 'help') { if (isset($this->args[0]) && $this->args[0] == 'help') {
if (method_exists($shell, 'help')) { if (method_exists($shell, 'help')) {
$shell->help(); $shell->help();
exit(); exit();
} else { } else {
$this->help(); $this->help();
} }
} }
$shell->execute(); $shell->execute();
return; return;
} }
} }
$classMethods = get_class_methods($shell); $classMethods = get_class_methods($shell);
$privateMethod = $missingCommand = false; $privateMethod = $missingCommand = false;
if ((in_array($command, $classMethods) || in_array(strtolower($command), $classMethods)) && strpos($command, '_', 0) === 0) { if ((in_array($command, $classMethods) || in_array(strtolower($command), $classMethods)) && strpos($command, '_', 0) === 0) {
$privateMethod = true; $privateMethod = true;
} }
if (!in_array($command, $classMethods) && !in_array(strtolower($command), $classMethods)) { if (!in_array($command, $classMethods) && !in_array(strtolower($command), $classMethods)) {
$missingCommand = true; $missingCommand = true;
} }
$protectedCommands = array( $protectedCommands = array(
'initialize','in','out','err','hr', 'initialize','in','out','err','hr',
'createfile', 'isdir','copydir','object','tostring', 'createfile', 'isdir','copydir','object','tostring',
'requestaction','log','cakeerror', 'shelldispatcher', 'requestaction','log','cakeerror', 'shelldispatcher',
'__initconstants','__initenvironment','__construct', '__initconstants','__initenvironment','__construct',
'dispatch','__bootstrap','getinput','stdout','stderr','parseparams','shiftargs' 'dispatch','__bootstrap','getinput','stdout','stderr','parseparams','shiftargs'
); );
if (in_array(strtolower($command), $protectedCommands)) { if (in_array(strtolower($command), $protectedCommands)) {
$missingCommand = true; $missingCommand = true;
} }
if ($missingCommand && method_exists($shell, 'main')) { if ($missingCommand && method_exists($shell, 'main')) {
$shell->startup(); $shell->startup();
$shell->main(); $shell->main();
} elseif (!$privateMethod && method_exists($shell, $command)) { } elseif (!$privateMethod && method_exists($shell, $command)) {
$this->shiftArgs(); $this->shiftArgs();
$shell->startup(); $shell->startup();
$shell->{$command}(); $shell->{$command}();
} else { } else {
$this->stderr("Unknown {$this->shellName} command '$command'.\nFor usage, try 'postfixadmin-cli {$this->shell} help'.\n\n"); $this->stderr("Unknown {$this->shellName} command '$command'.\nFor usage, try 'postfixadmin-cli {$this->shell} help'.\n\n");
} }
} }
/** /**

Loading…
Cancel
Save