Skip to content

Commit

Permalink
fix #828: Assignment to $this (patch by Marcus Taker and Philippe Jau…
Browse files Browse the repository at this point in the history
…sions)

git-svn-id: http://svn.php.net/repository/pear/packages/System_Command/trunk@194823 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information
Arnaud Limbourg committed Sep 1, 2005
1 parent 49d5c39 commit 91c6758
Showing 1 changed file with 28 additions and 21 deletions.
49 changes: 28 additions & 21 deletions Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
*/

// }}}
class System_Command extends PEAR {
class System_Command {
// {{{ properties

/**
Expand Down Expand Up @@ -118,6 +118,14 @@ class System_Command extends PEAR {
* @access private
*/
var $commandStatus = 0;

/**
* Hold initialization PEAR_Error
*
* @var object
* @access private
**/
var $_initError = null;

// }}}
// {{{ constructor
Expand All @@ -131,8 +139,6 @@ class System_Command extends PEAR {
*/
function System_Command($in_shell = null)
{
parent::PEAR();

// Defining constants
$this->options = array(
'SEQUENCE' => true,
Expand Down Expand Up @@ -176,15 +182,15 @@ function System_Command($in_shell = null)

// see if we still have no shell
if (empty($this->options['SHELL'])) {
$this = PEAR::raiseError(null, SYSTEM_COMMAND_NO_SHELL, null, E_USER_WARNING, null, 'System_Command_Error', true);
$this->_initError =& PEAR::raiseError(null, SYSTEM_COMMAND_NO_SHELL, null, E_USER_WARNING, null, 'System_Command_Error', true);
return;
}
}

// Caputre a temporary directory for capturing stderr from commands
$this->tmpdir = System::tmpdir();
if (!System::mkDir("-p {$this->tmpdir}")) {
$this = PEAR::raiseError(null, SYSTEM_COMMAND_TMPDIR_ERROR, null, E_USER_WARNING, null, 'System_Command_Error', true);
$this->_initError =& PEAR::raiseError(null, SYSTEM_COMMAND_TMPDIR_ERROR, null, E_USER_WARNING, null, 'System_Command_Error', true);
return;
}
}
Expand Down Expand Up @@ -212,6 +218,10 @@ function System_Command($in_shell = null)
*/
function setOption($in_option, $in_setting)
{
if ($this->_initError) {
return $this->_initError;
}

$option = strtoupper($in_option);

if (empty($this->options[$option])) {
Expand Down Expand Up @@ -270,6 +280,10 @@ function setOption($in_option, $in_setting)
*/
function pushCommand($in_command)
{
if ($this->_initError) {
return $this->_initError;
}

if (!is_null($this->previousElement) && !in_array($this->previousElement, $this->controlOperators)) {
$this->commandStatus = -1;
$error = PEAR::raiseError(null, SYSTEM_COMMAND_COMMAND_PLACEMENT, null, E_USER_WARNING, null, 'System_Command_Error', true);
Expand Down Expand Up @@ -311,6 +325,10 @@ function pushCommand($in_command)
*/
function pushOperator($in_operator)
{
if ($this->_initError) {
return $this->_initError;
}

$operator = isset($this->controlOperators[$in_operator]) ? $this->controlOperators[$in_operator] : $in_operator;

if (is_null($this->previousElement) || in_array($this->previousElement, $this->controlOperators)) {
Expand Down Expand Up @@ -339,6 +357,10 @@ function pushOperator($in_operator)
*/
function execute()
{
if ($this->_initError) {
return $this->_initError;
}

// if the command is empty or if the last element was a control operator, we can't continue
if (is_null($this->previousElement) || $this->commandStatus == -1 || in_array($this->previousElement, $this->controlOperators)) {
return PEAR::raiseError(null, SYSTEM_COMMAND_INVALID_COMMAND, null, E_USER_WARNING, $this->systemCommand, 'System_Command_Error', true);
Expand Down Expand Up @@ -407,22 +429,7 @@ function execute()
*/
function which($in_cmd)
{
// if we already have a binary, then return it
if (is_executable($in_cmd)) {
return $in_cmd;
}

$paths = explode(':', $_ENV['PATH']);

foreach ($paths as $path) {
$location = $path . '/' . $in_cmd;

if (is_executable($location)) {
return $location;
}
}

return false;
return System::which($in_cmd);
}

// }}}
Expand Down

0 comments on commit 91c6758

Please sign in to comment.