Skip to content

Commit 4af4111

Browse files
committed
Initial Signal Handler version
0 parents  commit 4af4111

37 files changed

+3531
-0
lines changed

.editorconfig

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# This file is for unifying the coding style for different editors and IDEs
2+
# editorconfig.org
3+
4+
root = true
5+
6+
[*]
7+
end_of_line = lf
8+
charset = utf-8
9+
indent_style = space
10+
indent_size = 4
11+
insert_final_newline = true
12+
trim_trailing_whitespace = true
13+
14+
[*.yml]
15+
indent_size = 2
16+
17+
[phars.xml]
18+
indent_size = 2
19+
20+
[*.neon]
21+
indent_style = tab

.gitattributes

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Define the line ending behavior of the different file extensions
2+
# Set default behaviour, in case users don't have core.autocrlf set.
3+
* text=auto
4+
* text eol=lf
5+
6+
# Explicitly declare text files we want to always be normalized and converted
7+
# to native line endings on checkout.
8+
*.php text
9+
*.default text
10+
*.ctp text
11+
*.md text
12+
*.po text
13+
*.js text
14+
*.css text
15+
*.ini text
16+
*.txt text
17+
*.xml text
18+
19+
# Declare files that will always have CRLF line endings on checkout.
20+
*.bat eol=crlf
21+
22+
# Declare files that will always have LF line endings on checkout.
23+
*.pem eol=lf
24+
25+
# Denote all files that are truly binary and should not be modified.
26+
*.png binary
27+
*.jpg binary
28+
*.gif binary
29+
*.ico binary
30+
*.mo binary
31+
32+
# Remove files for archives generated using `git archive`
33+
.editorconfig export-ignore
34+
.gitattributes export-ignore
35+
.gitignore export-ignore
36+
.stickler.yml export-ignore
37+
.travis.yml export-ignore
38+
CONTRIBUTING.md export-ignore
39+
Dockerfile export-ignore
40+
docs.Dockerfile export-ignore
41+
phpcs.xml.dist export-ignore
42+
phpstan.neon export-ignore
43+
phpunit.xml.dist export-ignore
44+
psalm.xml export-ignore
45+
/.github export-ignore
46+
/tests export-ignore
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: '[BUG] '
5+
labels: ['bug']
6+
assignees: ''
7+
---
8+
9+
**Describe the bug**
10+
A clear and concise description of what the bug is.
11+
12+
**To Reproduce**
13+
Steps to reproduce the behavior:
14+
1. Create command with '...'
15+
2. Use signal handling '....'
16+
3. Send signal '....'
17+
4. See error
18+
19+
**Expected behavior**
20+
A clear and concise description of what you expected to happen.
21+
22+
**Actual behavior**
23+
A clear and concise description of what actually happened.
24+
25+
**Environment:**
26+
- OS: [e.g. Ubuntu 22.04, Windows 11, macOS 14]
27+
- PHP Version: [e.g. 8.2.0]
28+
- CakePHP Version: [e.g. 5.0.0]
29+
- SignalHandler Version: [e.g. 1.0.0]
30+
31+
**Code Example**
32+
```php
33+
34+
```
35+
36+
**Additional context**
37+
Add any other context about the problem here, such as error messages, stack traces, or relevant configuration.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: '[FEATURE] '
5+
labels: ['enhancement']
6+
assignees: ''
7+
---
8+
9+
**Is your feature request related to a problem? Please describe.**
10+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
11+
12+
**Describe the solution you'd like**
13+
A clear and concise description of what you want to happen.
14+
15+
**Describe alternatives you've considered**
16+
A clear and concise description of any alternative solutions or features you've considered.
17+
18+
**Additional context**
19+
Add any other context or screenshots about the feature request here.
20+
21+
**Example Usage**
22+
If applicable, show how you would like to use the new feature:
23+
24+
```php
25+
26+
```

.github/pull_request_template.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
## Description
2+
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context.
3+
4+
## Type of change
5+
Please delete options that are not relevant.
6+
7+
- [ ] Bug fix (non-breaking change which fixes an issue)
8+
- [ ] New feature (non-breaking change which adds functionality)
9+
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
10+
- [ ] Documentation update
11+
- [ ] Code refactoring
12+

.github/workflows/ci.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
branches:
7+
- '*'
8+
9+
jobs:
10+
testsuite:
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
php-version: ['8.1', '8.2', '8.3', '8.4']
16+
os: [ubuntu-latest, windows-latest]
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Setup PHP
21+
uses: shivammathur/setup-php@v2
22+
with:
23+
php-version: ${{ matrix.php-version }}
24+
extensions: mbstring, intl
25+
coverage: pcov
26+
27+
- name: Cache composer dependencies
28+
uses: actions/cache@v4
29+
with:
30+
path: ~/.composer/cache
31+
key: ${{ runner.os }}-composer-${{ hashFiles('composer.json') }}
32+
33+
- name: composer install
34+
run: composer install --prefer-dist --no-progress
35+
36+
- name: Setup problem matchers for PHPUnit
37+
if: matrix.php-version == '8.2' && matrix.os == 'ubuntu-latest'
38+
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
39+
40+
- name: Run PHPUnit with coverage
41+
if: matrix.php-version == '8.2' && matrix.os == 'ubuntu-latest'
42+
run: |
43+
export CODECOVERAGE=1
44+
vendor/bin/phpunit --display-deprecations --display-incomplete --display-skipped --coverage-clover=coverage.xml
45+
46+
- name: Run PHPUnit without coverage
47+
if: matrix.php-version != '8.2' || matrix.os != 'ubuntu-latest'
48+
run: vendor/bin/phpunit
49+
50+
- name: Submit code coverage
51+
if: matrix.php-version == '8.2' && matrix.os == 'ubuntu-latest'
52+
uses: codecov/codecov-action@v3
53+
54+
cs-stan:
55+
name: Coding Standard & Static Analysis
56+
runs-on: ubuntu-latest
57+
58+
steps:
59+
- uses: actions/checkout@v4
60+
61+
- name: Setup PHP
62+
uses: shivammathur/setup-php@v2
63+
with:
64+
php-version: '8.2'
65+
extensions: mbstring, intl
66+
coverage: none
67+
68+
- name: Cache composer dependencies
69+
uses: actions/cache@v4
70+
with:
71+
path: ~/.composer/cache
72+
key: ${{ runner.os }}-composer-${{ hashFiles('composer.json') }}
73+
74+
- name: composer install
75+
run: composer install --prefer-dist --no-progress
76+
77+
- name: Setup PHPStan
78+
run: composer stan-setup
79+
80+
- name: Run PHP CodeSniffer
81+
run: composer cs-check
82+
83+
- name: Run phpstan
84+
run: composer stan

.gitignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# User specific & automatically generated files #
2+
#################################################
3+
/build
4+
/dist
5+
/tags
6+
/composer.lock
7+
/phpunit.xml
8+
/phpcs.xml
9+
/tools
10+
/vendor
11+
*.mo
12+
debug.log
13+
error.log
14+
/tests/test_app/config/Create/*
15+
/tests/test_app/config/Queue/*
16+
/tests/test_app/config/TestsQueue/schema-dump-test.lock
17+
/tests/test_app/Plugin/TestBlog/config/Queue/*
18+
.phpunit.cache
19+
20+
# IDE and editor specific files #
21+
#################################
22+
/nbproject
23+
.idea
24+
25+
# OS generated files #
26+
######################
27+
.DS_Store
28+
.DS_Store?
29+
._*
30+
.Spotlight-V100
31+
.Trashes
32+
Icon?
33+
ehthumbs.db
34+
Thumbs.db

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Evgeny Tomenko
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# SignalHandler Plugin
2+
3+
The **SignalHandler** plugin provides cross-platform signal handling for CakePHP console commands with the following features:
4+
5+
* Cross-platform signal handling (Linux, Windows, macOS)
6+
* Graceful command termination with Ctrl+C and other signals
7+
* Zero external dependencies - pure CakePHP implementation
8+
* CakePHP event system integration
9+
* Automatic signal handler registration and cleanup
10+
* Support for long-running commands and infinite loops
11+
* React event loop integration support
12+
13+
The plugin is designed to provide signal handling capabilities following 2 approaches:
14+
15+
* Quick drop-in solution for existing commands. Add signal handling in minutes.
16+
* Extensible solution for custom signal handling. You can extend:
17+
* SignalableCommandInterface for custom signal handling
18+
* SignalHandlerTrait for callback based signal handling
19+
* Custom signal event listeners
20+
* Platform-specific signal handlers
21+
22+
The plugin integrates seamlessly with CakePHP's console system and maintains zero external dependencies.
23+
24+
## Requirements
25+
26+
* CakePHP 5.0+
27+
* PHP 8.4+
28+
29+
## Documentation
30+
31+
For documentation, as well as tutorials, see the [Docs](docs/Home.md) directory of this repository.
32+
33+
## License
34+
35+
Licensed under the [MIT](http://www.opensource.org/licenses/mit-license.php) License. Redistributions of the source code included in this repository must retain the copyright notice found in each file.

composer.json

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"name": "skie/signal_handler",
3+
"description": "Cross-platform signal handling for CakePHP console commands with zero external dependencies. Supports Linux (pcntl), Windows (native API)",
4+
"type": "cakephp-plugin",
5+
"license": "MIT",
6+
"keywords": [
7+
"cakephp",
8+
"plugin",
9+
"signal",
10+
"console",
11+
"command",
12+
"pcntl",
13+
"windows",
14+
"cross-platform"
15+
],
16+
"homepage": "https://github.com/skie/SignalHandler",
17+
"support": {
18+
"issues": "https://github.com/skie/SignalHandler/issues",
19+
"source": "https://github.com/skie/SignalHandler"
20+
},
21+
"authors": [
22+
{
23+
"name": "Evgeny Tomenko",
24+
"homepage": "https://github.com/skie"
25+
}
26+
],
27+
"require": {
28+
"php": ">=8.1",
29+
"cakephp/cakephp": "^5.0"
30+
},
31+
"require-dev": {
32+
"phpunit/phpunit": "^10.0",
33+
"cakephp/cakephp-codesniffer": "^5.0"
34+
},
35+
"autoload": {
36+
"psr-4": {
37+
"SignalHandler\\": "src/"
38+
}
39+
},
40+
"autoload-dev": {
41+
"psr-4": {
42+
"SignalHandler\\Test\\": "tests/"
43+
}
44+
},
45+
"scripts": {
46+
"check": [
47+
"@cs-check",
48+
"@test"
49+
],
50+
"cs-check": "phpcs -p --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/",
51+
"cs-fix": "phpcbf --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/",
52+
"test": "phpunit",
53+
"test:coverage": "phpunit --coverage-html coverage",
54+
"stan": "phpstan analyse src/ tests/",
55+
"stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:^2.0 && mv composer.backup composer.json",
56+
"stan-rebuild-baseline": "phpstan analyse --configuration phpstan.neon --error-format baselineNeon src/ > phpstan-baseline.neon"
57+
},
58+
"extra": {
59+
"installer-name": "SignalHandler"
60+
},
61+
"config": {
62+
"allow-plugins": {
63+
"dealerdirect/phpcodesniffer-composer-installer": true
64+
}
65+
}
66+
}

0 commit comments

Comments
 (0)