Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| Signal | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
| exitStatus | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** |
| 6 | * This file is part of fast-forward/fork. |
| 7 | * |
| 8 | * This source file is subject to the license bundled |
| 9 | * with this source code in the file LICENSE. |
| 10 | * |
| 11 | * @copyright Copyright (c) 2026 Felipe Sayão Lobato Abreu <github@mentordosnerds.com> |
| 12 | * @license https://opensource.org/licenses/MIT MIT License |
| 13 | * |
| 14 | * @see https://github.com/php-fast-forward/fork |
| 15 | * @see https://github.com/php-fast-forward |
| 16 | * @see https://datatracker.ietf.org/doc/html/rfc2119 |
| 17 | */ |
| 18 | |
| 19 | namespace FastForward\Fork\Signal; |
| 20 | |
| 21 | /** |
| 22 | * Represents supported POSIX signals exposed by the public API. |
| 23 | * |
| 24 | * This enumeration provides a strongly-typed abstraction over common POSIX |
| 25 | * signals used for process control and inter-process communication. |
| 26 | * |
| 27 | * Each case MUST map directly to its corresponding POSIX signal number. |
| 28 | * Consumers MAY use this enum to improve readability and type safety when |
| 29 | * sending or handling signals. |
| 30 | * |
| 31 | * Implementations interacting with system-level process control SHOULD rely on |
| 32 | * these values to ensure consistency across environments. |
| 33 | */ |
| 34 | enum Signal: int |
| 35 | { |
| 36 | /** |
| 37 | * Terminal line hangup signal (SIGHUP). |
| 38 | * |
| 39 | * This signal is typically sent when a controlling terminal is closed. |
| 40 | */ |
| 41 | case Hangup = \SIGHUP; |
| 42 | |
| 43 | /** |
| 44 | * Interactive interrupt signal (SIGINT). |
| 45 | * |
| 46 | * This signal is usually triggered by user interaction (e.g., Ctrl+C). |
| 47 | */ |
| 48 | case Interrupt = \SIGINT; |
| 49 | |
| 50 | /** |
| 51 | * Interactive quit signal (SIGQUIT). |
| 52 | * |
| 53 | * This signal MAY trigger a core dump depending on the environment. |
| 54 | */ |
| 55 | case Quit = \SIGQUIT; |
| 56 | |
| 57 | /** |
| 58 | * Uncatchable termination signal (SIGKILL). |
| 59 | * |
| 60 | * This signal MUST NOT be caught, blocked, or ignored by the process. |
| 61 | */ |
| 62 | case Kill = \SIGKILL; |
| 63 | |
| 64 | /** |
| 65 | * User-defined application signal 1 (SIGUSR1). |
| 66 | * |
| 67 | * This signal MAY be used for custom application-level communication. |
| 68 | */ |
| 69 | case User1 = \SIGUSR1; |
| 70 | |
| 71 | /** |
| 72 | * User-defined application signal 2 (SIGUSR2). |
| 73 | * |
| 74 | * This signal MAY be used for custom application-level communication. |
| 75 | */ |
| 76 | case User2 = \SIGUSR2; |
| 77 | |
| 78 | /** |
| 79 | * Broken pipe signal (SIGPIPE). |
| 80 | * |
| 81 | * This signal is raised when writing to a pipe with no readers. |
| 82 | */ |
| 83 | case Pipe = \SIGPIPE; |
| 84 | |
| 85 | /** |
| 86 | * Alarm clock signal (SIGALRM). |
| 87 | * |
| 88 | * This signal is typically used for timer-based interruptions. |
| 89 | */ |
| 90 | case Alarm = \SIGALRM; |
| 91 | |
| 92 | /** |
| 93 | * Graceful termination signal (SIGTERM). |
| 94 | * |
| 95 | * This signal SHOULD be used to request a controlled shutdown. |
| 96 | */ |
| 97 | case Terminate = \SIGTERM; |
| 98 | |
| 99 | /** |
| 100 | * Child status changed signal (SIGCHLD). |
| 101 | * |
| 102 | * This signal is sent to a parent process when a child process changes state. |
| 103 | */ |
| 104 | case Child = \SIGCHLD; |
| 105 | |
| 106 | /** |
| 107 | * Continue-if-stopped signal (SIGCONT). |
| 108 | * |
| 109 | * This signal resumes a previously stopped process. |
| 110 | */ |
| 111 | case Continue = \SIGCONT; |
| 112 | |
| 113 | /** |
| 114 | * Process stop signal (SIGSTOP). |
| 115 | * |
| 116 | * This signal MUST stop the process and MUST NOT be caught or ignored. |
| 117 | */ |
| 118 | case Stop = \SIGSTOP; |
| 119 | |
| 120 | /** |
| 121 | * Terminal stop signal (SIGTSTP). |
| 122 | * |
| 123 | * This signal is typically triggered by user interaction (e.g., Ctrl+Z). |
| 124 | */ |
| 125 | case TerminalStop = \SIGTSTP; |
| 126 | |
| 127 | /** |
| 128 | * Returns the conventional shell exit status derived from this signal. |
| 129 | * |
| 130 | * According to POSIX conventions, when a process is terminated by a signal, |
| 131 | * the exit status SHOULD be reported as 128 plus the signal number. |
| 132 | * |
| 133 | * @return int the computed exit status |
| 134 | */ |
| 135 | public function exitStatus(): int |
| 136 | { |
| 137 | return 128 + $this->value; |
| 138 | } |
| 139 | } |