|
@@ -57,25 +57,25 @@ class Application extends Container implements HttpKernelInterface, TerminableIn |
|
|
protected $bootedCallbacks = array(); |
|
|
|
|
|
/** |
|
|
* The array of close callbacks. |
|
|
* The array of finish callbacks. |
|
|
* |
|
|
* @var array |
|
|
*/ |
|
|
protected $closeCallbacks = array(); |
|
|
protected $finishCallbacks = array(); |
|
|
|
|
|
/** |
|
|
* The array of finish callbacks. |
|
|
* The array of shutdown callbacks. |
|
|
* |
|
|
* @var array |
|
|
*/ |
|
|
protected $finishCallbacks = array(); |
|
|
protected $shutdownCallbacks = array(); |
|
|
|
|
|
/** |
|
|
* The array of shutdown callbacks. |
|
|
* All of the developer defined middlewares. |
|
|
* |
|
|
* @var array |
|
|
*/ |
|
|
protected $shutdownCallbacks = array(); |
|
|
protected $middlewares = array(); |
|
|
|
|
|
/** |
|
|
* All of the registered service providers. |
|
@@ -429,24 +429,6 @@ public function after($callback) |
|
|
return $this['router']->after($callback); |
|
|
} |
|
|
|
|
|
/** |
|
|
* Register a "close" application callback, or call them. |
|
|
* |
|
|
* @param Closure|string $callback |
|
|
* @return void |
|
|
*/ |
|
|
public function close($callback = null) |
|
|
{ |
|
|
if (is_null($callback)) |
|
|
{ |
|
|
$this->callCloseCallbacks(); |
|
|
} |
|
|
else |
|
|
{ |
|
|
$this->closeCallbacks[] = $callback; |
|
|
} |
|
|
} |
|
|
|
|
|
/** |
|
|
* Register a "finish" application filter. |
|
|
* |
|
@@ -549,18 +531,58 @@ public function run(SymfonyRequest $request = null) |
|
|
{ |
|
|
$request = $request ?: $this['request']; |
|
|
|
|
|
$response = with(new \Stack\Builder) |
|
|
$response = with($stack = $this->getStackedClient())->handle($request); |
|
|
|
|
|
$response->send(); |
|
|
|
|
|
$stack->terminate($request, $response); |
|
|
} |
|
|
|
|
|
/** |
|
|
* Get the stacked HTTP kernel for the application. |
|
|
* |
|
|
* @return \Symfony\Component\HttpKernel\HttpKernelInterface |
|
|
*/ |
|
|
protected function getStackedClient() |
|
|
{ |
|
|
$client = with(new \Stack\Builder) |
|
|
->push('Illuminate\Cookie\Guard', $this['encrypter']) |
|
|
->push('Illuminate\Cookie\Queue', $this['cookie']) |
|
|
->push('Illuminate\Session\Middleware', $this['session']) |
|
|
->resolve($this) |
|
|
->handle($request); |
|
|
->push('Illuminate\Session\Middleware', $this['session']); |
|
|
|
|
|
$this->callCloseCallbacks($request, $response); |
|
|
$this->mergeCustomMiddlewares($client); |
|
|
|
|
|
$response->send(); |
|
|
return $client->resolve($this); |
|
|
} |
|
|
|
|
|
/** |
|
|
* Merge the developer defined middlewares onto the stack. |
|
|
* |
|
|
* @param \Symfony\Component\HttpKernel\HttpKernelInterface |
|
|
* @return void |
|
|
*/ |
|
|
protected function mergeCustomMiddlewares(HttpKernelInterface $client) |
|
|
{ |
|
|
foreach ($this->middlewares as $key => $value) |
|
|
{ |
|
|
$parameters = array_unshift($value, $key); |
|
|
|
|
|
$this->terminate($request, $response); |
|
|
call_user_func_array(array($client, 'push'), $parameters); |
|
|
} |
|
|
} |
|
|
|
|
|
/** |
|
|
* Add a HttpKernel middleware onto the stack. |
|
|
* |
|
|
* @param string $class |
|
|
* @param array $parameters |
|
|
* @return \Illuminate\Foundation\Application |
|
|
*/ |
|
|
public function middleware($class, array $parameters = array()) |
|
|
{ |
|
|
$this->middlewares[$class] = $parameters; |
|
|
|
|
|
return $this; |
|
|
} |
|
|
|
|
|
/** |
|
@@ -629,21 +651,6 @@ protected function refreshRequest(Request $request) |
|
|
Facade::clearResolvedInstance('request'); |
|
|
} |
|
|
|
|
|
/** |
|
|
* Call the "close" callbacks assigned to the application. |
|
|
* |
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
|
|
* @param \Symfony\Component\HttpFoundation\Response $response |
|
|
* @return void |
|
|
*/ |
|
|
public function callCloseCallbacks(SymfonyRequest $request, SymfonyResponse $response) |
|
|
{ |
|
|
foreach ($this->closeCallbacks as $callback) |
|
|
{ |
|
|
call_user_func($callback, $request, $response); |
|
|
} |
|
|
} |
|
|
|
|
|
/** |
|
|
* Call the "finish" callbacks assigned to the application. |
|
|
* |
|
|