-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExitCode.php
More file actions
71 lines (54 loc) · 1.86 KB
/
ExitCode.php
File metadata and controls
71 lines (54 loc) · 1.86 KB
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
<?php
declare(strict_types=1);
namespace DurableWorkflow\Cli\Support;
/**
* Stable exit codes for the `dw` CLI.
*
* Scripts and CI pipelines rely on these values. Symfony Console's 0/1/2
* remain canonical for success, failure, and usage; dw extends that with
* specific codes for common server-driven outcomes so callers can react
* to auth, not-found, network, and server-side conditions without
* parsing stderr.
*/
final class ExitCode
{
/** Operation completed successfully. */
public const SUCCESS = 0;
/** Generic failure — command ran but did not succeed. */
public const FAILURE = 1;
/** Invalid usage — bad arguments, unknown options, or local validation. */
public const INVALID = 2;
/** Network failure — could not reach the server (connection refused, DNS, TLS, etc.). */
public const NETWORK = 3;
/** Authentication or authorization failure — HTTP 401 or 403. */
public const AUTH = 4;
/** Resource not found — HTTP 404. */
public const NOT_FOUND = 5;
/** Server error — HTTP 5xx or an unexpected server response. */
public const SERVER = 6;
/** Request timed out — the server did not respond within the deadline. */
public const TIMEOUT = 7;
private function __construct() {}
/**
* Map an HTTP status code to its canonical exit code.
*/
public static function fromHttpStatus(int $status): int
{
if ($status === 401 || $status === 403) {
return self::AUTH;
}
if ($status === 404) {
return self::NOT_FOUND;
}
if ($status === 408) {
return self::TIMEOUT;
}
if ($status >= 500 && $status <= 599) {
return self::SERVER;
}
if ($status >= 400 && $status <= 499) {
return self::INVALID;
}
return self::FAILURE;
}
}