Rewrote account service provider.

This commit is contained in:
James Cole
2017-01-30 16:59:55 +01:00
parent 01468c2663
commit 355baa7fef

View File

@@ -14,7 +14,10 @@ declare(strict_types = 1);
namespace FireflyIII\Providers; namespace FireflyIII\Providers;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Repositories\Account\AccountRepository;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Account\AccountTasker;
use FireflyIII\Repositories\Account\AccountTaskerInterface;
use Illuminate\Foundation\Application; use Illuminate\Foundation\Application;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
@@ -44,8 +47,6 @@ class AccountServiceProvider extends ServiceProvider
{ {
$this->registerRepository(); $this->registerRepository();
$this->registerTasker(); $this->registerTasker();
} }
/** /**
@@ -54,16 +55,16 @@ class AccountServiceProvider extends ServiceProvider
private function registerRepository() private function registerRepository()
{ {
$this->app->bind( $this->app->bind(
'FireflyIII\Repositories\Account\AccountRepositoryInterface', AccountRepositoryInterface::class,
function (Application $app, array $arguments) { function (Application $app) {
if (!isset($arguments[0]) && $app->auth->check()) { /** @var AccountRepositoryInterface $repository */
return app('FireflyIII\Repositories\Account\AccountRepository', [auth()->user()]); $repository = app(AccountRepository::class);
}
if (!isset($arguments[0]) && !$app->auth->check()) { if ($app->auth->check()) {
throw new FireflyException('There is no user present.'); $repository->setUser(auth()->user());
} }
return app('FireflyIII\Repositories\Account\AccountRepository', $arguments); return $repository;
} }
); );
} }
@@ -74,16 +75,16 @@ class AccountServiceProvider extends ServiceProvider
private function registerTasker() private function registerTasker()
{ {
$this->app->bind( $this->app->bind(
'FireflyIII\Repositories\Account\AccountTaskerInterface', AccountTaskerInterface::class,
function (Application $app, array $arguments) { function (Application $app) {
if (!isset($arguments[0]) && $app->auth->check()) { /** @var AccountTaskerInterface $tasker */
return app('FireflyIII\Repositories\Account\AccountTasker', [auth()->user()]); $tasker = app(AccountTasker::class);
}
if (!isset($arguments[0]) && !$app->auth->check()) { if ($app->auth->check()) {
throw new FireflyException('There is no user present.'); $tasker->setUser(auth()->user());
} }
return app('FireflyIII\Repositories\Account\AccountTasker', $arguments); return $tasker;
} }
); );
} }