Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
98.43% |
125 / 127 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| MailModuleServiceProvider | |
98.41% |
124 / 126 |
|
50.00% |
1 / 2 |
4 | |
0.00% |
0 / 1 |
| getDefinitions | |
98.40% |
123 / 125 |
|
0.00% |
0 / 1 |
3 | |||
| getExtensions | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** @license For full copyright and license information, please see the LICENSE.md file. */ |
| 6 | |
| 7 | namespace App\Modules\Mail\Config; |
| 8 | |
| 9 | defined('AMMONLY_APP') || exit('Direct script access is forbidden.'); |
| 10 | |
| 11 | use App\Core\Engine\Domain\Repository\RecordCoOwnerRepositoryInterface; |
| 12 | use App\Core\Engine\Infrastructure\Repository\SqlRecordCoOwnerRepository; |
| 13 | use App\Core\Security\Encryption\EncryptionServiceInterface; |
| 14 | use App\Modules\Integrations\Application\Service\EmailSecurityScanner; |
| 15 | use App\Modules\Mail\Application\Contract\EmailContextAssociationServiceInterface; |
| 16 | use App\Modules\Mail\Application\Service\EmailContextAssociationService; |
| 17 | use App\Modules\Mail\Application\Service\InboundEmailSyncService; |
| 18 | use App\Modules\Mail\Application\Service\MailDateFormatService; |
| 19 | use App\Modules\Mail\Application\Service\MailHtmlSanitizer; |
| 20 | use App\Modules\Mail\Application\Service\MailSenderService; |
| 21 | use App\Modules\Mail\Application\Service\MailTemplateRenderer; |
| 22 | use App\Modules\Mail\Task\InboundEmailSyncTask; |
| 23 | use App\Modules\Mail\Application\Service\MimeDecoderService; |
| 24 | use App\Modules\Mail\Application\Service\WebmailAuthService; |
| 25 | use App\Modules\Mail\Application\Service\WebmailFolderService; |
| 26 | use App\Modules\Mail\Application\Service\WebmailMessageService; |
| 27 | use App\Modules\Mail\Application\Service\WebmailSenderService; |
| 28 | use App\Modules\Mail\Application\Service\WebmailSyncService; |
| 29 | use App\Modules\Mail\Domain\Contract\MailHtmlSanitizerInterface; |
| 30 | use App\Modules\Mail\Domain\Contract\MailProtocolDriverRegistryInterface; |
| 31 | use App\Modules\Mail\Domain\Contract\MimeDecoderInterface; |
| 32 | use App\Modules\Mail\Domain\Contract\WebmailSenderServiceInterface; |
| 33 | use App\Modules\Mail\Domain\Repository\MailRepositoryInterface; |
| 34 | use App\Modules\Mail\Infrastructure\Protocol\MailProtocolDriverRegistry; |
| 35 | use App\Modules\Mail\Infrastructure\Repository\SqlMailRepository; |
| 36 | use App\Modules\Mail\Presentation\Api\MailApiController; |
| 37 | use App\Modules\Mail\Presentation\Api\WebmailApiController; |
| 38 | use App\Modules\Mail\Presentation\Api\WebmailEventsApiController; |
| 39 | use App\Modules\Mail\Presentation\Htmx\WebmailHtmxController; |
| 40 | use App\Modules\Mail\Presentation\Web\WebmailWebController; |
| 41 | use App\Modules\User\Infrastructure\Repository\SqlUserRepository; |
| 42 | use Nyholm\Psr7\Factory\Psr17Factory; |
| 43 | use PDO; |
| 44 | use Psr\Container\ContainerInterface; |
| 45 | use Psr\EventDispatcher\EventDispatcherInterface; |
| 46 | use Twig\Environment as TwigEnvironment; |
| 47 | use Yiisoft\Cache\CacheInterface; |
| 48 | use Yiisoft\Di\ServiceProviderInterface; |
| 49 | use Yiisoft\User\CurrentUser; |
| 50 | |
| 51 | /** |
| 52 | * MailModuleServiceProvider. |
| 53 | * |
| 54 | * Configures DI container definitions for Webmail, protocol drivers, sanitizers, and controllers. |
| 55 | * |
| 56 | * @package App\Modules\Mail\Config |
| 57 | */ |
| 58 | final class MailModuleServiceProvider implements ServiceProviderInterface |
| 59 | { |
| 60 | /** |
| 61 | * @return array<string, mixed> Definitions mapping for PSR-11 container. |
| 62 | */ |
| 63 | public function getDefinitions(): array |
| 64 | { |
| 65 | return [ |
| 66 | SqlMailRepository::class => static fn(PDO $pdo): SqlMailRepository => new SqlMailRepository($pdo), |
| 67 | MailRepositoryInterface::class => static fn(SqlMailRepository $r): MailRepositoryInterface => $r, |
| 68 | MailTemplateRenderer::class => static fn(): MailTemplateRenderer => new MailTemplateRenderer(), |
| 69 | |
| 70 | RecordCoOwnerRepositoryInterface::class => static fn( |
| 71 | PDO $pdo |
| 72 | ): RecordCoOwnerRepositoryInterface => new SqlRecordCoOwnerRepository($pdo), |
| 73 | |
| 74 | MimeDecoderInterface::class => static fn(): MimeDecoderInterface => new MimeDecoderService(), |
| 75 | MailHtmlSanitizerInterface::class => static fn(): MailHtmlSanitizerInterface => new MailHtmlSanitizer(), |
| 76 | |
| 77 | MailProtocolDriverRegistryInterface::class => static fn( |
| 78 | ): MailProtocolDriverRegistryInterface => new MailProtocolDriverRegistry(), |
| 79 | |
| 80 | WebmailAuthService::class => static fn( |
| 81 | PDO $pdo, |
| 82 | SqlMailRepository $repo, |
| 83 | RecordCoOwnerRepositoryInterface $coOwners, |
| 84 | EncryptionServiceInterface $enc, |
| 85 | MailProtocolDriverRegistryInterface $registry |
| 86 | ): WebmailAuthService => new WebmailAuthService($pdo, $repo, $coOwners, $enc, $registry), |
| 87 | |
| 88 | WebmailFolderService::class => static fn( |
| 89 | PDO $pdo, |
| 90 | SqlMailRepository $repo, |
| 91 | WebmailAuthService $auth, |
| 92 | EncryptionServiceInterface $enc, |
| 93 | MailProtocolDriverRegistryInterface $registry, |
| 94 | CacheInterface $cache |
| 95 | ): WebmailFolderService => new WebmailFolderService($pdo, $repo, $auth, $enc, $registry, $cache), |
| 96 | |
| 97 | MailDateFormatService::class => static fn( |
| 98 | ): MailDateFormatService => new MailDateFormatService(), |
| 99 | |
| 100 | WebmailMessageService::class => static fn( |
| 101 | ContainerInterface $c |
| 102 | ): WebmailMessageService => new WebmailMessageService( |
| 103 | $c->get(SqlMailRepository::class), |
| 104 | $c->get(RecordCoOwnerRepositoryInterface::class), |
| 105 | $c->get(EncryptionServiceInterface::class), |
| 106 | $c->get(MailProtocolDriverRegistryInterface::class), |
| 107 | $c->get(MailHtmlSanitizerInterface::class), |
| 108 | $c->get(MailDateFormatService::class), |
| 109 | $c->get(SqlUserRepository::class), |
| 110 | $c->get(CacheInterface::class) |
| 111 | ), |
| 112 | |
| 113 | WebmailSenderService::class => static fn( |
| 114 | SqlMailRepository $repo, |
| 115 | RecordCoOwnerRepositoryInterface $coOwners, |
| 116 | EncryptionServiceInterface $enc, |
| 117 | MailProtocolDriverRegistryInterface $registry |
| 118 | ): WebmailSenderService => new WebmailSenderService($repo, $coOwners, $enc, $registry), |
| 119 | |
| 120 | WebmailSenderServiceInterface::class => static fn( |
| 121 | WebmailSenderService $service |
| 122 | ): WebmailSenderServiceInterface => $service, |
| 123 | |
| 124 | WebmailSyncService::class => static fn( |
| 125 | PDO $pdo, |
| 126 | SqlMailRepository $repo, |
| 127 | EncryptionServiceInterface $enc, |
| 128 | MailProtocolDriverRegistryInterface $registry |
| 129 | ): WebmailSyncService => new WebmailSyncService($pdo, $repo, $enc, $registry), |
| 130 | |
| 131 | InboundEmailSyncService::class => static fn( |
| 132 | PDO $pdo, |
| 133 | SqlMailRepository $repo, |
| 134 | EncryptionServiceInterface $enc, |
| 135 | MailProtocolDriverRegistryInterface $registry, |
| 136 | EventDispatcherInterface $dispatcher |
| 137 | ): InboundEmailSyncService => new InboundEmailSyncService($pdo, $repo, $enc, $registry, $dispatcher), |
| 138 | |
| 139 | InboundEmailSyncTask::class => static fn( |
| 140 | InboundEmailSyncService $sync |
| 141 | ): InboundEmailSyncTask => new InboundEmailSyncTask($sync), |
| 142 | |
| 143 | MailSenderService::class => static fn( |
| 144 | SqlMailRepository $repo, |
| 145 | MailTemplateRenderer $renderer, |
| 146 | EncryptionServiceInterface $enc |
| 147 | ): MailSenderService => new MailSenderService($repo, $renderer, $enc), |
| 148 | |
| 149 | MailApiController::class => static fn( |
| 150 | Psr17Factory $psr17, |
| 151 | SqlMailRepository $repo, |
| 152 | MailSenderService $sender |
| 153 | ): MailApiController => new MailApiController($psr17, $repo, $sender), |
| 154 | |
| 155 | WebmailWebController::class => static fn( |
| 156 | TwigEnvironment $twig, |
| 157 | CurrentUser $user, |
| 158 | Psr17Factory $psr17, |
| 159 | WebmailAuthService $auth, |
| 160 | SqlMailRepository $repo |
| 161 | ): WebmailWebController => new WebmailWebController($twig, $user, $psr17, $auth, $repo), |
| 162 | |
| 163 | EmailContextAssociationServiceInterface::class => static fn( |
| 164 | PDO $pdo, |
| 165 | WebmailMessageService $msg |
| 166 | ): EmailContextAssociationServiceInterface => new EmailContextAssociationService($pdo, $msg), |
| 167 | |
| 168 | WebmailHtmxController::class => static fn( |
| 169 | ContainerInterface $c |
| 170 | ): WebmailHtmxController => new WebmailHtmxController( |
| 171 | $c->get(TwigEnvironment::class), |
| 172 | $c->get(CurrentUser::class), |
| 173 | $c->get(Psr17Factory::class), |
| 174 | $c->get(WebmailAuthService::class), |
| 175 | $c->get(WebmailFolderService::class), |
| 176 | $c->get(WebmailMessageService::class), |
| 177 | $c->get(WebmailSenderService::class), |
| 178 | $c->get(SqlMailRepository::class), |
| 179 | $c->has(EmailSecurityScanner::class) ? $c->get(EmailSecurityScanner::class) : null, |
| 180 | $c->has(EmailContextAssociationServiceInterface::class) |
| 181 | ? $c->get(EmailContextAssociationServiceInterface::class) |
| 182 | : null |
| 183 | ), |
| 184 | |
| 185 | WebmailApiController::class => static fn( |
| 186 | Psr17Factory $psr17, |
| 187 | CurrentUser $user, |
| 188 | WebmailAuthService $auth, |
| 189 | WebmailFolderService $folders, |
| 190 | WebmailMessageService $messages, |
| 191 | WebmailSenderService $sender, |
| 192 | WebmailSyncService $sync |
| 193 | ): WebmailApiController => new WebmailApiController( |
| 194 | $psr17, |
| 195 | $user, |
| 196 | $auth, |
| 197 | $folders, |
| 198 | $messages, |
| 199 | $sender, |
| 200 | $sync |
| 201 | ), |
| 202 | |
| 203 | WebmailEventsApiController::class => static fn( |
| 204 | Psr17Factory $psr17, |
| 205 | CurrentUser $user, |
| 206 | WebmailAuthService $auth |
| 207 | ): WebmailEventsApiController => new WebmailEventsApiController($psr17, $user, $auth), |
| 208 | ]; |
| 209 | } |
| 210 | |
| 211 | /** |
| 212 | * @return array<string, mixed> Service extensions mapping. |
| 213 | */ |
| 214 | public function getExtensions(): array |
| 215 | { |
| 216 | return []; |
| 217 | } |
| 218 | } |