aj Sun Feb 11 16:38:28 2001 EDT
Modified files:
/php4/pear CMD.php
Log:
Fixed indentation problems related to use of TAB instead of spaces
Index: php4/pear/CMD.php
diff -u php4/pear/CMD.php:1.1 php4/pear/CMD.php:1.2
--- php4/pear/CMD.php:1.1 Sun Feb 11 13:39:13 2001
+++ php4/pear/CMD.php Sun Feb 11 16:38:28 2001
@@ -13,11 +13,11 @@
// | obtain it through the world-wide-web, please send a note to |
// | [EMAIL PROTECTED] so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
-// | Authors: Anders Johannsen <[EMAIL PROTECTED]>
|
+// | Authors: Anders Johannsen <[EMAIL PROTECTED]> |
// | |
// +----------------------------------------------------------------------+
//
-define('CMD_RCSID', '$Id: CMD.php,v 1.1 2001/02/11 21:39:13 aj Exp $');
+define('CMD_RCSID', '$Id: CMD.php,v 1.2 2001/02/12 00:38:28 aj Exp $');
/**
* The Cmd:: class implements an abstraction for various ways
@@ -26,7 +26,7 @@
* register_shutdown_function() or as a detached process using nohup).
*
* @author Anders Johannsen <[EMAIL PROTECTED]>
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
**/
require_once 'PEAR.php';
@@ -34,67 +34,67 @@
class Cmd extends PEAR
{
- var $arrSetting = array();
- var $arrConstant = array();
- var $arrCommand = array();
-
+ var $arrSetting = array();
+ var $arrConstant = array();
+ var $arrCommand = array();
+
/**
* Class constructor
*
* Defines all necessary constants and sets defaults
*
* @author Anders Johannsen <[EMAIL PROTECTED]>
- *
+ *
* @access public
*
**/
-
+
function Cmd ()
{
- // Defining constants
- $this->arrConstant = array ("CMD_SEQUENCE",
-
"CMD_SHUTDOWN",
- "CMD_SHELL",
- "CMD_OUTPUT",
- "CMD_NOHUP",
- "CMD_VERBOSE"
- );
-
- foreach ($this->arrConstant as $key => $value) {
- if (!defined($value)) {
- define($value, $key);
- }
- }
-
- // Setting default values
- $this->arrSetting[CMD_SEQUENCE] = true;
- $this->arrSetting[CMD_SHUTDOWN] = false;
- $this->arrSetting[CMD_OUTPUT] = false;
- $this->arrSetting[CMD_NOHUP] = false;
- $this->arrSetting[CMD_VERBOSE] = false;
-
- $arrShell = array ("sh", "bash", "zsh", "tcsh", "csh", "ash", "sash",
"esh", "ksh");
-
- foreach ($arrShell as $shell) {
- if ($this->arrSetting[CMD_SHELL] = $this->which($shell)) {
- break;
- }
- }
-
- if (empty($this->arrSetting[CMD_SHELL])) {
- $this->raiseError("No shell found");
- }
+ // Defining constants
+ $this->arrConstant = array ("CMD_SEQUENCE",
+ "CMD_SHUTDOWN",
+ "CMD_SHELL",
+ "CMD_OUTPUT",
+ "CMD_NOHUP",
+ "CMD_VERBOSE"
+ );
+
+ foreach ($this->arrConstant as $key => $value) {
+ if (!defined($value)) {
+ define($value, $key);
+ }
+ }
+
+ // Setting default values
+ $this->arrSetting[CMD_SEQUENCE] = true;
+ $this->arrSetting[CMD_SHUTDOWN] = false;
+ $this->arrSetting[CMD_OUTPUT] = false;
+ $this->arrSetting[CMD_NOHUP] = false;
+ $this->arrSetting[CMD_VERBOSE] = false;
+
+ $arrShell = array ("sh", "bash", "zsh", "tcsh", "csh", "ash", "sash", "esh",
+"ksh");
+
+ foreach ($arrShell as $shell) {
+ if ($this->arrSetting[CMD_SHELL] = $this->which($shell)) {
+ break;
+ }
+ }
+
+ if (empty($this->arrSetting[CMD_SHELL])) {
+ $this->raiseError("No shell found");
+ }
}
-
+
/**
* Sets any option
*
* The options are currently:
- * CMD_SHUTDOWN : Execute commands via a shutdown function
- * CMD_SHELL : Path to shell
- * CMD_OUTPUT : Output stdout from process
- * CMD_NOHUP : Use nohup to detach process
- * CMD_VERBOSE : Print errors to stdout
+ * CMD_SHUTDOWN : Execute commands via a shutdown function
+ * CMD_SHELL : Path to shell
+ * CMD_OUTPUT : Output stdout from process
+ * CMD_NOHUP : Use nohup to detach process
+ * CMD_VERBOSE : Print errors to stdout
*
* @param $option is a constant, which corresponds to the
* option that should be changed
@@ -109,49 +109,49 @@
* @author Anders Johannsen <[EMAIL PROTECTED]>
*
**/
-
+
function setOption ($option, $setting)
{
- if (empty($this->arrConstant[$option])) {
- $this->raiseError("No such option: $option");
- return false;
- }
-
-
- switch ($option) {
- case CMD_OUTPUT:
- case CMD_SHUTDOWN:
- case CMD_VERBOSE:
- case CMD_SEQUENCE:
- $this->arrSetting[$option] = $setting;
- return true;
- break;
-
- case CMD_SHELL:
- if (is_executable($setting)) {
- $this->arrSetting[$option] = $setting;
- return true;
- } else {
- $this->raiseError("No such shell: $setting");
- return false;
- }
- break;
-
-
- case CMD_NOHUP:
- if (empty($setting)) {
- $this->arrSetting[$option] = false;
-
- } else if ($location = $this->which("nohup")) {
- $this->arrSetting[$option] = true;
-
- } else {
- $this->raiseError("Nohup was not found on your system");
- return false;
- }
- break;
-
- }
+ if (empty($this->arrConstant[$option])) {
+ $this->raiseError("No such option: $option");
+ return false;
+ }
+
+
+ switch ($option) {
+ case CMD_OUTPUT:
+ case CMD_SHUTDOWN:
+ case CMD_VERBOSE:
+ case CMD_SEQUENCE:
+ $this->arrSetting[$option] = $setting;
+ return true;
+ break;
+
+ case CMD_SHELL:
+ if (is_executable($setting)) {
+ $this->arrSetting[$option] = $setting;
+ return true;
+ } else {
+ $this->raiseError("No such shell: $setting");
+ return false;
+ }
+ break;
+
+
+ case CMD_NOHUP:
+ if (empty($setting)) {
+ $this->arrSetting[$option] = false;
+
+ } else if ($location = $this->which("nohup")) {
+ $this->arrSetting[$option] = true;
+
+ } else {
+ $this->raiseError("Nohup was not found on your system");
+ return false;
+ }
+ break;
+
+ }
}
/**
@@ -166,24 +166,24 @@
* @author Anders Johannsen <[EMAIL PROTECTED]>
*
**/
-
+
function command($command)
{
- if (is_array($command)) {
- foreach ($command as $key => $value) {
- $this->arrCommand[] = $value;
- }
- return true;
+ if (is_array($command)) {
+ foreach ($command as $key => $value) {
+ $this->arrCommand[] = $value;
+ }
+ return true;
- } else if (is_string($command)) {
- $this->arrCommand[] = $command;
- return true;
- }
-
- $this->raiseError("Argument not valid");
- return false;
+ } else if (is_string($command)) {
+ $this->arrCommand[] = $command;
+ return true;
+ }
+
+ $this->raiseError("Argument not valid");
+ return false;
}
-
+
/**
* Executes the code according to given options
*
@@ -194,39 +194,39 @@
* @author Anders Johannsen <[EMAIL PROTECTED]>
*
**/
-
+
function exec()
{
- // Warning about impossible mix of options
- if (!empty($this->arrSetting[CMD_OUTPUT])) {
- if (!empty($this->arrSetting[CMD_SHUTDOWN]) ||
!empty($this->arrSetting[CMD_NOHUP])) {
- $this->raiseError("Error: Commands executed via
shutdown functions or nohup cannot return output");
- return false;
- }
- }
-
- // Building command
- $strCommand = implode(";", $this->arrCommand);
-
- $strExec = "echo '$strCommand' | ".$this->arrSetting[CMD_SHELL];
-
- if (empty($this->arrSetting[CMD_OUTPUT])) {
- $strExec = $strExec . ' > /dev/null';
- }
-
- if (!empty($this->arrSetting[CMD_NOHUP])) {
- $strExec = 'nohup ' . $strExec;
- }
-
- // Executing
- if (!empty($this->arrSetting[CMD_SHUTDOWN])) {
- $line = "system(\"$strExec\");";
- $function = create_function('', $line);
- register_shutdown_function($function);
- return true;
- } else {
- return `$strExec`;
- }
+ // Warning about impossible mix of options
+ if (!empty($this->arrSetting[CMD_OUTPUT])) {
+ if (!empty($this->arrSetting[CMD_SHUTDOWN]) ||
+!empty($this->arrSetting[CMD_NOHUP])) {
+ $this->raiseError("Error: Commands executed via shutdown functions or
+nohup cannot return output");
+ return false;
+ }
+ }
+
+ // Building command
+ $strCommand = implode(";", $this->arrCommand);
+
+ $strExec = "echo '$strCommand' | ".$this->arrSetting[CMD_SHELL];
+
+ if (empty($this->arrSetting[CMD_OUTPUT])) {
+ $strExec = $strExec . ' > /dev/null';
+ }
+
+ if (!empty($this->arrSetting[CMD_NOHUP])) {
+ $strExec = 'nohup ' . $strExec;
+ }
+
+ // Executing
+ if (!empty($this->arrSetting[CMD_SHUTDOWN])) {
+ $line = "system(\"$strExec\");";
+ $function = create_function('', $line);
+ register_shutdown_function($function);
+ return true;
+ } else {
+ return `$strExec`;
+ }
}
/**
@@ -240,24 +240,24 @@
*
* @author Anders Johannsen <[EMAIL PROTECTED]>
**/
-
+
function raiseError($strError)
{
- if (!empty($this->arrSetting[CMD_VERBOSE])) {
- echo $strError;
- } else {
- $this->lastError = $strError;
- }
-
- return true;
+ if (!empty($this->arrSetting[CMD_VERBOSE])) {
+ echo $strError;
+ } else {
+ $this->lastError = $strError;
+ }
+
+ return true;
}
-
+
/**
* Functionality similiar to unix 'which'. Searches the path
* for the specified program.
*
- * @param $cmd name of the executable to search for
- *
+ * @param $cmd name of the executable to search for
+ *
* @return string returns the full path if found,
* false if not
*
@@ -265,22 +265,22 @@
*
* @author Anders Johannsen <[EMAIL PROTECTED]>
**/
-
+
function which($cmd)
{
- global $HTTP_ENV_VARS;
-
- $arrPath = explode(":", $HTTP_ENV_VARS['PATH']);
-
- foreach ($arrPath as $path) {
- $location = $path . "/" . $cmd;
-
- if (is_executable($location)) {
- return $location;
- }
- }
- return false;
- }
+ global $HTTP_ENV_VARS;
+
+ $arrPath = explode(":", $HTTP_ENV_VARS['PATH']);
+
+ foreach ($arrPath as $path) {
+ $location = $path . "/" . $cmd;
+
+ if (is_executable($location)) {
+ return $location;
+ }
+ }
+ return false;
+ }
}
-
+
?>
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]