Permalink
Browse files

Added App::middleware method to inject middlewares onto Stack.

  • Loading branch information...
taylorotwell committed Oct 28, 2013
1 parent d73fbbc commit 18e1aecb69897b9533968d4c9f291f3a522ef98f
Showing with 56 additions and 47 deletions.
  1. +53 −46 src/Illuminate/Foundation/Application.php
  2. +3 −1 src/Illuminate/Foundation/changes.json
@@ -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.
*
@@ -27,7 +27,9 @@
{"message": "Cookies should now be accessed via Input::cookie - Cookie::get will continue to work for this release.", "backport": null},
{"message": "When accessing cookies outside of a request context, you will need to decrypt them manually.", "backport": null},
{"message": "When unit testing, the application instance is now refreshed once per test class - not every test.", "backport": null},
{"message": "Added 'whereNotBetween' support to the query builder.", "backport": null}
{"message": "Added 'whereNotBetween' support to the query builder.", "backport": null},
{"message": "Added App::middleware method to inject middlewares onto Stack.", "backport": null},
{"message": "Deprecate 'close' application hooks, Stack middlewares should be used instead.", "backport": null}
],
"4.0.x": [
{"message": "Added implode method to query builder and Collection class.", "backport": null},

0 comments on commit 18e1aec

Please sign in to comment.