Laravel中间件原理

setContent(str_replace('{img_list}', '', $tplContent->getContent()));

        echo $tplContent->getContent(), PHP_EOL;

        return $next();
    }
}

class Title {
    public static function handle($tplContent, Closure $next) {
        $tplContent->setContent(str_replace('{title}', 'Test Title', $tplContent->getContent()));

        echo $tplContent->getContent(), PHP_EOL;

        return $next();
    }
}

$parsers = ['ImageList', 'Title'];

class TplContent {
        private $tplContent = '

{title}

{img_list}'; public function setContent($content) { $this->tplContent = $content; } public function getContent() { return $this->tplContent; } } $tplContent = new TplContent; $callback = array_reduce(array_reverse($parsers), function($stack, $pipe) use ($tplContent) { return function() use ($tplContent, $stack, $pipe) { return $pipe::handle($tplContent, $stack); }; }, function() use ($tplContent) { echo 'real process result: ', $tplContent->getContent(), PHP_EOL; }); call_user_func($callback);
此条目发表在 涨姿势 分类目录。将固定链接加入收藏夹。

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*


*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>