如何在zend-expressive中组合相同的中间件?

时间:2018-12-14 20:25:39

标签: php zend-expressive

我有2组路由(网络和api):

enter image description here

以下是网络路线示例:

Sub RecordData()
Dim Interval As Double
Dim cel As Range, Capture As Range
Interval = 30 'Number of seconds between each recording of data
Set Capture = Worksheets("Sheet1").Range("C4:K4") 'Capture this row of data
With Worksheets("Sheet2") 'Record the data on this worksheet
    Set cel = .Range("A2") 'First timestamp goes here
    Set cel = .Cells(.Rows.Count, cel.Column).End(xlUp).Offset(1, 0)
    cel.Value = Now
    cel.Offset(0, 1).Resize(1, Capture.Cells.Count).Value = Application.Transpose(Capture.Value)
End With
NextTime = Now + Interval / 86400
Application.OnTime NextTime, "RecordData"
End Sub

我注意到许多中间件都在重复。我想对一些中间件进行分组。 例如:

return function (Application $app, MiddlewareFactory $factory, ContainerInterface $container): void {

    $app->get('/', [
        Zend\Expressive\Session\SessionMiddleware::class,
        Zend\Expressive\Flash\FlashMessageMiddleware::class,
        User\Service\Auth\TemplateAuthMiddleware::class,
        Dev\Handler\IndexPageHandler::class
    ], 'home');

    $app->route('/auth/login', [
        Zend\Expressive\Session\SessionMiddleware::class,
        Zend\Expressive\Flash\FlashMessageMiddleware::class,
        User\Service\Auth\OnlyForGuestsMiddleware::class,
        User\Service\Auth\TemplateAuthMiddleware::class,
        User\Handler\LoginPageHandler::class
    ], ['GET', 'POST'], 'auth.login');


    $app->route('/auth/register', [
        Zend\Expressive\Session\SessionMiddleware::class,
        Zend\Expressive\Flash\FlashMessageMiddleware::class,
        User\Service\Auth\OnlyForGuestsMiddleware::class,
        User\Service\Auth\TemplateAuthMiddleware::class,
        User\Handler\ResetPageHandler::class
    ], ['GET', 'POST'], 'auth.register');

    ...
};

我知道zend-expressive不支持像laravel5这样的中间件。有一个漂亮的分组解决方案吗?

0 个答案:

没有答案