-
Notifications
You must be signed in to change notification settings - Fork 611
/
ShellCommandException.php
82 lines (70 loc) · 2.11 KB
/
ShellCommandException.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
/**
* @link https://craftcms.com/
* @copyright Copyright (c) Pixel & Tonic, Inc.
* @license https://craftcms.github.io/license/
*/
namespace craft\errors;
use mikehaertl\shellcommand\Command;
use yii\base\Exception;
/**
* ShellCommandException represents an exception caused by setting an invalid license key on a plugin.
*
* @author Pixel & Tonic, Inc. <support@pixelandtonic.com>
* @since 3.0.0
*/
final class ShellCommandException extends Exception
{
/**
* @var string The command that was executed
*/
public string $command;
/**
* @var int The command’s exit code
*/
public int $exitCode;
/**
* @var string|null The command’s error output
*/
public ?string $error = null;
/**
* Creates a ShellCommandException from a [[Command]] object
*
* @param Command $command The failed Command object
* @return static|false
*/
public static function createFromCommand(Command $command): self|false
{
$execCommand = $command->getExecCommand();
if ($execCommand === false) {
return false;
}
return new self($execCommand, $command->getExitCode(), $command->getStdErr());
}
/**
* Constructor.
*
* @param string $command The command that was executed
* @param int $exitCode The command’s exit code
* @param string|null $error The command’s error output
* @param string|null $message The error message
* @param int $code The error code
*/
public function __construct(string $command, int $exitCode, ?string $error = null, ?string $message = null, int $code = 0)
{
$this->command = $command;
$this->exitCode = $exitCode;
$this->error = $error;
if ($message === null) {
$message = "The shell command \"$command\" failed with exit code $exitCode" . ($error ? ": $error" : '.');
}
parent::__construct($message, $code);
}
/**
* @return string the user-friendly name of this exception
*/
public function getName(): string
{
return 'Shell Command Failure';
}
}