devpontes/route
Composer 安装命令:
composer require devpontes/route
包简介
Simples componente de rotas para projetos pequenos baseados em MVC
README 文档
README
About Route componet
Route is a simple and lightweight route management component designed for small projects based on MVC architecture.
O Route é um componente simples e leve de gerenciamento de rotas, projetado para pequenos projetos baseados em arquitetura MVC.
Highlights
- Suporte a rotas nomeadas. (named routes)
- Modo estrito para diferenciação de URLs. (strict mode)
- Configuração simples e intuitiva. (simple to set up)
- Padrão de rota: controller/method/{parameter}.
Instalação
Installation is available through Composer:
"devpontes/route": "3.*"
or run
composer require devpontes/route
Documentation
1. Configuração
To use Route, all application requests must be redirected to the index.php file, which will act as the Front Controller. Example using Apache (.htaccess)
Para utilizar o Route, todas as requisições da aplicação devem ser redirecionadas para o arquivo index.php, que atuará como o Front Controller. Exemplo usando o Apache (.htaccess):
Apache
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
2. Definição de Rotas
Routes must be defined in an array in the format [path, controller@method]
As rotas devem ser definidas em um array no formato [path, controller@method]:
$routes = [ ['/', 'Home@index'], ['/blog', 'Blog@index'], ['/contato', 'Contact@index'], ['/contato/{id}', 'Contact@index'], ['/not-found/404', 'Notfound@index'], ];
3. Captura da URL
The request URL must be captured and passed to the component in the constructor or via the setter method.
A URL da requisição deve ser capturada e passada ao componente no construtor ou via metodo setter. Exemplo com servidor Apache:
$url = $_GET['url'];
ou usando a pasta publica
$url = $_SERVER['REQUEST_URI'];
4. Inicialização
On component initialization: 1 - Enter the routes array; 2 - Configure the controllers' namespace (the same as defined in composer.json); 3 - Run with the run() method.
Na inicialização do componente:
- Informe o array de rotas.
- Configure o namespace dos controladores (mesmo definido no composer.json).
- Execute com o método run().
Usage
$route = new \DevPontes\Route\Route($routes); $route->setUrl($url); $route->namespace("App\Controller"); $route->run();
5. Tratamento de Erros
To capture unconfigured routes, use the fail method
Para capturar rotas não configuradas, utilize o método fail:
if ($route->fail()) { header('Location: /not-found/404'); }
6. Modo Estrito
Strict mode differentiates between routes with and without trailing slashes.
O modo estrito diferencia rotas com e sem barra final. Exemplo:
- /sobre ≠ /sobre/ (strict mode enabled).
- /sobre = /sobre/ (strict mode disabled).
Enabling/disabling
$route->setStrictMode(true);
Credits
- Moises Pontes (Developer)
License
The MIT License (MIT).
devpontes/route 适用场景与选型建议
devpontes/route 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 32 次下载、GitHub Stars 达 3, 最近一次更新时间为 2022 年 11 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「route」 「routing」 「router」 「routes」 「slin」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 devpontes/route 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 devpontes/route 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 devpontes/route 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Provide a way to secure accesses to all routes of an symfony application.
Write down your routing mapping at one place
A Laravel-like router for the WordPress Rewrite API
Flight routing is a simple, fast PHP router that is easy to get integrated with other routers.
A Laravel helper to detect if the current route/path is active.
Router
统计信息
- 总下载量: 32
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-11-22