yiiboot / routing
yii3 属性路由
v1.0.0
2022-11-27 12:34 UTC
Requires
- php: ^8.1
- yiiboot/attributed: ^2.0
- yiisoft/aliases: ^2.0
- yiisoft/di: ^1.1
- yiisoft/dummy-provider: ^1.0
- yiisoft/http: ^1.2
- yiisoft/router: ^2.0
Requires (Dev)
- phpunit/phpunit: ^9.5
- rector/rector: ^0.14.3
- roave/infection-static-analysis-plugin: ^1.16
- spatie/phpunit-watcher: ^1.23
- vimeo/psalm: ^4.18
This package is not auto-updated.
Last update: 2024-09-30 19:06:51 UTC
README
YiiBoot Routing
一种使用 Route PHP 属性定义路由的方式。这允许在类内部配置路由,而无需在外部文件中添加任何配置
要求
- PHP 8.1 或更高版本。
安装
可以使用 composer 安装此包
composer require yiiboot/routing
通用用法
配置文件 config/params.php
return [ // ... 'yiiboot/attributed' => [ 'paths' => [ dirname(__DIR__) . '/src/Controller' ] ] ];
控制器文件 src/Controller/CustomController.php
namespace App\Controller; use Yiiboot\Routing\Attribute\Route;use Yiisoft\Router\CurrentRoute; #[Route('/customs', name:'customs.', middleware: [ FormatDataResponseAsJson::class ])] final class CustomController { #[Route('/{page:\d+}', name: 'list', method: 'GET', defaults: ['page' => 1])] public function list(): ResponseInterface { // ... } #[Route('/{id:\d+}', name: 'view', method: 'GET')] public function view(CurrentRoute $route): ResponseInterface { $id = $route->getArgument('id'); // ... } #[Route(name: 'create', method: 'POST')] public function create(): ResponseInterface { // ... } #[Route('/{id:\d+}', name: 'delete', method: 'DELETE')] public function delete(CurrentRoute $route): ResponseInterface { $id = $route->getArgument('id'); // ... } }
测试
单元测试
该包使用 PHPUnit 进行测试。要运行测试
./vendor/bin/phpunit
突变测试
该包的测试使用 Infection 突变框架和 Infection 静态分析插件 进行检查。要运行它
./vendor/bin/roave-infection-static-analysis-plugin
静态分析
代码使用 Psalm 进行静态分析。要运行静态分析
./vendor/bin/psalm
代码风格
使用 Rector 来使代码库遵循某些特定规则,或使用最新版或任何特定版本的 PHP
./vendor/bin/rector
依赖
使用 ComposerRequireChecker 来检测传递性的 Composer 依赖。
许可证
Yii Routing 是免费软件。它根据 Apache-2.0 许可证发布。有关更多信息,请参阅 LICENSE
由 Yii Boot 维护。