webiik/middleware 问题修复 & 功能扩展

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

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

webiik/middleware

Composer 安装命令:

composer require webiik/middleware

包简介

The Middleware is middleware launcher that allows automatic constructor DI and sending custom data among middleware.

关键字:

README 文档

README

Middleware

The Middleware is middleware launcher that allows automatic constructor DI and sending custom data among middleware.

Installation

composer require webiik/middleware

Example

$middleware = new \Webiik\Middleware\Middleware($container, $data);
$middleware->add('MwTest:run', ['foo' => 'bar']);
$middleware->run();

Writing Middleware

Every middleware has to be a class with at least one public method with the following parameters \Webiik\Data\Data $data, callable $next. Every class can contain more methods with the mentioned parameters.

class MwTest
{
    public function run(\Webiik\Data\Data $data, callable $next)
    {
        // Get middleware data
        $mwData = $data->getAll(); // Array([foo] => [bar])
         
        // Change middleware data 
        $data->set('foo', 'foo');
        
        // Launch next middleware
        $next();
        
        // Continue current middlware...
    }
}

You can also use constructor DI to inject services from container to middleware. Read more about DI and container.

Adding

add

add(string $controller, $data = []): void

add() ads middleware to queue.

Parameters:

  • controller string representation of controller and method to be initiated e.g. controllerName:methodName
  • data a key-value array of data to be injected during the middleware initiation
$middleware->add('MwTest:run');

Launch

run

run(): void

run() runs all middleware in queue.

$middleware->run();

Resources

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-03-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固