2019-12-30 22:59:12 +01:00
|
|
|
<?php
|
2021-06-17 09:48:23 +02:00
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2022-04-27 05:20:41 +02:00
|
|
|
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
2021-06-17 09:48:23 +02:00
|
|
|
*
|
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
|
|
|
*/
|
2019-12-04 05:52:04 +01:00
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
|
|
|
use App\Helpers\Mail\GmailTransportManager;
|
2021-06-17 04:57:47 +02:00
|
|
|
use App\Utils\CssInlinerPlugin;
|
2021-02-22 04:39:53 +01:00
|
|
|
use Coconuts\Mail\PostmarkTransport;
|
2021-06-17 04:57:47 +02:00
|
|
|
use GuzzleHttp\Client as HttpClient;
|
2019-12-04 05:52:04 +01:00
|
|
|
use Illuminate\Mail\MailServiceProvider as MailProvider;
|
2021-02-10 12:34:39 +01:00
|
|
|
use Illuminate\Mail\TransportManager;
|
2022-02-20 11:09:20 +01:00
|
|
|
use Illuminate\Container\Container;
|
2019-12-04 05:52:04 +01:00
|
|
|
|
|
|
|
class MailServiceProvider extends MailProvider
|
|
|
|
{
|
2021-02-10 12:06:10 +01:00
|
|
|
|
|
|
|
public function register()
|
|
|
|
{
|
2021-06-17 06:34:01 +02:00
|
|
|
$this->registerIlluminateMailer();
|
2021-02-10 12:06:10 +01:00
|
|
|
}
|
|
|
|
|
2021-04-16 08:54:07 +02:00
|
|
|
public function boot()
|
|
|
|
{
|
2021-06-17 11:06:11 +02:00
|
|
|
app('mail.manager')->getSwiftMailer()->registerPlugin($this->app->make(CssInlinerPlugin::class));
|
2021-04-16 08:54:07 +02:00
|
|
|
}
|
|
|
|
|
2021-02-10 12:34:39 +01:00
|
|
|
protected function registerIlluminateMailer()
|
2019-12-04 05:52:04 +01:00
|
|
|
{
|
2022-02-20 11:09:20 +01:00
|
|
|
// //this is not octane safe
|
2021-04-16 09:16:32 +02:00
|
|
|
$this->app->singleton('mail.manager', function($app) {
|
2021-06-17 10:53:45 +02:00
|
|
|
return new GmailTransportManager($app);
|
2021-02-10 12:34:39 +01:00
|
|
|
});
|
2021-04-16 09:16:32 +02:00
|
|
|
|
2022-02-20 11:09:20 +01:00
|
|
|
|
|
|
|
//this is octane ready - but is untested
|
|
|
|
// $this->app->bind('mail.manager', function ($app){
|
|
|
|
// return new GmailTransportManager($app);
|
|
|
|
// });
|
|
|
|
|
2021-02-10 12:34:39 +01:00
|
|
|
$this->app->bind('mailer', function ($app) {
|
|
|
|
return $app->make('mail.manager')->mailer();
|
2019-12-04 05:52:04 +01:00
|
|
|
});
|
2021-02-10 12:34:39 +01:00
|
|
|
|
2021-06-17 09:48:23 +02:00
|
|
|
$this->app['mail.manager']->extend('cocopostmark', function () {
|
2021-06-17 06:34:01 +02:00
|
|
|
|
2021-06-17 06:29:39 +02:00
|
|
|
return new PostmarkTransport(
|
2021-04-24 17:09:38 +02:00
|
|
|
$this->guzzle(config('postmark.guzzle', [])),
|
|
|
|
config('postmark.secret')
|
|
|
|
);
|
2021-06-17 05:36:23 +02:00
|
|
|
|
2021-04-16 09:16:32 +02:00
|
|
|
});
|
2021-06-17 10:39:09 +02:00
|
|
|
|
2021-02-22 04:39:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function guzzle(array $config): HttpClient
|
|
|
|
{
|
2021-04-24 17:09:38 +02:00
|
|
|
return new HttpClient(array_merge($config, [
|
|
|
|
'base_uri' => empty($config['base_uri'])
|
|
|
|
? 'https://api.postmarkapp.com'
|
|
|
|
: $config['base_uri']
|
|
|
|
]));
|
2021-02-22 04:39:53 +01:00
|
|
|
}
|
2021-04-16 08:54:07 +02:00
|
|
|
|
|
|
|
public function provides()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'mail.manager',
|
2021-06-17 04:57:47 +02:00
|
|
|
'mailer'
|
|
|
|
];
|
2021-04-16 08:54:07 +02:00
|
|
|
}
|
2019-12-30 22:59:12 +01:00
|
|
|
}
|