HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: /home/xedaptot/ai.naniguide.com/app/Providers/MailerServiceProvider.php
<?php

namespace App\Providers;

use App\Model\SendingServer;
use App\Model\Setting;
use Illuminate\Contracts\Support\DeferrableProvider;
use Illuminate\Support\ServiceProvider;

/**
 * Wave F: legacy `SendingServerSmtp::instantiateFromSettings` /
 * `SendingServerSendmail::instantiateFromSettings` static factories were
 * removed with the STI tree. The `xmailer` binding now constructs an
 * in-memory SendingServer with type + config JSON; vendor logic resolves
 * via `$server->driver()` which DriverRegistry hands the right driver.
 */
class MailerServiceProvider extends ServiceProvider implements DeferrableProvider
{
    public function boot()
    {
        //
    }

    public function register()
    {
        $this->app->bind('xmailer', function ($app) {
            $mailer = Setting::get('mailer.mailer') ?: Setting::get('mailer.driver');

            $server = new SendingServer();
            $fromName = Setting::get('mailer.from.name') ?? config('mail.from.name');
            $fromAddress = Setting::get('mailer.from.address') ?? config('mail.from.address');

            switch ($mailer) {
                case SendingServer::TYPE_SMTP:
                    $server->type = SendingServer::TYPE_SMTP;
                    $server->setConfigMany([
                        'host' => Setting::get('mailer.host') ?? config('mail.host'),
                        'smtp_port' => Setting::get('mailer.port') ?? config('mail.port'),
                        'smtp_protocol' => Setting::get('mailer.encryption') ?? config('mail.encryption'),
                        'smtp_username' => Setting::get('mailer.username') ?? config('mail.username'),
                        'smtp_password' => Setting::get('mailer.password') ?? config('mail.password'),
                    ]);
                    break;

                case SendingServer::TYPE_SENDMAIL:
                    $server->type = SendingServer::TYPE_SENDMAIL;
                    $server->setConfigMany([
                        'sendmail_path' => Setting::get('mailer.sendmail_path') ?? config('mail.sendmail'),
                    ]);
                    break;

                case SendingServer::TYPE_SENDGRID_API:
                    $server->type = SendingServer::TYPE_SENDGRID_API;
                    $server->setConfigMany([
                        'api_key' => Setting::get('mailer.sendgrid_api_key'),
                    ]);
                    break;

                case SendingServer::TYPE_AMAZON_API:
                    $server->type = SendingServer::TYPE_AMAZON_API;
                    $server->setConfigMany([
                        'aws_access_key_id'     => Setting::get('mailer.aws_access_key_id'),
                        'aws_secret_access_key' => Setting::get('mailer.aws_secret_access_key'),
                        'aws_region'            => Setting::get('mailer.aws_region'),
                    ]);
                    break;

                default:
                    throw new \LogicException("Mail mailer '{$mailer}' not found");
            }

            $server->from_name = $fromName;
            $server->from_address = $fromAddress;

            return $server;
        });
    }

    public function provides()
    {
        return ['xmailer'];
    }
}