mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-28 09:51:21 -06:00
New middleware.
This commit is contained in:
parent
af29b31ea8
commit
d439dceac1
@ -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' => [
|
||||
|
50
app/Http/Middleware/Binder.php
Normal file
50
app/Http/Middleware/Binder.php
Normal 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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user