public function pipe(PipeableCommandInterface $anotherCommand, $appendToPipe = true)
{
if (!$anotherCommand instanceof NullCommand) {
if ($this === $anotherCommand) {
// Cannot pipe a command to itself, need to clone it
$anotherCommand = clone $anotherCommand;
}
if ($appendToPipe) {
if ($this->hasPipedCommand()) {
$this->_next->pipe($anotherCommand, true);
} else {
$this->_next = $anotherCommand;
}
} else {
if ($this->hasPipedCommand()) {
// Rearrange the commands pipe
$anotherCommand->pipe($this->_next, false);
}
$this->_next = $anotherCommand;
}
}
return $this;
}