1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00
invoiceninja/app/Providers/AppServiceProvider.php

155 lines
4.6 KiB
PHP
Raw Normal View History

2018-10-04 19:10:43 +02:00
<?php
2019-05-11 05:32:07 +02:00
/**
* Invoice Ninja (https://invoiceninja.com).
2019-05-11 05:32:07 +02:00
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2023-01-28 23:21:40 +01:00
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
2019-05-11 05:32:07 +02:00
*
2021-06-16 08:58:16 +02:00
* @license https://www.elastic.co/licensing/elastic-license
2019-05-11 05:32:07 +02:00
*/
2018-10-04 19:10:43 +02:00
namespace App\Providers;
use App\Utils\Ninja;
use Livewire\Livewire;
2019-04-20 00:27:37 +02:00
use App\Models\Invoice;
use App\Models\Proposal;
use App\Utils\TruthSource;
2023-01-11 09:29:27 +01:00
use Illuminate\Mail\Mailer;
2022-03-14 21:12:37 +01:00
use Illuminate\Support\Facades\App;
use App\Helpers\Mail\GmailTransport;
2023-10-26 04:57:44 +02:00
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Blade;
2020-08-11 02:48:05 +02:00
use Illuminate\Support\Facades\Queue;
use Illuminate\Support\Facades\Route;
2019-04-20 00:14:52 +02:00
use Illuminate\Support\Facades\Schema;
2018-10-04 19:10:43 +02:00
use Illuminate\Support\ServiceProvider;
use App\Http\Middleware\SetDomainNameDb;
use Illuminate\Queue\Events\JobProcessing;
use App\Helpers\Mail\Office365MailTransport;
use Illuminate\Database\Eloquent\Relations\Relation;
2023-12-21 16:59:39 +01:00
use Symfony\Component\Mailer\Bridge\Brevo\Transport\BrevoTransportFactory;
use Symfony\Component\Mailer\Transport\Dsn;
2018-10-04 19:10:43 +02:00
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
2023-04-27 22:54:45 +02:00
// \DB::listen(function($query) {
// nlog(
// $query->sql,
// [
// 'bindings' => $query->bindings,
// 'time' => $query->time
// ]
// );
// });
2023-01-20 05:17:21 +01:00
// Model::preventLazyLoading(
// !$this->app->isProduction()
// );
/* Defines the name used in polymorphic tables */
Relation::morphMap([
2023-12-18 19:37:13 +01:00
'invoices' => Invoice::class,
2020-10-28 11:10:49 +01:00
'proposals' => Proposal::class,
]);
Blade::if('env', function ($environment) {
return config('ninja.environment') === $environment;
});
2019-04-20 00:14:52 +02:00
/* Sets default varchar length */
2019-04-20 00:14:52 +02:00
Schema::defaultStringLength(191);
2021-05-23 23:53:30 +02:00
/* Handles setting the correct database with livewire classes */
if (Ninja::isHosted()) {
2021-05-23 23:53:30 +02:00
Livewire::addPersistentMiddleware([
SetDomainNameDb::class,
]);
}
Livewire::setUpdateRoute(function ($handle) {
return Route::post('/livewire/update', $handle)
->middleware('client');
});
2022-03-14 21:12:37 +01:00
/* Ensure we don't have stale state in jobs */
Queue::before(function (JobProcessing $event) {
App::forgetInstance('truthsource');
});
/* Always init a new instance everytime the container boots */
app()->instance(TruthSource::class, new TruthSource());
/* Extension for custom mailers */
2022-06-24 15:49:22 +02:00
Mail::extend('gmail', function () {
return new GmailTransport();
});
Mail::extend('office365', function () {
return new Office365MailTransport();
});
2023-01-11 09:29:27 +01:00
Mailer::macro('postmark_config', function (string $postmark_key) {
2023-08-18 13:36:50 +02:00
// @phpstan-ignore /** @phpstan-ignore-next-line **/
2023-01-11 09:29:27 +01:00
Mailer::setSymfonyTransport(app('mail.manager')->createSymfonyTransport([
'transport' => 'postmark',
'token' => $postmark_key
]));
2023-12-18 19:37:13 +01:00
2023-01-11 09:29:27 +01:00
return $this;
});
2023-12-18 19:37:13 +01:00
2023-03-23 03:03:37 +01:00
Mailer::macro('mailgun_config', function (string $secret, string $domain, string $endpoint = 'api.mailgun.net') {
2023-08-18 13:36:50 +02:00
// @phpstan-ignore /** @phpstan-ignore-next-line **/
2023-10-26 04:57:44 +02:00
Mailer::setSymfonyTransport(app('mail.manager')->createSymfonyTransport([
2023-01-11 09:29:27 +01:00
'transport' => 'mailgun',
'secret' => $secret,
'domain' => $domain,
2023-03-23 03:03:37 +01:00
'endpoint' => $endpoint,
2023-01-11 09:29:27 +01:00
'scheme' => config('services.mailgun.scheme'),
]));
2023-12-18 19:37:13 +01:00
return $this;
});
2023-12-21 16:59:39 +01:00
Mail::extend('brevo', function () {
return (new BrevoTransportFactory)->create(
new Dsn(
'brevo+api',
'default',
config('services.brevo.key')
)
);
});
2023-12-21 18:49:04 +01:00
// Mailer::macro('brevo_config', function (string $key) {
// // @phpstan-ignore /** @phpstan-ignore-next-line **/
// Mail::setSymfonyTransport((new BrevoTransportFactory)->create(
// new Dsn(
// 'brevo+api',
// 'default',
// $key
// )
// ));
// return $this;
// });
2023-01-17 13:44:38 +01:00
}
2023-03-24 04:03:58 +01:00
public function register(): void
{
2023-03-24 04:04:46 +01:00
if (Ninja::isHosted()) {
$this->app->register(\App\Providers\BroadcastServiceProvider::class);
}
2023-03-24 04:03:58 +01:00
}
2018-10-04 19:10:43 +02:00
}