Refactor SMS Provider Classes to Support Nullable API Key and Sender
- Updated KavehNegarProvider and RanginehProvider constructors to accept nullable API key and sender parameters. - Adjusted methods in both providers to handle cases where the API key or sender may not be set, preventing potential TypeErrors. - Modified community IDs in graph.json for various entities to reflect updated associations. - Updated manifest.json with new modification times and AST hashes for KavehNegarProvider and RanginehProvider. - Added new AST cache files for KavehNegarProvider and RanginehProvider reflecting the latest structure and relationships.
This commit is contained in:
@@ -12,12 +12,14 @@ class KavehNegarProvider implements SmsProviderInterface
|
||||
public function __construct(
|
||||
private readonly HttpClientInterface $httpClient,
|
||||
private readonly SiteConfigRepository $configRepo,
|
||||
private readonly string $apiKey = '',
|
||||
private readonly string $sender = '',
|
||||
// Nullable: env `%env(default::KAVENEGAR_API_KEY)%` resolves to null when unset
|
||||
// (the real key normally comes from DB site config below, not env).
|
||||
private readonly ?string $apiKey = null,
|
||||
private readonly ?string $sender = null,
|
||||
) {}
|
||||
|
||||
private function key(): string { return $this->configRepo->get('kavenegar_api_key') ?: $this->apiKey; }
|
||||
private function sender(): string { return $this->configRepo->get('kavenegar_sender') ?: $this->sender; }
|
||||
private function key(): string { return $this->configRepo->get('kavenegar_api_key') ?: ($this->apiKey ?? ''); }
|
||||
private function sender(): string { return $this->configRepo->get('kavenegar_sender') ?: ($this->sender ?? ''); }
|
||||
|
||||
public function getName(): string { return 'kavenegar'; }
|
||||
|
||||
|
||||
@@ -10,8 +10,10 @@ class RanginehProvider implements SmsProviderInterface
|
||||
|
||||
public function __construct(
|
||||
private readonly HttpClientInterface $httpClient,
|
||||
private readonly string $apiKey,
|
||||
private readonly string $sender,
|
||||
// Nullable: env `%env(default::RANGINEH_API_KEY)%` resolves to null when unset,
|
||||
// which would crash construction (TypeError) before the provider is ever used.
|
||||
private readonly ?string $apiKey = null,
|
||||
private readonly ?string $sender = null,
|
||||
) {}
|
||||
|
||||
public function getName(): string { return 'rangineh'; }
|
||||
@@ -20,8 +22,8 @@ class RanginehProvider implements SmsProviderInterface
|
||||
{
|
||||
try {
|
||||
$resp = $this->httpClient->request('POST', self::BASE . '/send', [
|
||||
'json' => ['from' => $this->sender, 'to' => [$mobile], 'text' => $message],
|
||||
'headers' => ['ApiKey' => $this->apiKey],
|
||||
'json' => ['from' => $this->sender ?? '', 'to' => [$mobile], 'text' => $message],
|
||||
'headers' => ['ApiKey' => $this->apiKey ?? ''],
|
||||
'timeout' => 10,
|
||||
]);
|
||||
return $resp->getStatusCode() === 200;
|
||||
|
||||
Reference in New Issue
Block a user