Skip to content

Commit 9b95463

Browse files
feat: initial release of codemonster-ru/support with global helpers
0 parents  commit 9b95463

27 files changed

Lines changed: 789 additions & 0 deletions

.github/workflows/release.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*'
7+
workflow_dispatch:
8+
9+
jobs:
10+
release:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: write
14+
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
19+
- name: Set up PHP
20+
uses: shivammathur/setup-php@v2
21+
with:
22+
php-version: '8.2'
23+
coverage: none
24+
tools: composer
25+
26+
- name: Install dependencies
27+
run: composer install --no-progress --no-suggest --prefer-dist
28+
29+
- name: Run tests
30+
run: vendor/bin/phpunit --testdox
31+
32+
- name: Extract changelog entry
33+
run: |
34+
RAW_VERSION=${GITHUB_REF_NAME#v}
35+
36+
if [[ "$RAW_VERSION" == *"-test" ]]; then
37+
VERSION=${RAW_VERSION%-test}
38+
else
39+
VERSION=$RAW_VERSION
40+
fi
41+
42+
echo "Looking for version: $VERSION (from tag $RAW_VERSION)"
43+
44+
awk "/^## \\[$VERSION\\]/ {flag=1; next} /^## \\[/ {flag=0} flag {print}" CHANGELOG.md > RELEASE_NOTES.md
45+
46+
if [ ! -s RELEASE_NOTES.md ]; then
47+
echo "⚠️ No changelog entry found, using default message"
48+
echo "Release $RAW_VERSION" > RELEASE_NOTES.md
49+
fi
50+
51+
echo "---- RELEASE NOTES ----"
52+
cat RELEASE_NOTES.md
53+
54+
- name: Create GitHub Release
55+
uses: softprops/action-gh-release@v2
56+
with:
57+
tag_name: ${{ github.ref_name }}
58+
name: Release ${{ github.ref_name }}
59+
body_path: RELEASE_NOTES.md
60+
env:
61+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/tests.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
8+
jobs:
9+
tests:
10+
runs-on: ubuntu-latest
11+
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
php: [8.2, 8.3, 8.4]
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
21+
- name: Setup PHP
22+
uses: shivammathur/setup-php@v2
23+
with:
24+
php-version: ${{ matrix.php }}
25+
coverage: none
26+
tools: composer:v2
27+
28+
- name: Validate composer.json
29+
run: composer validate --strict
30+
31+
- name: Install dependencies
32+
run: composer update --prefer-dist --no-progress --no-interaction
33+
34+
- name: Run tests
35+
run: composer test

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.idea
2+
.vscode
3+
vendor
4+
.phpunit.result.cache
5+
composer.lock
6+
composer.local.json
7+
composer.local.lock
8+
phpunit.xml

.prettierrc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"semi": true,
3+
"singleQuote": true,
4+
"tabWidth": 4,
5+
"printWidth": 120,
6+
"bracketSpacing": true,
7+
"trailingComma": "all",
8+
"arrowParens": "avoid",
9+
"endOfLine": "lf",
10+
"insertFinalNewLine": false
11+
}

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Changelog
2+
3+
All significant changes to this project will be documented in this file.
4+
5+
## [1.0.0] – 2025-10-28
6+
7+
### Added
8+
9+
- Global helper functions for the entire **Codemonster PHP ecosystem**:
10+
- `config()` — access or modify configuration values
11+
- `env()` — read environment variables
12+
- `dump()`, `dd()` — elegant variable dumping
13+
- `request()` — get current HTTP request or input
14+
- `response()`, `json()` — send structured responses
15+
- `router()` / `route()` — define and access routes
16+
- `session()` — read or write session data
17+
- `view()` / `render()` — render templates and return responses
18+
- Seamless integration with the **Annabel** framework via `app()` container
19+
- Standalone compatibility when Annabel is not installed
20+
- Full PHPUnit test coverage for all helpers (18 tests / 25 assertions)
21+
- Support for **PHP 8.2 – 8.4** and PHPUnit **9–12**

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-present Kirill Kolesnikov
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: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# codemonster-ru/support
2+
3+
[![Latest Version on Packagist](https://img.shields.io/packagist/v/codemonster-ru/support.svg?style=flat-square)](https://packagist.org/packages/codemonster-ru/support)
4+
[![Total Downloads](https://img.shields.io/packagist/dt/codemonster-ru/support.svg?style=flat-square)](https://packagist.org/packages/codemonster-ru/support)
5+
[![License](https://img.shields.io/packagist/l/codemonster-ru/support.svg?style=flat-square)](https://packagist.org/packages/codemonster-ru/support)
6+
[![Tests](https://github.com/codemonster-ru/support/actions/workflows/tests.yml/badge.svg)](https://github.com/codemonster-ru/support/actions/workflows/tests.yml)
7+
8+
Global helper functions for the **Codemonster PHP ecosystem**.
9+
10+
## 📦 Installation
11+
12+
```bash
13+
composer require codemonster-ru/support
14+
```
15+
16+
## 🧩 Provided Helpers
17+
18+
| Function | Description |
19+
| ---------------------- | ------------------------------------ |
20+
| `config()` | Get or set configuration values |
21+
| `env()` | Read environment variables |
22+
| `view()` / `render()` | Render or return a view instance |
23+
| `router()` / `route()` | Access router instance |
24+
| `request()` | Get the current HTTP request |
25+
| `response()` | Create a new HTTP response |
26+
| `json()` | Return a JSON response |
27+
| `session()` | Read, write, or access session store |
28+
| `dump()` / `dd()` | Debugging utilities (print and exit) |
29+
30+
## 🚀 Usage
31+
32+
All helpers are automatically registered via Composer’s autoloading.
33+
You can call them from anywhere in your application.
34+
35+
```php
36+
<?php
37+
38+
require __DIR__ . '/vendor/autoload.php';
39+
40+
// Environment variables
41+
$value = env('APP_ENV', 'production');
42+
43+
// Configuration
44+
config(['app.name' => 'Codemonster']);
45+
46+
echo config('app.name'); // Codemonster
47+
48+
// HTTP request and response
49+
$request = request();
50+
$response = response('Hello World', 200);
51+
$response->send();
52+
53+
// Router
54+
router()->get('/', fn() => response('Home'));
55+
router()->post('/contact', fn() => response('Contact form submitted'));
56+
57+
// View rendering
58+
echo render('emails.welcome', ['user' => 'Vasya']);
59+
60+
// Debugging
61+
dump($request);
62+
dd('Goodbye');
63+
```
64+
65+
## 🧪 Testing
66+
67+
You can run tests with the command:
68+
69+
```bash
70+
composer test
71+
```
72+
73+
## 👨‍💻 Author
74+
75+
[**Kirill Kolesnikov**](https://github.com/KolesnikovKirill)
76+
77+
## 📜 License
78+
79+
[MIT](https://github.com/codemonster-ru/support/blob/main/LICENSE)

composer.json

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{
2+
"name": "codemonster-ru/support",
3+
"description": "Global helper functions for the Codemonster PHP ecosystem.",
4+
"type": "library",
5+
"license": "MIT",
6+
"readme": "README.md",
7+
"authors": [
8+
{
9+
"name": "Kirill Kolesnikov",
10+
"email": "admin@codemonster.net",
11+
"homepage": "https://github.com/KolesnikovKirill",
12+
"role": "Lead Developer"
13+
}
14+
],
15+
"require": {
16+
"php": ">=8.2",
17+
"codemonster-ru/http": "^1.0",
18+
"codemonster-ru/view": "^2.0",
19+
"codemonster-ru/config": "^2.0",
20+
"codemonster-ru/env": "^2.0",
21+
"codemonster-ru/router": "^2.0",
22+
"codemonster-ru/session": "^1.0",
23+
"codemonster-ru/dumper": "^1.0"
24+
},
25+
"require-dev": {
26+
"phpunit/phpunit": "^9.6 || ^10.5 || ^11.0 || ^12.0",
27+
"codemonster-ru/view-php": "^2.0"
28+
},
29+
"autoload": {
30+
"psr-4": {
31+
"Codemonster\\Support\\": "src/"
32+
},
33+
"files": [
34+
"src/helpers/config.php",
35+
"src/helpers/env.php",
36+
"src/helpers/view.php",
37+
"src/helpers/router.php",
38+
"src/helpers/request.php",
39+
"src/helpers/response.php",
40+
"src/helpers/session.php",
41+
"src/helpers/dump.php"
42+
]
43+
},
44+
"autoload-dev": {
45+
"psr-4": {
46+
"Tests\\": "tests/"
47+
},
48+
"files": [
49+
"tests/bootstrap.php"
50+
]
51+
},
52+
"scripts": {
53+
"test": "phpunit --colors=always --testdox"
54+
},
55+
"minimum-stability": "stable",
56+
"prefer-stable": true,
57+
"homepage": "https://github.com/codemonster-ru/support",
58+
"keywords": [
59+
"php",
60+
"helpers",
61+
"support",
62+
"codemonster",
63+
"annabel",
64+
"framework",
65+
"utilities"
66+
],
67+
"support": {
68+
"issues": "https://github.com/codemonster-ru/support/issues",
69+
"source": "https://github.com/codemonster-ru/support"
70+
},
71+
"config": {
72+
"sort-packages": true
73+
},
74+
"extra": {
75+
"branch-alias": {
76+
"dev-main": "1.x-dev"
77+
}
78+
}
79+
}

phpunit.xml.dist

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit bootstrap="tests/bootstrap.php" colors="true">
3+
<testsuites>
4+
<testsuite name="Codemonster Support">
5+
<directory>./tests/Helpers</directory>
6+
</testsuite>
7+
</testsuites>
8+
</phpunit>

src/helpers/config.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
if (!function_exists('config')) {
4+
function config(string|array|null $key = null, mixed $default = null): mixed
5+
{
6+
$config = app('config');
7+
8+
if ($key === null) {
9+
return $config->all();
10+
}
11+
12+
if (is_array($key)) {
13+
foreach ($key as $name => $value) {
14+
$config->set($name, $value);
15+
}
16+
17+
return true;
18+
}
19+
20+
return $config->get($key, $default);
21+
}
22+
}

0 commit comments

Comments
 (0)