承接 ikkez/f3-middleware 相关项目开发

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

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

ikkez/f3-middleware

最新稳定版本:v1.1.3

Composer 安装命令:

composer require ikkez/f3-middleware

包简介

A middleware router plugin for PHP Fat-Free Framework

README 文档

README

Middleware

Middleware Router

This is a middleware router for PHP Fat-Free-Framework, version 3.x

It's based on the F3 core router, that can be called independently before or after the main routing cycle. This can be useful if you want to hook into a group of other routes and want to do something right before processing the main route handler.

Installation

  • Method 1: use composer composer require ikkez/f3-middleware

  • Method 2: copy the middleware.php file into your F3 lib/ directory or another directory that is known to the AUTOLOADER

Usage Samples

$f3 = require('lib/base.php'); // imagine you have some admin routes $f3->route('GET|POST /admin','Controller\Admin->login'); // and these actions should be protected $f3->route('GET|POST /admin/@action','Controller\Admin->@action'); $f3->route('GET|POST /admin/@action/@type','Controller\Admin->@action'); $f3->route('PUT /admin/upload','Controller\Files->upload'); // so just add a global pre-route to all at once \Middleware::instance()->before('GET|POST /admin/*', function(\Base $f3, $params, $alias) { // do auth checks }); \Middleware::instance()->run(); $f3->run();

Of course you could also use the beforeroute and afterroute events in your controller to add that auth check functionality. But in case your controller structure isn't ready yet for easy implementation or you have things you strictly want to separate from your controllers, like settings. Here the Middleware Router will aid you.

// enable the CORS settings only for your API routes: \Middleware::instance()->before('GET|HEAD|POST|PUT|OPTIONS /api/*', function(\Base $f3) { $f3->set('CORS.origin','*'); });

You can also create additional middleware wrappers on other events:

$mw = \Middleware::instance(); $mw->on('limit',['GET @v1: /api/v1/*','GET @v2: /api/v2/*'], function($f3,$args,$alias) { // do api usage limit checks return false; }); if ($mw->run('limit')) { // all good, continue }else{ // API limit reached }

Notice

Although you can probably use the middleware router as a completely stand alone router, it is not a full replacement of the frameworks integrated router. The middleware router does not include handling of route caching, header management or automated CORS support, so use it as an additional component for settings, checks and workload before/after the main routing cycle.

License

You are allowed to use this plugin under the terms of the GNU General Public License version 3 or later.

Copyright (C) 2019 Christian Knuth (ikkez)

统计信息

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

GitHub 信息

  • Stars: 24
  • Watchers: 5
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固