定制 stack/inline 二次开发

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

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

stack/inline

Composer 安装命令:

composer require stack/inline

包简介

Inline stack middleware.

README 文档

README

Inline stack middleware.

Enables the usage of callables as stack middlewares.

Example

Here is a contrived example showing how a callable can be used to easily act as a stack middleware for a silex application:

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

$app = new Silex\Application();

$app->get('/', function (Request $request) {
    if ('success' === $request->attributes->get('callable_middleware')) {
        return new Response('SUCCESS');
    }

    return new Response('FAILED', 500);
});

$inlineMiddleware = function(
    HttpKernelInterface $app,
    Request $request,
    $type = HttpKernelInterface::MASTER_REQUEST,
    $catch = true
) {
    $request->attributes->set('callable_middleware', 'success');

    $response = $app->handle($request, $type, $catch);
    $response->setContent('['.$response->getContent().']');

    return $response;
};

$stack = (new Stack\Builder())
    ->push('Stack\Inline', $inlineMiddleware);

$app = $stack->resolve($app);

Usage

The method signature for the callable is similar to HttpKernelInterface::handle except that it requires an HttpKernelInterface instance as its first argument. A simple passthru inline middleware would look like this:

$app = new Stack\Inline($app, function(
    HttpKernelInterface $app,
    Request $request,
    $type = HttpKernelInterface::MASTER_REQUEST,
    $catch = true
) {
    return $app->handle($request, $type, $catch);
});

统计信息

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

GitHub 信息

  • Stars: 5
  • Watchers: 4
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-02-19