Clinner\Command\Command::fromString PHP Метод

fromString() публичный статический Метод

For example: $command = Command::fromString('cat /etc/hosts | grep localhost'); Is roughly equivalent to: $command = Command::create('cat', array('/etc/hosts')) ->pipe(Command::create('grep', array('localhost')));
public static fromString ( string $commandString ) : Clinner\Command\CommandInterface
$commandString string The command string to parse.
Результат Clinner\Command\CommandInterface
    public static function fromString($commandString)
    {
        $splitCommands = array_map(function ($str) {
            return trim($str);
        }, explode(self::PIPE, $commandString));
        $command = new NullCommand();
        foreach ($splitCommands as $rawCommand) {
            $command = $command->pipe(static::parse($rawCommand));
        }
        return $command;
    }

Usage Example

Пример #1
0
 /**
  * @covers \Clinner\Command\Command::fromString
  * @covers \Clinner\Command\Command::parse
  */
 public function testStaticFromStringManyCommands()
 {
     $commandString = 'cat ~/test.html | tr -s " " | cut -d: -f2 | wc';
     $commandsCount = 4;
     $command = Command::fromString($commandString);
     $this->assertInstanceOf('\\Clinner\\Command\\Command', $command);
     // Test that the inverse function also works
     $this->assertEquals($commandString, $command->toCommandString(true));
     $count = 0;
     while (null !== $command) {
         $count++;
         $command = $command->getPipedCommand();
     }
     $this->assertEquals($commandsCount, $count);
 }
All Usage Examples Of Clinner\Command\Command::fromString