Rewrote bill service provider

This commit is contained in:
James Cole 2017-01-30 17:10:08 +01:00
parent 2c786e6a38
commit 3aaf356054
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E

View File

@ -14,7 +14,8 @@ declare(strict_types = 1);
namespace FireflyIII\Providers; namespace FireflyIII\Providers;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Repositories\Bill\BillRepository;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use Illuminate\Foundation\Application; use Illuminate\Foundation\Application;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
@ -43,16 +44,16 @@ class BillServiceProvider extends ServiceProvider
public function register() public function register()
{ {
$this->app->bind( $this->app->bind(
'FireflyIII\Repositories\Bill\BillRepositoryInterface', BillRepositoryInterface::class,
function (Application $app, array $arguments) { function (Application $app) {
if (!isset($arguments[0]) && $app->auth->check()) { /** @var BillRepositoryInterface $repository */
return app('FireflyIII\Repositories\Bill\BillRepository', [auth()->user()]); $repository = app(BillRepository::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\Bill\BillRepository', $arguments); return $repository;
} }
); );
} }