mikehaertl\shellcommand\Command::setCommand PHP Метод

setCommand() публичный Метод

public setCommand ( string $command ) : static
$command string the command or full command string to execute, like 'gzip' or 'gzip -d'. You can still call addArg() to add more arguments to the command. If $escapeCommand was set to true, the command gets escaped through escapeshellcmd().
Результат static for method chaining
    public function setCommand($command)
    {
        if ($this->escapeCommand) {
            $command = escapeshellcmd($command);
        }
        if ($this->getIsWindows()) {
            // Make sure to switch to correct drive like "E:" first if we have a full path in command
            $chdrive = isset($command[1]) && $command[1] === ':' ? $command[0] . ': && ' : '';
            $command = sprintf($chdrive . 'cd %s && %s', escapeshellarg(dirname($command)), basename($command));
        }
        $this->_command = $command;
        return $this;
    }

Usage Example

Пример #1
0
 public function testCanAddArguments()
 {
     $command = new Command(array('locale' => 'en_US.UTF-8'));
     $command->setCommand('test');
     $command->setArgs('--arg1=x');
     $command->addArg('--a');
     $command->addArg('--a', '中文字äüp');
     $command->addArg('--a', array("v'1", 'v2', 'v3'));
     $command->addArg('-b=', 'v', false);
     $command->addArg('-b=', array('v4', 'v5', 'v6'));
     $command->addArg('-c', '');
     $command->addArg('some name', null, true);
     $this->assertEquals("--arg1=x --a --a '中文字äüp' --a 'v'\\''1' 'v2' 'v3' -b=v -b='v4' 'v5' 'v6' -c '' 'some name'", $command->getArgs());
     $this->assertEquals("test --arg1=x --a --a '中文字äüp' --a 'v'\\''1' 'v2' 'v3' -b=v -b='v4' 'v5' 'v6' -c '' 'some name'", $command->getExecCommand());
 }
All Usage Examples Of mikehaertl\shellcommand\Command::setCommand