From 01468c2663cdf3ebb7d5c77bb5dca4036d22389d Mon Sep 17 00:00:00 2001 From: James Cole Date: Mon, 30 Jan 2017 16:58:10 +0100 Subject: [PATCH] Rewrote journal service provider --- app/Providers/JournalServiceProvider.php | 55 +++++++++++++----------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/app/Providers/JournalServiceProvider.php b/app/Providers/JournalServiceProvider.php index 2ac7f61f64..6f22587325 100644 --- a/app/Providers/JournalServiceProvider.php +++ b/app/Providers/JournalServiceProvider.php @@ -14,7 +14,12 @@ declare(strict_types = 1); namespace FireflyIII\Providers; -use FireflyIII\Exceptions\FireflyException; +use FireflyIII\Helpers\Collector\JournalCollector; +use FireflyIII\Helpers\Collector\JournalCollectorInterface; +use FireflyIII\Repositories\Journal\JournalRepository; +use FireflyIII\Repositories\Journal\JournalRepositoryInterface; +use FireflyIII\Repositories\Journal\JournalTasker; +use FireflyIII\Repositories\Journal\JournalTaskerInterface; use Illuminate\Foundation\Application; use Illuminate\Support\ServiceProvider; @@ -50,16 +55,16 @@ class JournalServiceProvider extends ServiceProvider private function registerCollector() { $this->app->bind( - 'FireflyIII\Helpers\Collector\JournalCollectorInterface', - function (Application $app, array $arguments) { - if (!isset($arguments[0]) && $app->auth->check()) { - return app('FireflyIII\Helpers\Collector\JournalCollector', [auth()->user()]); - } - if (!isset($arguments[0]) && !$app->auth->check()) { - throw new FireflyException('There is no user present.'); + JournalCollectorInterface::class, + function (Application $app) { + /** @var JournalCollectorInterface $collector */ + $collector = app(JournalCollector::class); + + if ($app->auth->check()) { + $collector->setUser(auth()->user()); } - return app('FireflyIII\Helpers\Collector\JournalCollector', $arguments); + return $collector; } ); } @@ -67,16 +72,16 @@ class JournalServiceProvider extends ServiceProvider private function registerRepository() { $this->app->bind( - 'FireflyIII\Repositories\Journal\JournalRepositoryInterface', - function (Application $app, array $arguments) { - if (!isset($arguments[0]) && $app->auth->check()) { - return app('FireflyIII\Repositories\Journal\JournalRepository', [auth()->user()]); - } - if (!isset($arguments[0]) && !$app->auth->check()) { - throw new FireflyException('There is no user present.'); + JournalRepositoryInterface::class, + function (Application $app) { + /** @var JournalRepositoryInterface $repository */ + $repository = app(JournalRepository::class); + if ($app->auth->check()) { + + $repository->setUser(auth()->user()); } - return app('FireflyIII\Repositories\Journal\JournalRepository', $arguments); + return $repository; } ); } @@ -84,16 +89,16 @@ class JournalServiceProvider extends ServiceProvider private function registerTasker() { $this->app->bind( - 'FireflyIII\Repositories\Journal\JournalTaskerInterface', - function (Application $app, array $arguments) { - if (!isset($arguments[0]) && $app->auth->check()) { - return app('FireflyIII\Repositories\Journal\JournalTasker', [auth()->user()]); - } - if (!isset($arguments[0]) && !$app->auth->check()) { - throw new FireflyException('There is no user present.'); + JournalTaskerInterface::class, + function (Application $app) { + /** @var JournalTaskerInterface $tasker */ + $tasker = app(JournalTasker::class); + + if ($app->auth->check()) { + $tasker->setUser(auth()->user()); } - return app('FireflyIII\Repositories\Journal\JournalTasker', $arguments); + return $tasker; } ); }