oihana/php-routes
Composer 安装命令:
composer require oihana/php-routes
包简介
The Oihana PHP Routes library
README 文档
README
Declarative, composable HTTP route definitions for PHP 8.4+, built on Slim.
📚 Documentation
User guides (FR + EN), with narrative explanations and examples:
| 🇬🇧 English documentation | 🇫🇷 Documentation française |
|---|---|
| Getting started, routes, HTTP method routes, document & i18n routes, helpers, testing. | Démarrage, routes, routes par méthode HTTP, routes document & i18n, helpers, tests. |
Auto-generated API reference (phpDocumentor):
👉 https://bcommebois.github.io/oihana-php-routes
🧠 What is it?
oihana/php-routes provides a small, declarative layer for defining HTTP routes
on top of Slim: a composable Route base, one class per HTTP verb
(GetRoute, PostRoute, …), higher-level DocumentRoute / I18nRoute, and
helpers to register them on a Slim app from a PSR-11 container. Each route maps
a URL pattern to a controller method.
use DI\Container; use Slim\Factory\AppFactory; use Slim\App; use oihana\routes\http\GetRoute; $container = new Container(); AppFactory::setContainer( $container ); $app = AppFactory::create(); $container->set( App::class , $app ); // Register: GET /api/test -> $controller->get() $route = new GetRoute( $container , [ 'controllerID' => 'my.controller', 'route' => 'api/test', ] ); $route(); // registers the route on the Slim app
For full details (route classes, flags, helpers), see the table of contents in the documentation.
🚀 Features
- 🧭 A composable
Routebase and per-verb route classes —GetRoute,PostRoute,PutRoute,PatchRoute,DeleteRoute,DeleteAllRoute,OptionsRoute,ListRoute. - 📄 Higher-level routes —
DocumentRouteandI18nRoutefor documents and localized paths. - 🚩 Declarative route options via the
RouteFlagbit flags. - 🧩 Route registration helpers —
HttpMethodRoutesTrait,HasRouteTrait, pluswithPlaceholder()andresponsePassthrough(). - 🔗 Built on Slim and wired through a PSR-11 container.
- 🧪 Full unit-test coverage ensuring reliability and maintainability.
💡 Designed to be composable, testable, and compatible with any PHP 8.4+ project.
📦 Installation
Requires PHP 8.4+
Install via Composer:
composer require oihana/php-routes
oihana/php-routesdepends onoihana/php-controllers, which requires theext-imagickextension — make sure it is installed.
✅ Tests & coverage
Run the full unit-test suite (PHPUnit, strict mode):
composer test
Run a single test case:
./vendor/bin/phpunit --filter GetRouteTest
Measure coverage (requires Xdebug or PCOV):
composer coverage # text + Clover + HTML under build/coverage/ composer coverage:md # readable Markdown summary (build/coverage/COVERAGE.md)
The suite runs in strict mode and targets 100% line coverage.
🧾 License
This project is licensed under the Mozilla Public License 2.0 (MPL-2.0).
👤 About the author
- Author : Marc ALCARAZ (aka eKameleon)
- Mail : marc@ooop.fr
- Website : http://www.ooop.fr
🛠️ Generate the Documentation
We use phpDocumentor to generate the documentation into the ./docs folder.
Usage
Run the command :
composer doc
🔗 Related packages
- oihana/php-controllers – the HTTP controllers the routes dispatch to (provides
AppTrait). - oihana/php-core – core helpers and utilities used by this library.
- oihana/php-enums – strongly-typed constant enumerations (HTTP methods, etc.).
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MPL-2.0
- 更新时间: 2026-06-21
