-
-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathErrorOutputBehavior.php
86 lines (77 loc) · 2.84 KB
/
ErrorOutputBehavior.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
83
84
85
86
<?php
declare(strict_types=1);
namespace Psl\Shell;
use Psl\Default\DefaultInterface;
/**
* Specifies the behavior for handling the standard error (stderr) output of shell commands.
*
* This enum is utilized to configure how stderr output should be treated in relation to the
* standard output (stdout) when executing shell commands via the Shell component. Each case
* offers a different strategy for managing or combining stderr and stdout, allowing for flexible
* error output handling based on specific requirements of the execution context.
*/
enum ErrorOutputBehavior implements DefaultInterface
{
/**
* Discard the standard error output.
*
* Example:
*
* $stdout = Shell\execute('cmd', ['arg1', 'arg2'], error_output_behavior: ErrorOutputBehavior::Discard);
*/
case Discard;
/**
* Append the standard error output content to the standard output content.
*
* Example:
*
* $stdout_followed_by_stderr = Shell\execute('cmd', ['arg1', 'arg2'], error_output_behavior: ErrorOutputBehavior::Append);
*/
case Append;
/**
* Prepend the standard error output content to the standard output content.
*
* Example:
*
* $stderr_followed_by_stdout = Shell\execute('cmd', ['arg1', 'arg2'], error_output_behavior: ErrorOutputBehavior::Prepend);
*/
case Prepend;
/**
* Replace the standard output content with the standard error output content.
*
* Example:
*
* $stderr = Shell\execute('cmd', ['arg1', 'arg2'], error_output_behavior: ErrorOutputBehavior::Replace);
*/
case Replace;
/**
* Pack the standard output content with the standard error output content, enabling
* you to split them later on, using `Shell\unpack`.
*
* Example:
*
* $result = Shell\execute('cmd', ['arg1', 'arg2'], error_output_behavior: ErrorOutputBehavior::Packed);
* [$stdout, $stderr] = Shell\unpack($result);
*
* @note The packing format is not guaranteed to be BC, you should always use `Shell\unpack` instead of attempting to unpack the result manually.
*/
case Packed;
/**
* Provides the default error output behavior.
*
* The default behavior is to discard the standard error output. This choice simplifies
* handling of command outputs in scenarios where error details are not crucial, or
* errors are expected and non-critical. It offers a clean approach for focusing solely
* on the standard output content, especially in automated scripts or where output clarity
* is a priority.
*
* @return static The default `Discard` behavior instance, representing the preference to ignore stderr output.
*
* @pure
*/
#[\Override]
public static function default(): static
{
return self::Discard;
}
}