![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/sebastianfeldmann/cli/src/Command/Runner/ |
<?php /** * This file is part of SebastianFeldmann\Cli. * * (c) Sebastian Feldmann <[email protected]> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianFeldmann\Cli\Command\Runner; use RuntimeException; use SebastianFeldmann\Cli\Command; use SebastianFeldmann\Cli\Command\Runner; use SebastianFeldmann\Cli\Command\OutputFormatter; use SebastianFeldmann\Cli\Processor; /** * Class Simple * * @package SebastianFeldmann\Cli * @author Sebastian Feldmann <[email protected]> * @link https://github.com/sebastianfeldmann/cli * @since Class available since Release 0.9.0 */ class Simple implements Runner { /** * Class handling system calls. * * @var \SebastianFeldmann\Cli\Processor */ private $processor; /** * Exec constructor. * * @param \SebastianFeldmann\Cli\Processor $processor */ public function __construct(Processor $processor = null) { $this->processor = $processor !== null ? $processor : new Processor\ProcOpen(); } /** * Execute a cli command. * * @param \SebastianFeldmann\Cli\Command $command * @param \SebastianFeldmann\Cli\Command\OutputFormatter $formatter * @return \SebastianFeldmann\Cli\Command\Runner\Result */ public function run(Command $command, OutputFormatter $formatter = null): Result { $cmd = $this->processor->run($command->getCommand(), $command->getAcceptableExitCodes()); if (!$cmd->isSuccessful()) { throw new RuntimeException( 'Command failed:' . PHP_EOL . ' exit-code: ' . $cmd->getCode() . PHP_EOL . ' message: ' . $cmd->getStdErr() . PHP_EOL, $cmd->getCode() ); } $formatted = $formatter !== null ? $formatter->format($cmd->getStdOutAsArray()) : []; $result = new Result($cmd, $formatted); return $result; } }