New middleware.

This commit is contained in:
James Cole 2016-01-09 15:39:02 +01:00
parent af29b31ea8
commit d439dceac1
2 changed files with 52 additions and 0 deletions

View File

@ -3,6 +3,7 @@
namespace FireflyIII\Http;
use FireflyIII\Http\Middleware\Authenticate;
use FireflyIII\Http\Middleware\Binder;
use FireflyIII\Http\Middleware\EncryptCookies;
use FireflyIII\Http\Middleware\Range;
use FireflyIII\Http\Middleware\RedirectIfAuthenticated;
@ -64,6 +65,7 @@ class Kernel extends HttpKernel
VerifyCsrfToken::class,
Authenticate::class,
Range::class,
Binder::class,
],
'api' => [

View File

@ -0,0 +1,50 @@
<?php
namespace FireflyIII\Http\Middleware;
use Closure;
use FireflyIII\Support\Domain;
class Binder
{
protected $binders = [];
public function __construct()
{
$this->binders = Domain::getBindables();
}
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
*
* @return mixed
*/
public function handle($request, Closure $next)
{
foreach ($request->route()->parameters() as $key => $value) {
if (isset($this->binders[$key])) {
$boundObject = $this->performBinding($key, $value, $request->route());
$request->route()->setParameter($key, $boundObject);
}
}
return $next($request);
//return $next($request);
}
/**
* @param $key
* @param $value
* @param $route
*
* @return mixed
*/
private function performBinding($key, $value, $route)
{
return $this->binders[$key]::routeBinder($value, $route);
}
}