|
| 1 | +# codemonster-ru/support |
| 2 | + |
| 3 | +[](https://packagist.org/packages/codemonster-ru/support) |
| 4 | +[](https://packagist.org/packages/codemonster-ru/support) |
| 5 | +[](https://packagist.org/packages/codemonster-ru/support) |
| 6 | +[](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) |
0 commit comments