Use facades.

This commit is contained in:
James Cole
2014-11-21 11:12:22 +01:00
parent ec776bb6eb
commit 3dce194930
22 changed files with 177 additions and 90 deletions

View File

@@ -238,7 +238,7 @@ class Budget implements CUD, CommonDatabaseCalls, BudgetInterface
public function transactionsWithoutBudgetInDateRange(Carbon $start, Carbon $end)
{
// Add expenses that have no budget:
return \Auth::user()->transactionjournals()->whereNotIn(
return $this->getUser()->transactionjournals()->whereNotIn(
'transaction_journals.id', function ($query) use ($start, $end) {
$query->select('transaction_journals.id')->from('transaction_journals')->leftJoin(
'component_transaction_journal', 'component_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id'

View File

@@ -67,9 +67,7 @@ class Recurring implements CUD, CommonDatabaseCalls, RecurringInterface
/*
* Jump to the start of the period.
*/
/** @var \FireflyIII\Shared\Toolkit\Date $toolkit */
$toolkit = \App::make('FireflyIII\Shared\Toolkit\Date');
$date = $toolkit->startOfPeriod($date, $data['repeat_freq']);
$date = DateKit::startOfPeriod($date, $data['repeat_freq']);
$recurring->date = $date;
$recurring->skip = intval($data['skip']);

View File

@@ -407,7 +407,7 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData
// }
$validator = \Validator::make([$model], \Transaction::$rules);
$validator = \Validator::make([$model], \TransactionJournal::$rules);
if ($validator->invalid()) {
$errors->merge($errors);
}

View File

@@ -13,11 +13,9 @@ class Budget
*/
public function storeOrUpdateLimit(\Limit $limit)
{
/** @var \FireflyIII\Shared\Toolkit\Date $dateKit */
$dateKit = \App::make('FireflyIII\Shared\Toolkit\Date');
$end = $dateKit->addPeriod(clone $limit->startdate, $limit->repeat_freq, 0);
$end = DateKit::addPeriod(clone $limit->startdate, $limit->repeat_freq, 0);
$end->subDay();
$set = $limit->limitrepetitions()->where('startdate', $limit->startdate->format('Y-m-d'))->where('enddate', $end->format('Y-m-d'))->get();

View File

@@ -2,6 +2,7 @@
namespace FireflyIII;
use FireflyIII\Shared\Validation\FireflyValidator;
use Illuminate\Foundation\AliasLoader;
use Illuminate\Support\ServiceProvider;
/**
@@ -21,6 +22,16 @@ class FF3ServiceProvider extends ServiceProvider
);
}
/**
* Return the services bla bla.
*
* @return array
*/
public function provides()
{
return ['reminders', 'filters', 'datekit', 'navigation'];
}
/**
* Triggered automatically by Laravel
*/
@@ -29,12 +40,50 @@ class FF3ServiceProvider extends ServiceProvider
// FORMAT:
#$this->app->bind('Interface', 'Class');
$this->app->bind(
'reminders', function () {
return new \FireflyIII\Shared\Toolkit\Reminders;
}
);
$this->app->bind(
'filter', function () {
return new \FireflyIII\Shared\Toolkit\Filter;
}
);
$this->app->bind(
'datekit', function () {
return new \FireflyIII\Shared\Toolkit\Date;
}
);
$this->app->bind(
'navigation', function () {
return new \FireflyIII\Shared\Toolkit\Navigation;
}
);
$this->app->bind(
'ffform', function () {
return new \FireflyIII\Shared\Toolkit\Form;
}
);
// preferences:
$this->app->bind('FireflyIII\Shared\Preferences\PreferencesInterface', 'FireflyIII\Shared\Preferences\Preferences');
// registration and user mail:
$this->app->bind('FireflyIII\Shared\Mail\RegistrationInterface', 'FireflyIII\Shared\Mail\Registration');
// Shortcut so developers don't need to add an Alias in app/config/app.php
$this->app->booting(
function () {
$loader = AliasLoader::getInstance();
$loader->alias('Reminders', 'FireflyIII\Shared\Facade\Reminders');
$loader->alias('Filter', 'FireflyIII\Shared\Facade\Filter');
$loader->alias('DateKit', 'FireflyIII\Shared\Facade\DateKit');
$loader->alias('Navigation', 'FireflyIII\Shared\Facade\Navigation');
$loader->alias('FFForm', 'FireflyIII\Shared\Facade\FFForm');
}
);
}
}

View File

@@ -0,0 +1,16 @@
<?php
namespace FireflyIII\Shared\Facade;
use Illuminate\Support\Facades\Facade;
class DateKit extends Facade
{
protected static function getFacadeAccessor()
{
return 'datekit';
}
}

View File

@@ -0,0 +1,16 @@
<?php
namespace FireflyIII\Shared\Facade;
use Illuminate\Support\Facades\Facade;
class FFForm extends Facade
{
protected static function getFacadeAccessor()
{
return 'ffform';
}
}

View File

@@ -0,0 +1,16 @@
<?php
namespace FireflyIII\Shared\Facade;
use Illuminate\Support\Facades\Facade;
class Filter extends Facade
{
protected static function getFacadeAccessor()
{
return 'filter';
}
}

View File

@@ -0,0 +1,16 @@
<?php
namespace FireflyIII\Shared\Facade;
use Illuminate\Support\Facades\Facade;
class Navigation extends Facade
{
protected static function getFacadeAccessor()
{
return 'navigation';
}
}

View File

@@ -0,0 +1,16 @@
<?php
namespace FireflyIII\Shared\Facade;
use Illuminate\Support\Facades\Facade;
class Reminders extends Facade
{
protected static function getFacadeAccessor()
{
return 'reminders';
}
}

View File

@@ -22,6 +22,7 @@ class Date
*/
public function addPeriod(Carbon $date, $repeatFreq, $skip)
{
// TODO clone the dates so referred date won't be altered.
$add = ($skip + 1);
switch ($repeatFreq) {
default:

View File

@@ -23,9 +23,6 @@ class Reminders
public function amountForReminder(\Reminder $reminder)
{
/** @var \FireflyIII\Shared\Toolkit\Date $dateKit */
$dateKit = \App::make('FireflyIII\Shared\Toolkit\Date');
switch (get_class($reminder->remindersable)) {
case 'Piggybank':
@@ -34,7 +31,7 @@ class Reminders
$reminders = 0;
while ($start <= $end) {
$reminders++;
$start = $dateKit->addPeriod($start, $reminder->remindersable->reminder, $reminder->remindersable->reminder_skip);
$start = DateKit::addPeriod($start, $reminder->remindersable->reminder, $reminder->remindersable->reminder_skip);
}
/*
* Now find amount yet to save.
@@ -49,9 +46,6 @@ class Reminders
throw new FireflyException('Cannot handle class ' . get_class($reminder->remindersable) . ' in amountForReminder.');
break;
}
return 50;
}
/**
@@ -77,10 +71,6 @@ class Reminders
/** @var \FireflyIII\Database\Piggybank $repository */
$repository = \App::make('FireflyIII\Database\Piggybank');
/** @var \FireflyIII\Shared\Toolkit\Date $dateKit */
$dateKit = \App::make('FireflyIII\Shared\Toolkit\Date');
/** @var Collection $piggybanks */
$piggybanks = $repository->get();
$set = $piggybanks->filter(
@@ -100,12 +90,12 @@ class Reminders
*/
/** @var \PiggybankRepetition $repetition */
$repetition = $piggybank->currentRelevantRep();
$start = $dateKit->startOfPeriod(Carbon::now(), $piggybank->reminder);
$start = DateKit::startOfPeriod(Carbon::now(), $piggybank->reminder);
if ($repetition->targetdate && $repetition->targetdate <= Carbon::now()) {
// break when no longer relevant:
continue;
}
$end = $dateKit->endOfPeriod(clone $start, $piggybank->reminder);
$end = DateKit::endOfPeriod(clone $start, $piggybank->reminder);
// should have a reminder for this period:
/** @var \Collection $reminders */
$reminders = $piggybank->reminders()->dateIs($start, $end)->get();