2424trait SignalTrait
2525{
2626 /**
27- * Whether the process should continue running (false = termination requested)
27+ * Whether the process should continue running (false = termination requested).
2828 */
2929 private bool $ running = true ;
3030
3131 /**
32- * Whether signals are currently blocked
32+ * Whether signals are currently blocked.
3333 */
3434 private bool $ signalsBlocked = false ;
3535
3636 /**
37- * Array of registered signals
37+ * Array of registered signals.
3838 *
3939 * @var list<int>
4040 */
4141 private array $ registeredSignals = [];
4242
4343 /**
44- * Signal-to-method mapping
44+ * Signal-to-method mapping.
4545 *
4646 * @var array<int, string>
4747 */
4848 private array $ signalMethodMap = [];
4949
5050 /**
51- * Cached result of PCNTL extension availability
51+ * Cached result of PCNTL extension availability.
5252 */
5353 private static ?bool $ isPcntlAvailable = null ;
5454
5555 /**
56- * Cached result of POSIX extension availability
56+ * Cached result of POSIX extension availability.
5757 */
5858 private static ?bool $ isPosixAvailable = null ;
5959
6060 /**
61- * Check if PCNTL extension is available (cached)
61+ * Check if PCNTL extension is available (cached).
6262 */
6363 protected function isPcntlAvailable (): bool
6464 {
@@ -77,7 +77,7 @@ protected function isPcntlAvailable(): bool
7777 }
7878
7979 /**
80- * Check if POSIX extension is available (cached)
80+ * Check if POSIX extension is available (cached).
8181 */
8282 protected function isPosixAvailable (): bool
8383 {
@@ -89,7 +89,7 @@ protected function isPosixAvailable(): bool
8989 }
9090
9191 /**
92- * Register signal handlers
92+ * Register signal handlers.
9393 *
9494 * @param list<int> $signals List of signals to handle
9595 * @param array<int, string> $methodMap Optional signal-to-method mapping
@@ -129,7 +129,7 @@ protected function registerSignals(
129129 }
130130
131131 /**
132- * Handle incoming signals
132+ * Handle incoming signals.
133133 */
134134 protected function handleSignal (int $ signal ): void
135135 {
@@ -158,8 +158,8 @@ protected function handleSignal(int $signal): void
158158 }
159159
160160 /**
161- * Call custom signal handler if one is mapped for this signal
162- * Falls back to generic onInterruption() method if no explicit mapping exists
161+ * Call custom signal handler if one is mapped for this signal.
162+ * Falls back to generic onInterruption() method if no explicit mapping exists.
163163 */
164164 private function callCustomHandler (int $ signal ): void
165165 {
@@ -179,31 +179,31 @@ private function callCustomHandler(int $signal): void
179179 }
180180
181181 /**
182- * Check if command should terminate
182+ * Check if command should terminate.
183183 */
184184 protected function shouldTerminate (): bool
185185 {
186186 return ! $ this ->running ;
187187 }
188188
189189 /**
190- * Check if the process is currently running (not terminated)
190+ * Check if the process is currently running (not terminated).
191191 */
192192 protected function isRunning (): bool
193193 {
194194 return $ this ->running ;
195195 }
196196
197197 /**
198- * Request immediate termination
198+ * Request immediate termination.
199199 */
200200 protected function requestTermination (): void
201201 {
202202 $ this ->running = false ;
203203 }
204204
205205 /**
206- * Reset all states (for testing or restart scenarios)
206+ * Reset all states (for testing or restart scenarios).
207207 */
208208 protected function resetState (): void
209209 {
@@ -216,7 +216,7 @@ protected function resetState(): void
216216 }
217217
218218 /**
219- * Execute a callable with ALL signals blocked to prevent ANY interruption during critical operations
219+ * Execute a callable with ALL signals blocked to prevent ANY interruption during critical operations.
220220 *
221221 * This blocks ALL interruptible signals including:
222222 * - Termination signals (SIGTERM, SIGINT, etc.)
@@ -244,8 +244,8 @@ protected function withSignalsBlocked(Closure $operation)
244244 }
245245
246246 /**
247- * Block ALL interruptible signals during critical sections
248- * Only SIGKILL (unblockable) can terminate the process
247+ * Block ALL interruptible signals during critical sections.
248+ * Only SIGKILL (unblockable) can terminate the process.
249249 */
250250 protected function blockSignals (): void
251251 {
@@ -262,7 +262,7 @@ protected function blockSignals(): void
262262 }
263263
264264 /**
265- * Unblock previously blocked signals
265+ * Unblock previously blocked signals.
266266 */
267267 protected function unblockSignals (): void
268268 {
@@ -279,23 +279,23 @@ protected function unblockSignals(): void
279279 }
280280
281281 /**
282- * Check if signals are currently blocked
282+ * Check if signals are currently blocked.
283283 */
284284 protected function signalsBlocked (): bool
285285 {
286286 return $ this ->signalsBlocked ;
287287 }
288288
289289 /**
290- * Add or update signal-to-method mapping at runtime
290+ * Add or update signal-to-method mapping at runtime.
291291 */
292292 protected function mapSignal (int $ signal , string $ method ): void
293293 {
294294 $ this ->signalMethodMap [$ signal ] = $ method ;
295295 }
296296
297297 /**
298- * Get human-readable signal name
298+ * Get human-readable signal name.
299299 */
300300 protected function getSignalName (int $ signal ): string
301301 {
@@ -315,7 +315,7 @@ protected function getSignalName(int $signal): string
315315 }
316316
317317 /**
318- * Unregister all signals (cleanup)
318+ * Unregister all signals (cleanup).
319319 */
320320 protected function unregisterSignals (): void
321321 {
@@ -332,15 +332,15 @@ protected function unregisterSignals(): void
332332 }
333333
334334 /**
335- * Check if signals are registered
335+ * Check if signals are registered.
336336 */
337337 protected function hasSignals (): bool
338338 {
339339 return $ this ->registeredSignals !== [];
340340 }
341341
342342 /**
343- * Get list of registered signals
343+ * Get list of registered signals.
344344 *
345345 * @return list<int>
346346 */
@@ -350,7 +350,7 @@ protected function getSignals(): array
350350 }
351351
352352 /**
353- * Get comprehensive process state information
353+ * Get comprehensive process state information.
354354 *
355355 * @return array<string, mixed>
356356 */
0 commit comments