first commit

This commit is contained in:
2025-08-02 16:30:27 +02:00
commit 23646bfcee
14851 changed files with 1750626 additions and 0 deletions

View File

@@ -0,0 +1,72 @@
<?php
declare(strict_types=1);
namespace KupShop\KupShopBundle\Mailer;
use KupShop\KupShopBundle\Config;
use Symfony\Component\Mailer\Transport\AbstractTransportFactory;
use Symfony\Component\Mailer\Transport\Dsn;
use Symfony\Component\Mailer\Transport\Smtp\EsmtpTransportFactory;
use Symfony\Component\Mailer\Transport\TransportInterface;
class TransportFactory extends AbstractTransportFactory
{
/** @var EsmtpTransportFactory */
private $transportFactory;
public function setTransportFactory(EsmtpTransportFactory $transportFactory): void
{
$this->transportFactory = $transportFactory;
}
public function create(Dsn $dsn): TransportInterface
{
if ($customDsn = $this->getCustomDsn($dsn->getOption('index'))) {
$dsn = $customDsn;
}
return $this->transportFactory->create($dsn);
}
public function getCustomDsn($index): ?Dsn
{
$dbcfg = \Settings::getDefault();
// change smtp by settings
if (!empty($dbcfg->smtp)) {
$scheme = 'smtp';
$smtp = $dbcfg->smtp;
if (!empty($smtp[$index])) {
$smtp = $smtp[$index];
if ($smtp['enabled'] == 'Y' && !empty($smtp['host']) && !empty($smtp['port'])) {
$encryption = $smtp['encryption'] ?? null;
// enables TLS - routines:ssl3_get_record:wrong version number - bez toho to funguje taky, tak snad to je ok
// if ($encryption) {
// $scheme = 'smtps';
// }
$user = $smtp['user'] ?? null;
$users = explode(',', $smtp['user']);
// randomly select user if there is more than one
if (count($users) > 1) {
$user = trim($users[array_rand($users)]);
}
return new Dsn($scheme, $smtp['host'], $user, $smtp['password'] ?? null, (int) $smtp['port'], [
'verify_peer' => 0,
'local_domain' => rtrim(Config::get()['Addr']['print'], '/'),
'timeout' => 10,
]);
}
}
}
return null;
}
protected function getSupportedSchemes(): array
{
return ['wpjshop'];
}
}