Route::get('test',function(){
dump(debug_backtrace());
});
/**
* Send the given request through the middleware / router.
*
* @param IlluminateHttpRequest $request
* @return IlluminateHttpResponse
*/
protected function sendRequestThroughRouter($request)
{
$this->app->instance('request', $request);
Facade::clearResolvedInstance('request');
$this->bootstrap();
return (new Pipeline($this->app))
->send($request)
->through($this->app->shouldSkipMiddleware() ? [] : $this->middleware)
->then($this->dispatchToRouter());
}
/**ARRAY_REDUCE 使用
* Run the pipeline with a final destination callback.
*
* @param Closure $destination
* @return mixed
*/
public function then(Closure $destination)
{
$pipeline = array_reduce(
array_reverse($this->pipes), $this->carry(), $this->prepareDestination($destination)
);
return $pipeline($this->passable);
}
function sum($carry, $item)
{
$carry += $item;
return $carry;
}
$a = array(1, 2, 3, 4, 5);
var_dump(array_reduce($a, "sum")); // int(15)
$arr = ['AAAA', 'BBBB', 'CCCC'];
$res = array_reduce($arr, function($carry, $item){
return function() use ($carry,$item){
dump("item:".$item);
if(is_null($carry)){
return "CARRY is null. item:".$item;
}
if($carry instanceof Closure){
dump($carry());
return strtolower($item);
}
return $item;
};
});
dump($res());
/**
* Get a Closure that represents a slice of the application onion.
*
* @return Closure
*/
protected function carry()
{
return function ($stack, $pipe) {
return function ($passable) use ($stack, $pipe) {
if (is_callable($pipe)) {
// If the pipe is an instance of a Closure, we will just call it directly but
// otherwise we'll resolve the pipes out of the container and call it with
// the appropriate method and arguments, returning the results back out.
return $pipe($passable, $stack);
} elseif (! is_object($pipe)) {
list($name, $parameters) = $this->parsePipeString($pipe);
// If the pipe is a string we will parse the string and resolve the class out
// of the dependency injection container. We can then build a callable and
// execute the pipe function giving in the parameters that are required.
$pipe = $this->getContainer()->make($name);
$parameters = array_merge([$passable, $stack], $parameters);
} else {
// If the pipe is already an object we'll just make a callable and pass it to
// the pipe as-is. There is no need to do any extra parsing and formatting
// since the object we're given was already a fully instantiated object.
$parameters = [$passable, $stack];
}
return method_exists($pipe, $this->method)
? $pipe->{$this->method}(...$parameters)
: $pipe(...$parameters);
};
};
}
Route::get('test',function(){
dump('this is controller');
//dump(debug_backtrace());
});
$response = $next($request);
本文为 @ 21CTO 创作并授权 21CTO 发布,未经许可,请勿转载。
内容授权事宜请您联系 webmaster@21cto.com或关注 21CTO 公众号。
该文观点仅代表作者本人,21CTO 平台仅提供信息存储空间服务。