Rewrote journal service provider

This commit is contained in:
James Cole 2017-01-30 16:58:10 +01:00
parent c7341c9194
commit 01468c2663
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E

View File

@ -14,7 +14,12 @@ declare(strict_types = 1);
namespace FireflyIII\Providers; 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\Foundation\Application;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
@ -50,16 +55,16 @@ class JournalServiceProvider extends ServiceProvider
private function registerCollector() private function registerCollector()
{ {
$this->app->bind( $this->app->bind(
'FireflyIII\Helpers\Collector\JournalCollectorInterface', JournalCollectorInterface::class,
function (Application $app, array $arguments) { function (Application $app) {
if (!isset($arguments[0]) && $app->auth->check()) { /** @var JournalCollectorInterface $collector */
return app('FireflyIII\Helpers\Collector\JournalCollector', [auth()->user()]); $collector = app(JournalCollector::class);
}
if (!isset($arguments[0]) && !$app->auth->check()) { if ($app->auth->check()) {
throw new FireflyException('There is no user present.'); $collector->setUser(auth()->user());
} }
return app('FireflyIII\Helpers\Collector\JournalCollector', $arguments); return $collector;
} }
); );
} }
@ -67,16 +72,16 @@ class JournalServiceProvider extends ServiceProvider
private function registerRepository() private function registerRepository()
{ {
$this->app->bind( $this->app->bind(
'FireflyIII\Repositories\Journal\JournalRepositoryInterface', JournalRepositoryInterface::class,
function (Application $app, array $arguments) { function (Application $app) {
if (!isset($arguments[0]) && $app->auth->check()) { /** @var JournalRepositoryInterface $repository */
return app('FireflyIII\Repositories\Journal\JournalRepository', [auth()->user()]); $repository = app(JournalRepository::class);
} if ($app->auth->check()) {
if (!isset($arguments[0]) && !$app->auth->check()) {
throw new FireflyException('There is no user present.'); $repository->setUser(auth()->user());
} }
return app('FireflyIII\Repositories\Journal\JournalRepository', $arguments); return $repository;
} }
); );
} }
@ -84,16 +89,16 @@ class JournalServiceProvider extends ServiceProvider
private function registerTasker() private function registerTasker()
{ {
$this->app->bind( $this->app->bind(
'FireflyIII\Repositories\Journal\JournalTaskerInterface', JournalTaskerInterface::class,
function (Application $app, array $arguments) { function (Application $app) {
if (!isset($arguments[0]) && $app->auth->check()) { /** @var JournalTaskerInterface $tasker */
return app('FireflyIII\Repositories\Journal\JournalTasker', [auth()->user()]); $tasker = app(JournalTasker::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\Journal\JournalTasker', $arguments); return $tasker;
} }
); );
} }