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

233 lines
7.9 KiB
PHP
Raw Normal View History

2015-02-06 20:43:19 +01:00
<?php
2022-12-29 19:42:26 +01:00
/**
* FireflyServiceProvider.php
2020-02-16 13:55:52 +01:00
* Copyright (c) 2019 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
2017-10-21 08:40:00 +02:00
*
* This program is distributed in the hope that it will be useful,
2017-10-21 08:40:00 +02:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
2017-10-21 08:40:00 +02:00
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://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;
2017-02-02 07:35:53 +01:00
use FireflyIII\Generator\Chart\Basic\ChartJsGenerator;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Generator\Webhook\MessageGeneratorInterface;
use FireflyIII\Generator\Webhook\StandardMessageGenerator;
2017-02-02 07:35:53 +01:00
use FireflyIII\Helpers\Attachments\AttachmentHelper;
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
2019-06-21 19:10:02 +02:00
use FireflyIII\Helpers\Fiscal\FiscalHelper;
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
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;
use FireflyIII\Helpers\Webhook\Sha3SignatureGenerator;
use FireflyIII\Helpers\Webhook\SignatureGeneratorInterface;
2022-10-02 14:37:50 +02:00
use FireflyIII\Repositories\AuditLogEntry\ALERepository;
use FireflyIII\Repositories\AuditLogEntry\ALERepositoryInterface;
2020-06-07 11:31:01 +02:00
use FireflyIII\Repositories\ObjectGroup\ObjectGroupRepository;
use FireflyIII\Repositories\ObjectGroup\ObjectGroupRepositoryInterface;
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;
2020-11-29 18:35:49 +01:00
use FireflyIII\Repositories\Webhook\WebhookRepository;
use FireflyIII\Repositories\Webhook\WebhookRepositoryInterface;
use FireflyIII\Services\FireflyIIIOrg\Update\UpdateRequest;
use FireflyIII\Services\FireflyIIIOrg\Update\UpdateRequestInterface;
2020-04-11 06:42:40 +02:00
use FireflyIII\Services\Password\PwndVerifierV2;
2017-08-04 15:48:26 +02:00
use FireflyIII\Services\Password\Verifier;
use FireflyIII\Services\Webhook\StandardWebhookSender;
use FireflyIII\Services\Webhook\WebhookSenderInterface;
2015-02-11 07:35:10 +01:00
use FireflyIII\Support\Amount;
2019-08-10 16:50:37 +02:00
use FireflyIII\Support\ExpandedForm;
2019-08-17 10:47:29 +02:00
use FireflyIII\Support\FireflyConfig;
use FireflyIII\Support\Form\AccountForm;
2019-08-10 16:50:37 +02:00
use FireflyIII\Support\Form\CurrencyForm;
use FireflyIII\Support\Form\PiggyBankForm;
use FireflyIII\Support\Form\RuleForm;
2015-02-11 07:35:10 +01:00
use FireflyIII\Support\Navigation;
use FireflyIII\Support\Preferences;
use FireflyIII\Support\Steam;
use FireflyIII\TransactionRules\Engine\RuleEngineInterface;
use FireflyIII\TransactionRules\Engine\SearchRuleEngine;
2015-02-11 07:35:10 +01:00
use FireflyIII\Validation\FireflyValidator;
2020-06-20 10:22:07 +02:00
use Illuminate\Foundation\Application;
2015-02-06 20:43:19 +01:00
use Illuminate\Support\ServiceProvider;
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
*
2019-08-17 10:47:29 +02:00
*
*/
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(
2019-12-28 09:44:56 +01:00
static function ($translator, $data, $rules, $messages) {
2015-02-11 07:35:10 +01:00
return new FireflyValidator($translator, $data, $rules, $messages);
}
);
}
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
*
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',
2020-03-13 08:02:38 +01:00
static function () {
2022-10-30 14:24:28 +01:00
return new Preferences();
2017-11-15 10:52:29 +01:00
}
2015-02-06 20:43:19 +01:00
);
$this->app->bind(
2017-11-15 10:52:29 +01:00
'fireflyconfig',
2020-03-13 08:02:38 +01:00
static function () {
2022-10-30 14:24:28 +01:00
return new FireflyConfig();
2017-11-15 10:52:29 +01:00
}
);
2015-02-06 21:23:14 +01:00
$this->app->bind(
2017-11-15 10:52:29 +01:00
'navigation',
2020-03-13 08:02:38 +01:00
static function () {
2022-10-30 14:24:28 +01:00
return new Navigation();
2017-11-15 10:52:29 +01:00
}
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',
2020-03-13 08:02:38 +01:00
static function () {
2022-10-30 14:24:28 +01:00
return new Amount();
2017-11-15 10:52:29 +01:00
}
2015-02-07 06:49:24 +01:00
);
$this->app->bind(
2017-11-15 10:52:29 +01:00
'steam',
2020-03-13 08:02:38 +01:00
static function () {
2022-10-30 14:24:28 +01:00
return new Steam();
2017-11-15 10:52:29 +01:00
}
);
$this->app->bind(
2017-11-15 10:52:29 +01:00
'expandedform',
2019-08-10 16:50:37 +02:00
static function () {
2022-10-30 14:24:28 +01:00
return new ExpandedForm();
2017-11-15 10:52:29 +01:00
}
);
2015-02-09 07:23:39 +01:00
$this->app->bind(
'accountform',
static function () {
2022-10-30 14:24:28 +01:00
return new AccountForm();
}
);
2019-08-10 16:50:37 +02:00
$this->app->bind(
'currencyform',
static function () {
2022-10-30 14:24:28 +01:00
return new CurrencyForm();
2019-08-10 16:50:37 +02:00
}
);
$this->app->bind(
'piggybankform',
static function () {
2022-10-30 14:24:28 +01:00
return new PiggyBankForm();
2019-08-10 16:50:37 +02:00
}
);
$this->app->bind(
'ruleform',
static function () {
2022-10-30 14:24:28 +01:00
return new RuleForm();
2019-08-10 16:50:37 +02: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:25:46 +01:00
// other generators
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);
2020-06-20 10:22:07 +02:00
2017-02-02 07:35:53 +01:00
$this->app->bind(AttachmentHelperInterface::class, AttachmentHelper::class);
2022-10-02 14:37:50 +02:00
$this->app->bind(ALERepositoryInterface::class, ALERepository::class);
2020-06-20 10:22:07 +02:00
$this->app->bind(
ObjectGroupRepositoryInterface::class,
static function (Application $app) {
/** @var ObjectGroupRepository $repository */
$repository = app(ObjectGroupRepository::class);
2022-12-31 13:32:42 +01:00
if ($app->auth->check()) { // @phpstan-ignore-line (phpstan does not understand the reference to auth)
2020-06-20 10:22:07 +02:00
$repository->setUser(auth()->user());
}
return $repository;
}
);
2020-11-29 18:35:49 +01:00
$this->app->bind(
WebhookRepositoryInterface::class,
static function (Application $app) {
/** @var WebhookRepository $repository */
$repository = app(WebhookRepository::class);
2022-12-31 13:32:42 +01:00
if ($app->auth->check()) { // @phpstan-ignore-line (phpstan does not understand the reference to auth)
2020-11-29 18:35:49 +01:00
$repository->setUser(auth()->user());
}
return $repository;
}
);
$this->app->bind(
RuleEngineInterface::class,
static function (Application $app) {
/** @var SearchRuleEngine $engine */
$engine = app(SearchRuleEngine::class);
2022-12-31 13:32:42 +01:00
if ($app->auth->check()) { // @phpstan-ignore-line (phpstan does not understand the reference to auth)
$engine->setUser(auth()->user());
}
return $engine;
}
);
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(ReportHelperInterface::class, ReportHelper::class);
2017-02-17 06:42:36 +01:00
$this->app->bind(FiscalHelperInterface::class, FiscalHelper::class);
$this->app->bind(UpdateRequestInterface::class, UpdateRequest::class);
// webhooks:
$this->app->bind(MessageGeneratorInterface::class, StandardMessageGenerator::class);
2021-03-21 09:15:40 +01:00
$this->app->bind(SignatureGeneratorInterface::class, Sha3SignatureGenerator::class);
$this->app->bind(WebhookSenderInterface::class, StandardWebhookSender::class);
2017-08-04 15:46:52 +02:00
// password verifier thing
2020-04-11 06:42:40 +02:00
$this->app->bind(Verifier::class, PwndVerifierV2::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
}