firefly-iii/app/Providers/CrudServiceProvider.php

84 lines
2.1 KiB
PHP
Raw Normal View History

<?php
/**
* CrudServiceProvider.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
declare(strict_types = 1);
namespace FireflyIII\Providers;
use FireflyIII\Exceptions\FireflyException;
2016-07-23 14:37:06 -05:00
use Illuminate\Auth\AuthManager;
use Illuminate\Foundation\Application;
use Illuminate\Support\ServiceProvider;
2016-07-23 14:37:06 -05:00
use Log;
/**
* Class CrudServiceProvider
*
* @package FireflyIII\Providers
*/
class CrudServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
//
}
/**
* Register the application services.
*
* @return void
*/
public function register()
{
2016-05-20 04:53:34 -05:00
$this->registerJournal();
$this->registerAccount();
}
private function registerAccount()
{
$this->app->bind(
2016-05-20 04:53:34 -05:00
'FireflyIII\Crud\Account\AccountCrudInterface',
function (Application $app, array $arguments) {
2016-07-23 14:37:06 -05:00
if (!isset($arguments[0]) && auth()->check()) {
return app('FireflyIII\Crud\Account\AccountCrud', [auth()->user()]);
}
if (!isset($arguments[0]) && !$app->auth->check()) {
throw new FireflyException('There is no user present.');
}
2016-05-20 04:53:34 -05:00
return app('FireflyIII\Crud\Account\AccountCrud', $arguments);
}
);
2016-05-20 04:53:34 -05:00
}
2016-05-20 02:25:17 -05:00
2016-05-20 04:53:34 -05:00
private function registerJournal()
{
2016-05-20 02:25:17 -05:00
$this->app->bind(
2016-05-20 04:53:34 -05:00
'FireflyIII\Crud\Split\JournalInterface',
2016-05-20 02:25:17 -05:00
function (Application $app, array $arguments) {
if (!isset($arguments[0]) && $app->auth->check()) {
2016-07-23 14:37:06 -05:00
return app('FireflyIII\Crud\Split\Journal', [auth()->user()]);
2016-05-20 02:25:17 -05:00
}
if (!isset($arguments[0]) && !$app->auth->check()) {
throw new FireflyException('There is no user present.');
}
2016-05-20 04:53:34 -05:00
return app('FireflyIII\Crud\Split\Journal', $arguments);
2016-05-20 02:25:17 -05:00
}
);
2016-05-20 04:53:34 -05:00
}
}