From 0e3c7a7dbdd2ae8bf77ed89c47bb84d87c5fbe50 Mon Sep 17 00:00:00 2001 From: Jagepard Date: Fri, 19 Jun 2026 09:12:26 +0300 Subject: [PATCH] refactor: update exception classes to PHP 8.4 standards --- README.md | 59 ++++++++++++++++++++++++++++++++--------- tests/ExceptionTest.php | 19 ++++++------- 2 files changed, 54 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 43db747..60b75f5 100755 --- a/README.md +++ b/README.md @@ -5,9 +5,52 @@ ----- # Rudra-Exception | [API](https://github.com/Jagepard/Rudra-Exception/blob/master/docs.md "Documentation API") -#### Установка / Install -```composer require rudra/exception``` +#### Install +```bash +composer require rudra/exception +``` +#### Usage +##### Throwing HTTP Errors +```php +// Using abort() helper +abort(404); +abort(500, "Internal Server Error"); +// Or directly +throw new RouterException("Not Found", 404); +throw new NotFoundException("Resource not found"); +throw new LogicException("Invalid configuration"); +``` +#### Exception Hierarchy +```text +Throwable +└── RuntimeException + └── RudraException + ├── RouterException + ├── LogicException + │ └── MiddlewareException + ├── NotFoundException + └── RuntimeException +``` +#### Configuration +##### Error Pages +Configure error handlers in your ```setting.{$env}.yml```: +```yml +http.errors: + 404: + controller: App\Ship\Errors\Controller\HttpErrorsController + action: error404 + 503: + controller: App\Ship\Errors\Controller\HttpErrorsController + action: error503 +``` +#### DebugBar Integration +In development mode, exceptions are automatically logged to DebugBar: +```php +if (Rudra::config()->get("environment") === "development") { + $debugbar->addCollector(new DebugBar\DataCollector\ExceptionsCollector()); +} +``` ## License This project is licensed under the **Mozilla Public License 2.0 (MPL-2.0)** — a free, open-source license that: @@ -18,14 +61,4 @@ This project is licensed under the **Mozilla Public License 2.0 (MPL-2.0)** — - Permits combining with proprietary code in larger works. 📄 Full license text: [LICENSE](./LICENSE) -🌐 Official MPL-2.0 page: https://mozilla.org/MPL/2.0/ - --------------------------- -Проект распространяется под лицензией **Mozilla Public License 2.0 (MPL-2.0)**. Это означает: - - Вы можете свободно использовать, изменять и распространять код. - - При изменении файлов, содержащих исходный код из этого репозитория, вы обязаны оставить их открытыми под той же лицензией. - - Вы **обязаны сохранять уведомления об авторстве** и ссылку на оригинал. - - Вы можете встраивать код в проприетарные проекты, если исходные файлы остаются под MPL. - -📄 Полный текст лицензии (на английском): [LICENSE](./LICENSE) -🌐 Официальная страница: https://mozilla.org/MPL/2.0/ \ No newline at end of file +🌐 Official MPL-2.0 page: https://mozilla.org/MPL/2.0/ \ No newline at end of file diff --git a/tests/ExceptionTest.php b/tests/ExceptionTest.php index 4a87a2b..3cf8e32 100755 --- a/tests/ExceptionTest.php +++ b/tests/ExceptionTest.php @@ -8,20 +8,17 @@ * @author Korotkov Danila (Jagepard) * @license https://mozilla.org/MPL/2.0/ MPL-2.0 * - * phpunit src/tests/ContainerTest --coverage-html src/tests/coverage-html + * phpunit src/tests/ExceptionTest --coverage-html src/tests/coverage-html */ -use Rudra\Exceptions\{ - LogicException, - RudraException, - RouterException, - RuntimeException, - NotFoundException, - MiddlewareException, -}; -use PHPUnit\Framework\TestCase; +use Rudra\Exceptions\LogicException; +use Rudra\Exceptions\RudraException; +use Rudra\Exceptions\RouterException; +use Rudra\Exceptions\RuntimeException; +use Rudra\Exceptions\NotFoundException; +use Rudra\Exceptions\MiddlewareException; -class ExceptionTest extends TestCase +class ExceptionTest extends \PHPUnit\Framework\TestCase { protected function tearDown(): void {