Files
firefly-iii/app/Providers/FireflyServiceProvider.php

209 lines
7.4 KiB
PHP
Raw Normal View History

2015-02-06 20:43:19 +01:00
<?php
/**
* FireflyServiceProvider.php
2017-10-21 08:40:00 +02:00
* Copyright (c) 2017 thegrumpydictator@gmail.com
*
2017-10-21 08:40:00 +02:00
* This file is part of Firefly III.
*
2017-10-21 08:40:00 +02:00
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2017-12-17 14:44:05 +01:00
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
2017-03-29 21:20:54 +02:00
declare(strict_types=1);
2015-02-06 20:43:19 +01:00
namespace FireflyIII\Providers;
2019-02-13 17:38:41 +01:00
use FireflyIII\Exceptions\FireflyException;
2017-08-18 15:32:11 +02:00
use FireflyIII\Export\ExpandedProcessor;
2017-02-02 07:35:53 +01:00
use FireflyIII\Export\ProcessorInterface;
use FireflyIII\Generator\Chart\Basic\ChartJsGenerator;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Helpers\Attachments\AttachmentHelper;
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
use FireflyIII\Helpers\Chart\MetaPieChart;
use FireflyIII\Helpers\Chart\MetaPieChartInterface;
use FireflyIII\Helpers\FiscalHelper;
use FireflyIII\Helpers\FiscalHelperInterface;
use FireflyIII\Helpers\Help\Help;
use FireflyIII\Helpers\Help\HelpInterface;
use FireflyIII\Helpers\Report\BalanceReportHelper;
use FireflyIII\Helpers\Report\BalanceReportHelperInterface;
use FireflyIII\Helpers\Report\BudgetReportHelper;
use FireflyIII\Helpers\Report\BudgetReportHelperInterface;
use FireflyIII\Helpers\Report\NetWorth;
use FireflyIII\Helpers\Report\NetWorthInterface;
2017-03-29 21:20:54 +02:00
use FireflyIII\Helpers\Report\PopupReport;
use FireflyIII\Helpers\Report\PopupReportInterface;
2017-02-02 07:35:53 +01:00
use FireflyIII\Helpers\Report\ReportHelper;
use FireflyIII\Helpers\Report\ReportHelperInterface;
2019-03-08 05:47:51 +01:00
use FireflyIII\Repositories\TransactionType\TransactionTypeRepository;
use FireflyIII\Repositories\TransactionType\TransactionTypeRepositoryInterface;
2017-02-02 07:35:53 +01:00
use FireflyIII\Repositories\User\UserRepository;
use FireflyIII\Repositories\User\UserRepositoryInterface;
2018-03-25 09:00:45 +02:00
use FireflyIII\Services\Currency\ExchangeRateInterface;
use FireflyIII\Services\IP\IpifyOrg;
use FireflyIII\Services\IP\IPRetrievalInterface;
2018-03-08 20:44:56 +01:00
use FireflyIII\Services\Password\PwndVerifierV2;
2017-08-04 15:48:26 +02:00
use FireflyIII\Services\Password\Verifier;
2015-02-11 07:35:10 +01:00
use FireflyIII\Support\Amount;
use FireflyIII\Support\ExpandedForm;
use FireflyIII\Support\FireflyConfig;
2015-02-11 07:35:10 +01:00
use FireflyIII\Support\Navigation;
use FireflyIII\Support\Preferences;
use FireflyIII\Support\Steam;
use FireflyIII\Support\Twig\AmountFormat;
use FireflyIII\Support\Twig\Extension\TransactionGroupTwig;
2015-05-01 22:44:35 +02:00
use FireflyIII\Support\Twig\General;
2015-05-02 11:32:45 +02:00
use FireflyIII\Support\Twig\Journal;
2018-04-16 20:21:28 +02:00
use FireflyIII\Support\Twig\Loader\AccountLoader;
use FireflyIII\Support\Twig\Loader\TransactionGroupLoader;
use FireflyIII\Support\Twig\Loader\TransactionJournalLoader;
use FireflyIII\Support\Twig\Loader\TransactionLoader;
2016-01-15 08:10:22 +01:00
use FireflyIII\Support\Twig\Rule;
use FireflyIII\Support\Twig\Transaction;
2016-10-10 07:49:55 +02:00
use FireflyIII\Support\Twig\Translation;
2015-02-11 07:35:10 +01:00
use FireflyIII\Validation\FireflyValidator;
2017-06-05 11:12:50 +02:00
use Illuminate\Foundation\Application;
2015-02-06 20:43:19 +01:00
use Illuminate\Support\ServiceProvider;
2015-05-01 08:29:41 +02:00
use Twig;
use Validator;
2015-02-06 20:43:19 +01:00
/**
2018-07-22 18:50:27 +02:00
*
2017-11-15 12:25:49 +01:00
* Class FireflyServiceProvider.
2018-07-22 18:50:27 +02:00
*
* @codeCoverageIgnore
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
2015-02-06 20:43:19 +01:00
class FireflyServiceProvider extends ServiceProvider
{
2017-12-22 18:32:43 +01:00
/**
* Start provider.
*/
2018-07-22 18:50:27 +02:00
public function boot(): void
2015-02-11 07:35:10 +01:00
{
Validator::resolver(
2018-07-22 18:50:27 +02:00
/** @noinspection MoreThanThreeArgumentsInspection */
2015-06-06 23:09:12 +02:00
function ($translator, $data, $rules, $messages) {
2015-02-11 07:35:10 +01:00
return new FireflyValidator($translator, $data, $rules, $messages);
}
);
2015-07-07 19:09:45 +02:00
$config = app('config');
2019-03-02 20:14:45 +01:00
//Twig::addExtension(new Functions($config));
//Twig::addRuntimeLoader(new TransactionLoader);
//Twig::addRuntimeLoader(new AccountLoader);
//Twig::addRuntimeLoader(new TransactionJournalLoader);
//Twig::addRuntimeLoader(new TransactionGroupLoader);
2015-05-01 22:44:35 +02:00
Twig::addExtension(new General);
Twig::addExtension(new TransactionGroupTwig);
//Twig::addExtension(new Journal);
2015-05-09 22:42:45 +02:00
Twig::addExtension(new Translation);
//Twig::addExtension(new Transaction);
//Twig::addExtension(new Rule);
Twig::addExtension(new AmountFormat);
2019-03-02 20:14:45 +01:00
//Twig::addExtension(new Twig_Extension_Debug);
}
2015-02-11 07:35:10 +01:00
2015-05-17 10:30:18 +02:00
/**
2017-12-22 18:32:43 +01:00
* Register stuff.
2018-07-22 18:50:27 +02:00
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
2015-05-17 10:30:18 +02:00
*/
2018-07-22 18:50:27 +02:00
public function register(): void
2015-02-06 20:43:19 +01:00
{
$this->app->bind(
2017-11-15 10:52:29 +01:00
'preferences',
function () {
return new Preferences;
}
2015-02-06 20:43:19 +01:00
);
$this->app->bind(
2017-11-15 10:52:29 +01:00
'fireflyconfig',
function () {
return new FireflyConfig;
}
);
2015-02-06 21:23:14 +01:00
$this->app->bind(
2017-11-15 10:52:29 +01:00
'navigation',
function () {
return new Navigation;
}
2015-02-06 21:23:14 +01:00
);
2015-02-07 06:49:24 +01:00
$this->app->bind(
2017-11-15 10:52:29 +01:00
'amount',
function () {
return new Amount;
}
2015-02-07 06:49:24 +01:00
);
$this->app->bind(
2017-11-15 10:52:29 +01:00
'steam',
function () {
return new Steam;
}
);
$this->app->bind(
2017-11-15 10:52:29 +01:00
'expandedform',
function () {
return new ExpandedForm;
}
);
2015-02-09 07:23:39 +01:00
2016-12-11 16:02:04 +01:00
// chart generator:
2017-02-02 07:35:53 +01:00
$this->app->bind(GeneratorInterface::class, ChartJsGenerator::class);
2016-12-11 16:02:04 +01:00
// chart builder
2017-04-29 08:55:37 +02:00
$this->app->bind(
MetaPieChartInterface::class,
function (Application $app) {
/** @var MetaPieChart $chart */
$chart = app(MetaPieChart::class);
if ($app->auth->check()) {
$chart->setUser(auth()->user());
}
return $chart;
}
);
2016-12-11 16:25:46 +01:00
// other generators
2017-08-18 15:32:11 +02:00
// export:
$this->app->bind(ProcessorInterface::class, ExpandedProcessor::class);
2017-02-02 07:35:53 +01:00
$this->app->bind(UserRepositoryInterface::class, UserRepository::class);
2019-03-08 05:47:51 +01:00
$this->app->bind(TransactionTypeRepositoryInterface::class, TransactionTypeRepository::class);
2017-02-02 07:35:53 +01:00
$this->app->bind(AttachmentHelperInterface::class, AttachmentHelper::class);
2016-12-25 12:55:22 +01:00
2017-03-29 21:20:54 +02:00
// more generators:
$this->app->bind(PopupReportInterface::class, PopupReport::class);
2017-02-02 07:35:53 +01:00
$this->app->bind(HelpInterface::class, Help::class);
$this->app->bind(ReportHelperInterface::class, ReportHelper::class);
2017-02-17 06:42:36 +01:00
$this->app->bind(FiscalHelperInterface::class, FiscalHelper::class);
2017-02-02 07:35:53 +01:00
$this->app->bind(BalanceReportHelperInterface::class, BalanceReportHelper::class);
$this->app->bind(BudgetReportHelperInterface::class, BudgetReportHelper::class);
$class = (string)config(sprintf('firefly.cer_providers.%s', (string)config('firefly.cer_provider')));
2019-02-13 17:38:41 +01:00
if ('' === $class) {
throw new FireflyException('Invalid currency exchange rate provider. Cannot continue.');
}
$this->app->bind(ExchangeRateInterface::class, $class);
2017-08-04 15:46:52 +02:00
// password verifier thing
2018-03-08 20:44:56 +01:00
$this->app->bind(Verifier::class, PwndVerifierV2::class);
// IP thing:
$this->app->bind(IPRetrievalInterface::class, IpifyOrg::class);
// net worth thing.
$this->app->bind(NetWorthInterface::class, NetWorth::class);
2015-02-06 20:43:19 +01:00
}
2015-03-29 08:14:32 +02:00
}