💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
``` <?php interface Middleware { public static function go(Closure $next, $p); } class testOne implements Middleware { public static function go(Closure $next, $p) { echo "测试一" . $p . "\n"; $next(++$p); echo "测试一后" . $p . "\n"; } } class testTwo implements Middleware { public static function go(Closure $next, $p) { echo "测试二" . $p . "\n"; $next(++$p); echo "测试二后" . $p . "\n"; } } function goFun(){ return function ($f, $className) { return function ($p) use ($f, $className) { $res = $className::go($f, $p); }; }; } function run(){ $steps = ['testOne', 'testTwo']; $prepare = function ($p) { echo "我是要做的操作" . $p . "\n"; }; $go = array_reduce(array_reverse($steps), goFun(), $prepare); $go('666'); } run(); ``` 帮助理解: ``` function goFun(){ return function ($f, $className) { return function ($p) use ($f, $className) { $res = $className::go($f, $p); // 处理或使用 $res 的值 echo $res; }; }; } // 调用 goFun() 函数 $functionWrapper = goFun(); // 调用返回的匿名函数,并传递参数 $functionToExecute = $functionWrapper('bar', 'Foo'); $functionToExecute(5); ```