From d439dceac14060287cef7e00f197b6a7c759a6a0 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 9 Jan 2016 15:39:02 +0100 Subject: [PATCH] New middleware. --- app/Http/Kernel.php | 2 ++ app/Http/Middleware/Binder.php | 50 ++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 app/Http/Middleware/Binder.php diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 32625a3528..3c1c958dec 100755 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -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' => [ diff --git a/app/Http/Middleware/Binder.php b/app/Http/Middleware/Binder.php new file mode 100644 index 0000000000..3d13b49de5 --- /dev/null +++ b/app/Http/Middleware/Binder.php @@ -0,0 +1,50 @@ +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); + } +}