ifcanduela/kernel-middleware 问题修复 & 功能扩展

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

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

ifcanduela/kernel-middleware

最新稳定版本:1.0.0

Composer 安装命令:

composer require ifcanduela/kernel-middleware

包简介

Middleware processor for HTTP requests and responses

README 文档

README

A request/response processor with a simple implementation of middleware.

Using the Kernel

The ifcanduela\kernel\Kernel class is ready to be extended by your own class:

<?php

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class App extends \ifcanduela\kernel\Kernel
{
    public function __construct(array $middleware)
    {
        $middleware[] = $this->run(...);

        parent::__construct($middleware)
    }

    public function run(Request $request, Closure $next): Response
    {
        return new Response("hello");
    }
}

Using Middleware

Middlewares must either be callable or implement \ifcanduela\kernel\Middleware. The expected signature of the callable is this:

function (Request $request, Closure $next): Response;

Where Request and Response are the Symfony HTTP Foundation classes and the $next Closure is a function that optionally accepts a Request and will return a Response.

A middleware can return $next() or $next($request) to pass control to the next middleware in the chain and get a Response object.

class ExampleMiddleware implements Middleware
{
    public function handle($request, $next)
    {
        return $next();
    }
}

Middleware implementing ifcanduela\kernel\Middleware

Any object that implements this interface is valid middleware, including anonymous classes:

new Kernel([
    InitSessionMiddleware::class,

    new InitContainerMiddleware($container)

    new class implements Middleware {
        public function handle(Request $request, Closure $next): Response
        {
            // ...
        }
    }
])

Middleware using callables

Functions and objects implementing __invoke() are acceptable middleware.

new Kernel([
    new class {
        public function __invoke($req, $next) {
            return $next();
        }
    },

    fn ($req, $next) => new JsonResponse([]),
])

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-11-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固