Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Split binder in api and http binder
James Colefae7dabbc216
diff --git a/app/Http/Kernel.php b/app/Http/Kernel.phpindex 606e103174..60c9c9776e 100644--- a/app/Http/Kernel.php+++ b/app/Http/Kernel.php@@ -24,8 +24,8 @@ namespace FireflyIII\Http;use FireflyIII\Http\Middleware\Authenticate;use FireflyIII\Http\Middleware\AuthenticateTwoFactor;-use FireflyIII\Http\Middleware\Binder;use FireflyIII\Http\Middleware\EncryptCookies;+use FireflyIII\Http\Middleware\HttpBinder;use FireflyIII\Http\Middleware\IsAdmin;use FireflyIII\Http\Middleware\Range;use FireflyIII\Http\Middleware\RedirectIfAuthenticated;@@ -44,7 +44,8 @@ use Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull;use Illuminate\Foundation\Http\Middleware\ValidatePostSize;use Illuminate\Routing\Middleware\ThrottleRequests;use Illuminate\View\Middleware\ShareErrorsFromSession;-use \Laravel\Passport\Http\Middleware\CreateFreshApiToken;+use Laravel\Passport\Http\Middleware\CreateFreshApiToken;+/*** @codeCoverageIgnore* Class Kernel@@ -95,7 +96,7 @@ class Kernel extends HttpKernelStartFireflySession::class,ShareErrorsFromSession::class,VerifyCsrfToken::class,- Binder::class,+ HttpBinder::class,RedirectIfAuthenticated::class,],// MUST be logged in.@@ -108,7 +109,7 @@ class Kernel extends HttpKernelStartFireflySession::class,ShareErrorsFromSession::class,VerifyCsrfToken::class,- Binder::class,+ HttpBinder::class,Authenticate::class,RedirectIfTwoFactorAuthenticated::class,],@@ -123,7 +124,7 @@ class Kernel extends HttpKernelStartFireflySession::class,ShareErrorsFromSession::class,VerifyCsrfToken::class,- Binder::class,+ HttpBinder::class,Authenticate::class,],@@ -141,7 +142,7 @@ class Kernel extends HttpKernelAuthenticate::class,AuthenticateTwoFactor::class,Range::class,- Binder::class,+ HttpBinder::class,CreateFreshApiToken::class,],// MUST be logged in@@ -160,11 +161,11 @@ class Kernel extends HttpKernelAuthenticateTwoFactor::class,IsAdmin::class,Range::class,- Binder::class,+ HttpBinder::class,CreateFreshApiToken::class,],- 'api' => [+ 'auth:api' => ['throttle:60,1','bindings',],@@ -181,7 +182,7 @@ class Kernel extends HttpKernel= ['auth' => Authenticate::class,'auth.basic' => AuthenticateWithBasicAuth::class,- 'bindings' => Binder::class,+ 'bindings' => HttpBinder::class,'can' => Authorize::class,'guest' => RedirectIfAuthenticated::class,'throttle' => ThrottleRequests::class,diff --git a/app/Http/Middleware/Binder.php b/app/Http/Middleware/ApiBinder.phpsimilarity index 94%rename from app/Http/Middleware/Binder.phprename to app/Http/Middleware/ApiBinder.phpindex 0a7bfc1bda..ff0c844f53 100644--- a/app/Http/Middleware/Binder.php+++ b/app/Http/Middleware/ApiBinder.php@@ -1,7 +1,7 @@<?php/**- * Binder.php- * Copyright (c) 2017 [email protected]+ * ApiBinder.php+ * Copyright (c) 2018 [email protected]** This file is part of Firefly III.*@@ -27,9 +27,9 @@ use FireflyIII\Support\Domain;use Illuminate\Http\Request;/**- * Class Binder.+ * Class ApiBinder*/-class Binder+class ApiBinder{/*** @var arraydiff --git a/app/Http/Middleware/HttpBinder.php b/app/Http/Middleware/HttpBinder.phpnew file mode 100644index 0000000000..7408658bb7--- /dev/null+++ b/app/Http/Middleware/HttpBinder.php@@ -0,0 +1,80 @@+<?php+/**+ * HttpBinder.php+ * Copyright (c) 2018 [email protected]+ *+ * This file is part of Firefly III.+ *+ * Firefly III is free software: you can redistribute it and/or modify+ * it under the terms of the GNU General Public License as published by+ * the Free Software Foundation, either version 3 of the License, or+ * (at your option) any later version.+ *+ * Firefly III is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU General Public License for more details.+ *+ * You should have received a copy of the GNU General Public License+ * along with Firefly III. If not, see <http://www.gnu.org/licenses/>.+ */+declare(strict_types=1);++namespace FireflyIII\Http\Middleware;++use Closure;+use FireflyIII\Support\Domain;+use Illuminate\Http\Request;++/**+ * Class HttpBinder+ */+class HttpBinder+{+ /**+ * @var array+ */+ protected $binders = [];++ /**+ * Binder constructor.+ */+ 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 $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);+ }++ /**+ * @param $key+ * @param $value+ * @param $route+ *+ * @return mixed+ */+ private function performBinding($key, $value, $route)+ {+ $class = $this->binders[$key];++ return $class::routeBinder($value, $route);+ }+}