wilsonneto-dev/express-router 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

wilsonneto-dev/express-router

最新稳定版本:1.0.1

Composer 安装命令:

composer require wilsonneto-dev/express-router

包简介

The simplest router for PHP

README 文档

README

🎈 The simplest, easiest, and most minimalist way 😃 to create routes in a pure PHP app

Install it in your project:

composer require wilsonneto-dev/express-router

Use it in your project:

require_once __DIR__ . "/vendor/autoload.php";

$router = new ExpressRouter\Router();

// ... register your routes...

$router->route(isset($_GET["path"]) ? $_GET["path"] : "");

Simple example of creating routes

require_once __DIR__ . "/vendor/autoload.php";

$router = new ExpressRouter\Router();

$router->get("/", function ($req, $res) {
    return $res->response(array("ok" => true, "tip" => "Use /articles"));
});

$router->get("/articles", function ($req, $res) {
    return $res->response(array("example" => "list of articles"));
});

$router->get("/articles/:id", function ($req, $res) {
    return $res->response(array("example" => "details of the article with id " . $req->parameters["id"]));
});

$router->get("/articles/:id/comments", function ($req, $res) {
    return $res->response(array("example" => "list of comments of the article with id " . $req->parameters["id"]));
});

$router->post("/articles", function ($req, $res) {
    return $res->response(array("example" => "create a new article"));
});

$router->put("/articles/:id", function ($req, $res) {
    return $res->response(array("example" => "update the article with id " . $req->parameters["id"]));
});

$router->route(isset($_GET["path"]) ? $_GET["path"] : "");

You will need the rewrite mod enabled and a .htaccess file as the below:

<Files app.ini> 
    Order Allow,Deny
    Deny from all
</Files>

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?path=$1 [NC,L,QSA]

Example project:

https://github.com/wilsonneto-dev/express-router-example

Package website:

https://wilsonneto-dev.github.io/express-router/

Packagist:

https://packagist.org/packages/wilsonneto-dev/express-router

Request and Response objects

your router callbacks will receive two objects, the request with all the request information; and the response is the object responsible by prepare the response.

class Request {
    // the route parameters
    public ?Array $parameters;

    // query parameters 
    public ?Array $query = null;

    // body payload
    public $body = null;

    // the request route
    public string $route = "";

    // the request method
    public string $method = "";
}
class Response {
    // use this method to control the response status code, default 200. 
    public function status(int $new_status_code);

    // use this method to return the response
    public function response(Array $response);
}

And yes, that's all!
Life can be simple sometimes ✨

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-09-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固