feat(runner): add signal handling support (SIGINT/SIGTERM)#52
Merged
Conversation
- Add SignalHandler class with register/remove/enable/disable API - Add enableSignalHandling() and setSignalHandler() to Runner - Add onSignal() per-command cleanup registration to Command - Default SIGINT: exits with code 130 (interactive: interrupts command only) - Default SIGTERM: sets shutdown flag, exits with code 143 - Graceful degradation on Windows (no-op when pcntl unavailable) - Interactive mode loop respects shutdown flag for clean exit - Per-command handlers auto-removed after command finishes Closes #45
52e04bc to
5b68bfe
Compare
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #52 +/- ##
============================================
+ Coverage 87.72% 87.97% +0.24%
+ Complexity 1322 1284 -38
============================================
Files 33 34 +1
Lines 3610 3693 +83
============================================
+ Hits 3167 3249 +82
- Misses 443 444 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Adds signal handling support (SIGINT/SIGTERM) to the CLI library, enabling graceful shutdown and per-command cleanup registration.
Motivation
When a CLI application receives OS signals, PHP terminates immediately with no cleanup opportunity. This is problematic for commands holding locks, temp files, or DB transactions, and for interactive mode running in containers. Closes #45.
Changes
SignalHandlerclass withregister(),remove(),enable(),disable(),isSupported()APIenableSignalHandling(),setSignalHandler(),getSignalHandler(),isShutdownRequested()toRunneronSignal(),getSignalHandlers(),clearSignalHandlers()toCommandHow to Test / Verify
Unit and integration tests with 100% line coverage on all new code:
tests/WebFiori/Tests/Cli/SignalHandlerTest.php(13 tests)tests/WebFiori/Tests/Cli/SignalIntegrationTest.php(22 tests)Run:
composer testBreaking Changes and Migration Steps
None. All new functionality is opt-in via
enableSignalHandling().Checklist
composer fix-cs)Related issues
Closes #45