mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-30 10:29:42 +00:00
Remove legacy ShortMessage components and integrate Notifier
Replaced outdated ShortMessage functionalities with Symfony's Notifier component for handling SMS messages. Deprecated legacy `ShortMessage` components and introduced a transition layer for existing OVH configurations. Updated dependencies and environment setup to support the new implementation.
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Service\Notifier;
|
||||
|
||||
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
|
||||
use Symfony\Component\Notifier\Transport\AbstractTransportFactory;
|
||||
use Symfony\Component\Notifier\Transport\Dsn;
|
||||
use Symfony\Component\Notifier\Transport\TransportInterface;
|
||||
|
||||
/**
|
||||
* This is a legacy ovh cloud provider, to provide the regular OvhCloudTransporter from the previous configuration.
|
||||
*
|
||||
* This is only for transition purpose from the previous ovh dsn, which was existing in chill.
|
||||
*/
|
||||
class LegacyOvhCloudFactory extends AbstractTransportFactory
|
||||
{
|
||||
protected function getSupportedSchemes(): array
|
||||
{
|
||||
return ['ovh'];
|
||||
}
|
||||
|
||||
public function create(Dsn $dsn): TransportInterface
|
||||
{
|
||||
$scheme = $dsn->getScheme();
|
||||
|
||||
if ('ovh' !== $scheme) {
|
||||
throw new UnsupportedSchemeException($dsn, 'ovh', $this->getSupportedSchemes());
|
||||
}
|
||||
|
||||
if (!class_exists($class = '\Symfony\Component\Notifier\Bridge\OvhCloud\OvhCloudTransport')) {
|
||||
throw new \RuntimeException(sprintf('The class %s is missing, please add the dependency with "composer require symfony/ovh-cloud-notifier".', $class));
|
||||
}
|
||||
|
||||
$applicationKey = $this->getUser($dsn);
|
||||
$applicationSecret = $this->getPassword($dsn);
|
||||
$consumerKey = $dsn->getRequiredOption('consumer_key');
|
||||
$serviceName = $dsn->getRequiredOption('service_name');
|
||||
$sender = $dsn->getOption('sender');
|
||||
$host = null;
|
||||
$port = $dsn->getPort();
|
||||
|
||||
return (new $class($applicationKey, $applicationSecret, $consumerKey, $serviceName, $this->client, $this->dispatcher))
|
||||
->setHost($host)->setPort($port)->setSender($sender);
|
||||
}
|
||||
}
|
@@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers.
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Service\ShortMessage;
|
||||
|
||||
class NullShortMessageSender implements ShortMessageSenderInterface
|
||||
{
|
||||
public function send(ShortMessage $shortMessage): void {}
|
||||
}
|
@@ -20,6 +20,8 @@ namespace Chill\MainBundle\Service\ShortMessage;
|
||||
|
||||
use libphonenumber\PhoneNumber;
|
||||
|
||||
trigger_deprecation('chill-project/chill-bundles', '3.7', 'Short Messages are deprecated, use SmsMessage and Notifier component instead');
|
||||
|
||||
class ShortMessage
|
||||
{
|
||||
final public const PRIORITY_LOW = 'low';
|
||||
|
@@ -18,17 +18,33 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Service\ShortMessage;
|
||||
|
||||
use libphonenumber\PhoneNumberFormat;
|
||||
use libphonenumber\PhoneNumberUtil;
|
||||
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
|
||||
use Symfony\Component\Notifier\Message\SmsMessage;
|
||||
use Symfony\Component\Notifier\TexterInterface;
|
||||
|
||||
/**
|
||||
* @AsMessageHandler
|
||||
*/
|
||||
class ShortMessageHandler implements MessageHandlerInterface
|
||||
{
|
||||
public function __construct(private readonly ShortMessageTransporterInterface $messageTransporter) {}
|
||||
private readonly PhoneNumberUtil $phoneNumberUtil;
|
||||
|
||||
public function __construct(private readonly TexterInterface $texter)
|
||||
{
|
||||
$this->phoneNumberUtil = PhoneNumberUtil::getInstance();
|
||||
}
|
||||
|
||||
public function __invoke(ShortMessage $message): void
|
||||
{
|
||||
$this->messageTransporter->send($message);
|
||||
trigger_deprecation('Chill-project/chill-bundles', '3.7.0', 'Send message using Notifier component');
|
||||
|
||||
$this->texter->send(
|
||||
new SmsMessage(
|
||||
$this->phoneNumberUtil->format($message->getPhoneNumber(), PhoneNumberFormat::E164),
|
||||
$message->getContent(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers.
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Service\ShortMessage;
|
||||
|
||||
interface ShortMessageSenderInterface
|
||||
{
|
||||
public function send(ShortMessage $shortMessage): void;
|
||||
}
|
@@ -1,29 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers.
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Service\ShortMessage;
|
||||
|
||||
class ShortMessageTransporter implements ShortMessageTransporterInterface
|
||||
{
|
||||
public function __construct(private readonly ShortMessageSenderInterface $sender) {}
|
||||
|
||||
public function send(ShortMessage $shortMessage): void
|
||||
{
|
||||
$this->sender->send($shortMessage);
|
||||
}
|
||||
}
|
@@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers.
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Service\ShortMessage;
|
||||
|
||||
interface ShortMessageTransporterInterface
|
||||
{
|
||||
public function send(ShortMessage $shortMessage);
|
||||
}
|
@@ -1,65 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers.
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Service\ShortMessageOvh;
|
||||
|
||||
use Chill\MainBundle\Service\ShortMessage\ShortMessage;
|
||||
use Chill\MainBundle\Service\ShortMessage\ShortMessageSenderInterface;
|
||||
use libphonenumber\PhoneNumberFormat;
|
||||
use libphonenumber\PhoneNumberUtil;
|
||||
use Ovh\Api;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class OvhShortMessageSender implements ShortMessageSenderInterface
|
||||
{
|
||||
public function __construct(
|
||||
private readonly Api $api,
|
||||
// for DI, must remains as first argument
|
||||
private readonly string $serviceName,
|
||||
// for di, must remains as second argument
|
||||
private readonly string $sender,
|
||||
// for DI, must remains as third argument
|
||||
private readonly LoggerInterface $logger,
|
||||
private readonly PhoneNumberUtil $phoneNumberUtil,
|
||||
) {}
|
||||
|
||||
public function send(ShortMessage $shortMessage): void
|
||||
{
|
||||
$receiver = $this->phoneNumberUtil->format($shortMessage->getPhoneNumber(), PhoneNumberFormat::E164);
|
||||
|
||||
$response = $this->api->post(
|
||||
strtr('/sms/{serviceName}/jobs', ['{serviceName}' => $this->serviceName]),
|
||||
[
|
||||
'message' => $shortMessage->getContent(),
|
||||
'receivers' => [$receiver],
|
||||
'sender' => $this->sender,
|
||||
'noStopClause' => true,
|
||||
'coding' => '7bit',
|
||||
'charset' => 'UTF-8',
|
||||
'priority' => $shortMessage->getPriority(),
|
||||
]
|
||||
);
|
||||
|
||||
$improved = array_merge([
|
||||
'validReceiversI' => implode(',', $response['validReceivers']),
|
||||
'idsI' => implode(',', $response['ids']),
|
||||
], $response);
|
||||
|
||||
$this->logger->warning('[sms] a sms was sent', $improved);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user