定制 pinga/router 二次开发

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

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

pinga/router

最新稳定版本:v0.1

Composer 安装命令:

composer require pinga/router

包简介

Router for PHP. Simple, lightweight and convenient.

README 文档

README

Router for PHP. Simple, lightweight and convenient.

Requirements

  • PHP 8.1.0+

Installation

  1. Include the library via Composer [?]:

    $ composer require pinga/router
    
  2. Include the Composer autoloader:

    require __DIR__ . '/vendor/autoload.php';

Usage

  1. Enable URL rewriting on your web server

    • Apache (in .htaccess or httpd.conf)

      RewriteEngine On
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteRule . index.php [L]
      
    • Nginx (in nginx.conf)

      try_files $uri /index.php;
      
  2. Create a new Router instance

    • for the web root

      $router = new \Delight\Router\Router();
    • for any subdirectory

      $router = new \Delight\Router\Router('/my/base/path');
  3. Add some routes and map them to anonymous functions or closures

    • Static route:

      $router->get('/', function () {
          // do something
      });
    • Dynamic route (with parameters):

      $router->get('/users/:id/photo', function ($id) {
          // get the photo for user `$id`
      });

      The values of parameters matched in the URL can be captured as arguments in the callback.

    • Route with multiple supported request methods:

      $router->any([ 'POST', 'PUT' ], '/users/:id/address', function ($id) {
          // update the address for user `$id`
      });
  4. Map routes to controller methods instead for more complex callbacks

    // use static methods
    $router->get('/photos/:id/convert/:mode', [ 'PhotoController', 'myStaticMethod' ]);
    
    // or
    
    // instance methods
    $router->get('/photos/:id/convert/:mode', [ $myPhotoController, 'myInstanceMethod' ]);
  5. Inject arguments for access to further values and objects (prepended to those matched in the route)

    class MyController {
    
        public static function someStaticMethod($database, $uuid) {
            // do something
        }
    
    }

    and

    $database = new MyDatabase();
    
    // ...
    
    $router->delete('/messages/:uuid', [ 'MyController', 'someStaticMethod' ], [ $database ]);

Contributing

All contributions are welcome! If you wish to contribute, please create an issue first so that your feature, problem or question can be discussed.

License

This project is licensed under the terms of the MIT License.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-01-27

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固