mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Rewrote journal service provider
This commit is contained in:
parent
c7341c9194
commit
01468c2663
@ -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;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user