Skip to content

ArtARTs36/ShellCommand

Repository files navigation

ShellCommand - wrapper for calls console commands

PHP Composer License: MIT Total Downloads


Installation:

Run: composer require artarts36/shell-command


Examples:

1. Arguments && Options

use ArtARTs36\ShellCommand\ShellCommand;

$command = ShellCommand::make('git')->addArgument('push')->addOption('force');

var_dump($command->__toString()); // git 'push' --force 2>&1

2. Execute Commands

use ArtARTs36\ShellCommand\ShellCommand;

$command = ShellCommand::make('git')->addArgument('pull');
$result = $command->execute();

var_dump($result->getCommandLine());
var_dump($result->getCode());
var_dump($result->getDate());
var_dump($result->getResult());
var_dump($result->getError());

3. SSH

To use ssh, you need to connect the library "artarts36/shell-command-ssh-executor":

Run command artarts36/shell-command-ssh-executor

$connection = \ArtARTs36\ShellCommandSshExecutor\SSH\Connection::withPassword(
    'remote.host',
    'user',
    'password'
);

$command = \ArtARTs36\ShellCommand\ShellCommand::make('ls');

$command->setExecutor(new \ArtARTs36\ShellCommandSshExecutor\SshCommandExecutor($connection));

var_dump($command->getShellResult());

4. Mocking

$executor = new \ArtARTs36\ShellCommand\Executors\TestExecutor();

$command = new \ArtARTs36\ShellCommand\ShellCommand('reboot');

$executor->addSuccess('OK');

$command->execute($executor);