artarts36 / shell-command
OOP ShellCommand
2.1.15
2022-05-17 13:48 UTC
Requires
- php: ^7.3 || 8.*
- ext-mbstring: *
- artarts36/str: *
Requires (Dev)
- artarts36/php-cs-fixer-good-fixers: ^0.1.2
- phpstan/phpstan: ^1.4
- phpunit/phpunit: ^8.0
- squizlabs/php_codesniffer: 3.*
Suggests
This package is auto-updated.
Last update: 2024-09-13 14:14:33 UTC
README
安装
运行: composer require artarts36/shell-command
示例
1. 参数 && 选项
use ArtARTs36\ShellCommand\ShellCommand; $command = ShellCommand::make('git')->addArgument('push')->addOption('force'); var_dump($command->__toString()); // git 'push' --force 2>&1
2. 执行命令
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
要使用ssh,您需要连接到库 "artarts36/shell-command-ssh-executor"
运行命令 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. 模拟
$executor = new \ArtARTs36\ShellCommand\Executors\TestExecutor(); $command = new \ArtARTs36\ShellCommand\ShellCommand('reboot'); $executor->addSuccess('OK'); $command->execute($executor);