定制 exan/poopexpress 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

exan/poopexpress

最新稳定版本:2.0.0

Composer 安装命令:

composer require exan/poopexpress

包简介

A crappy router you shouldn't use

README 文档

README

It's a router. It's fast. Don't use it.

Using it is a shitty experience, hence PoopExpress.

Usage

You start by initializing the router, with your request details

$router = new PoopExpress($_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI']);

You then attempt routes, rather than registering them

$router->attempt([''], ['GET', function () {
    echo 'Home page';
}]) || $router->attempt(['somewhere-else'], ['GET' => function () {
    echo 'This is a different page';
}]);

This gives you 2 endpoints, with automatic 405 handling:

  • /
  • /somewhere-else

Dynamic routes are an option

$router->attempt(['group', '*'], ['GET' => function ($id) {
    echo 'This page is within the "group", ', $id;
}]);

And for optimal performance, use this garbage syntax to seperate your routes into groups:

(
    $router->group(['group']) && (
        $router->attempt(['group', 'nowhere'], ['GET' => function () {
            echo 'This page is also within the "group"';
        }]) || $router->attempt(['group', 'some-other-group'], ['POST' => function () {
            echo 'This page is yet again within the "group"';
        }])
    )
)

All together:

$router = new PoopExpress($_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI']);

$router->attempt([''], ['GET', function () {
    echo 'Home page';
}]) || $router->attempt(['somewhere-else'], ['GET' => function () {
    echo 'This is a different page';
}]) || (
    $router->group(['group']) && (
        $router->attempt(['group', 'nowhere'], ['GET' => function () {
            echo 'This page is also within the "group"';
        }]) || $router->attempt(['group', 'some-other-group'], ['POST' => function () {
            echo 'This page is yet again within the "group"';
        }]) || $router->attempt(['group', '*'], ['GET' => function ($id) {
            echo 'This page is within the "group", ', $id;
        }])
    )
) || $router->attempt(['not-group', 'page'], ['GET' => function () {
    echo 'This is no longer in the group';
}]) || (function () {
    http_response_code(404);
    echo '404';
})();

How is this fast?

Routes are never registered, and when the "current" route is attempted, parsing of any other route never occurs to any degree. With groups and funky and-gates you can skip the checking of sub-routes if the parent does not match.

Why shouldn't I use it?

If your app is slow, it's very unlikely throwing a new router into the mix will solve your problems.

It's also just plain painful to try to use this.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-05