mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Split binder in api and http binder
This commit is contained in:
parent
3a813c30b4
commit
fae7dabbc2
@ -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 HttpKernel
|
||||
StartFireflySession::class,
|
||||
ShareErrorsFromSession::class,
|
||||
VerifyCsrfToken::class,
|
||||
Binder::class,
|
||||
HttpBinder::class,
|
||||
RedirectIfAuthenticated::class,
|
||||
],
|
||||
// MUST be logged in.
|
||||
@ -108,7 +109,7 @@ class Kernel extends HttpKernel
|
||||
StartFireflySession::class,
|
||||
ShareErrorsFromSession::class,
|
||||
VerifyCsrfToken::class,
|
||||
Binder::class,
|
||||
HttpBinder::class,
|
||||
Authenticate::class,
|
||||
RedirectIfTwoFactorAuthenticated::class,
|
||||
],
|
||||
@ -123,7 +124,7 @@ class Kernel extends HttpKernel
|
||||
StartFireflySession::class,
|
||||
ShareErrorsFromSession::class,
|
||||
VerifyCsrfToken::class,
|
||||
Binder::class,
|
||||
HttpBinder::class,
|
||||
Authenticate::class,
|
||||
],
|
||||
|
||||
@ -141,7 +142,7 @@ class Kernel extends HttpKernel
|
||||
Authenticate::class,
|
||||
AuthenticateTwoFactor::class,
|
||||
Range::class,
|
||||
Binder::class,
|
||||
HttpBinder::class,
|
||||
CreateFreshApiToken::class,
|
||||
],
|
||||
// MUST be logged in
|
||||
@ -160,11 +161,11 @@ class Kernel extends HttpKernel
|
||||
AuthenticateTwoFactor::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,
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* Binder.php
|
||||
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
||||
* ApiBinder.php
|
||||
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||
*
|
||||
* 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 array
|
80
app/Http/Middleware/HttpBinder.php
Normal file
80
app/Http/Middleware/HttpBinder.php
Normal file
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/**
|
||||
* HttpBinder.php
|
||||
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||
*
|
||||
* 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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user