Refactor references to static facades. Improve budget controller code.

This commit is contained in:
James Cole
2018-07-14 16:08:34 +02:00
parent b8699422c8
commit 89834baf01
41 changed files with 284 additions and 246 deletions

View File

@@ -27,9 +27,7 @@ use Carbon\Carbon;
use Closure;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use Illuminate\Http\Request;
use Preferences;
use Session;
use View;
/**
* Class SessionFilter.
@@ -68,8 +66,8 @@ class Range
*/
private function configureList(): void
{
$pref = Preferences::get('list-length', config('firefly.list_length', 10))->data;
View::share('listLength', $pref);
$pref = app('preferences')->get('list-length', config('firefly.list_length', 10))->data;
app('view')->share('listLength', $pref);
}
/**
@@ -77,7 +75,7 @@ class Range
*/
private function configureView(): void
{
$pref = Preferences::get('language', config('firefly.default_language', 'en_US'));
$pref = app('preferences')->get('language', config('firefly.default_language', 'en_US'));
/** @noinspection NullPointerExceptionInspection */
$lang = $pref->data;
App::setLocale($lang);
@@ -90,7 +88,7 @@ class Range
// send error to view if could not set money format
if (false === $moneyResult) {
View::share('invalidMonetaryLocale', true); // @codeCoverageIgnore
app('view')->share('invalidMonetaryLocale', true); // @codeCoverageIgnore
}
// save some formats:
@@ -98,9 +96,9 @@ class Range
$dateTimeFormat = (string)trans('config.date_time');
$defaultCurrency = app('amount')->getDefaultCurrency();
View::share('monthAndDayFormat', $monthAndDayFormat);
View::share('dateTimeFormat', $dateTimeFormat);
View::share('defaultCurrency', $defaultCurrency);
app('view')->share('monthAndDayFormat', $monthAndDayFormat);
app('view')->share('dateTimeFormat', $dateTimeFormat);
app('view')->share('defaultCurrency', $defaultCurrency);
}
/**
@@ -122,10 +120,10 @@ class Range
{
// ignore preference. set the range to be the current month:
if (!Session::has('start') && !Session::has('end')) {
$viewRange = Preferences::get('viewRange', '1M')->data;
$viewRange = app('preferences')->get('viewRange', '1M')->data;
if (null === $viewRange) {
$viewRange = '1M';
Preferences::set('viewRange', '1M');
app('preferences')->set('viewRange', '1M');
}
$start = new Carbon;
$start = app('navigation')->updateStartDate($viewRange, $start);

View File

@@ -24,7 +24,6 @@ namespace FireflyIII\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Auth;
use Preferences;
/**
* Class RedirectIfTwoFactorAuthenticated.
@@ -43,9 +42,9 @@ class RedirectIfTwoFactorAuthenticated
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->check()) {
$is2faEnabled = Preferences::get('twoFactorAuthEnabled', false)->data;
$is2faEnabled = app('preferences')->get('twoFactorAuthEnabled', false)->data;
$has2faSecret = null !== Preferences::get('twoFactorAuthSecret');
$has2faSecret = null !== app('preferences')->get('twoFactorAuthSecret');
// grab 2auth information from cookie.
$is2faAuthed = 'true' === $request->cookie('twoFactorAuthenticated');

View File

@@ -30,7 +30,6 @@ use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\User;
use Illuminate\Http\Request;
use Log;
use View;
/**
* Class Sandstorm.
@@ -53,7 +52,7 @@ class Sandstorm
{
// is in Sandstorm environment?
$sandstorm = 1 === (int)getenv('SANDSTORM');
View::share('SANDSTORM', $sandstorm);
app('view')->share('SANDSTORM', $sandstorm);
if (!$sandstorm) {
return $next($request);
}
@@ -76,7 +75,7 @@ class Sandstorm
$user = $repository->first();
/** @noinspection NullPointerExceptionInspection */
Auth::guard($guard)->login($user);
View::share('SANDSTORM_ANON', false);
app('view')->share('SANDSTORM_ANON', false);
return $next($request);
}
@@ -86,7 +85,7 @@ class Sandstorm
$user = User::first();
/** @noinspection NullPointerExceptionInspection */
Auth::guard($guard)->login($user);
View::share('SANDSTORM_ANON', true);
app('view')->share('SANDSTORM_ANON', true);
return $next($request);
}
@@ -108,7 +107,7 @@ class Sandstorm
$repository->attachRole($user, 'owner');
// share value.
View::share('SANDSTORM_ANON', false);
app('view')->share('SANDSTORM_ANON', false);
return $next($request);
}
@@ -124,11 +123,11 @@ class Sandstorm
// if in Sandstorm, user logged in, still must check if user is anon.
$userId = (string)$request->header('X-Sandstorm-User-Id');
if ('' === $userId) {
View::share('SANDSTORM_ANON', true);
app('view')->share('SANDSTORM_ANON', true);
return $next($request);
}
View::share('SANDSTORM_ANON', false);
app('view')->share('SANDSTORM_ANON', false);
return $next($request);
}