承接 niltonduarte/route 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

niltonduarte/route

Composer 安装命令:

composer require niltonduarte/route

包简介

A lightweight, simple and easy request router for your application.

README 文档

README

For more details, see the examples folder inside the library. It has no dependencies. Use this with any server, including PHP's built-in server. Inside the folder where you downloaded the component open the terminal and run the command:

php -S localhost:80 -t .

or

php -S localhost:80

If you have a problem, just change the 80 to another port number. For more details on PHP's built-in web server see https://www.php.net/manual/en/features.commandline.webserver.php

Its use is ridiculously easy!

I recommend that you create an index.php file in the root of the public folder that will be accessed by the server when it receives a request from some page of your application and call composer autoload to load Route like this:

<?php
require __DIR__ . '/path/to/vendor/autoload.php';

Start by instantiating the Route\Route\Route class that implements the Route\Route\RouteInterface interface.

$route = new Route\Route\Route();

The Route component supports the five most common HTTP methods in applications, GET, POST, PUT, PATCH and DELETE.

To define a route, call one of the methods of the Route\Route\RouteInterface interface, passing a route and a handle as a parameter:

$route->get('/route-name', 'handler');

The handler can be a method of a class or a callback function.

Passing parameters via URL

Route works with friendly URL and you can pass parameters via URL between curly braces without using querystring. Remembering that you can still use them if you prefer.

$route->get('/route-name/{foo}/{bar}', function (array $params) {
    print_r($params);
    echo '<p>Page content</p>';
});

Respond to other HTTP methods

If the handler is a class with a method, you must write in the second parameter as a string the fully qualified name of the class as recommended by PSR-4, separated from the method by the character @.

$route->get('/route-one', 'VendorNamespace\SubNamespace\ControllerName@methodA');
$route->post('/route-two', 'VendorNamespace\SubNamespace\ControllerName@methodB');
$route->put('/route-three', 'VendorNamespace\SubNamespace\ControllerName@methodC');
$route->patch('/route-four', 'VendorNamespace\SubNamespace\ControllerName@methodD');
$route->delete('/route-five', 'VendorNamespace\SubNamespace\ControllerName@methodE');

dispatching the route

After defining all the routes of your web application, call the run() method which will do the routing based on the accessed URI.

$route->run();

To catch errors, just call the getError() method after run(), which will return an object with the error information. As in the case of a non-existent route.

if ($error = $route->getError()) {
    // Handle errors here.
    $code = $error->getHttpErrorCode();
    $message = $error->getHttpErrorMessage();
    echo "Error {$code}, {$message}!";
}

See the examples folder

niltonduarte/route 适用场景与选型建议

niltonduarte/route 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 07 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「routing」 「mvc」 「controller」 「router」 「psr-7」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 niltonduarte/route 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 niltonduarte/route 我们能提供哪些服务?
定制开发 / 二次开发

基于 niltonduarte/route 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 11
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 15
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2022-07-12