From 986fa1d901888616cac7ff56ec3208e283236ee7 Mon Sep 17 00:00:00 2001 From: Marko Jovanovic Date: Thu, 2 Oct 2025 16:18:00 +0200 Subject: [PATCH] Added env var SMS_GATEWAY_API_KEY --- config/services.yaml | 3 ++- src/Command/ContactUncontactedCommand.php | 11 ++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/config/services.yaml b/config/services.yaml index 843ef43..c7cf163 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -4,13 +4,14 @@ # Put parameters here that don't need to change on each machine where the app is deployed # https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration parameters: - app.sms_gateway_api_key: '%env(SMS_GATEWAY_API_KEY)%' services: # default configuration for services in *this* file _defaults: autowire: true # Automatically injects dependencies in your services. autoconfigure: true # Automatically registers your services as commands, event subscribers, etc. + bind: + string $sms_gateway_api_key: '%env(SMS_GATEWAY_API_KEY)%' # makes classes in src/ available to be used as services # this creates a service per class whose id is the fully-qualified class name diff --git a/src/Command/ContactUncontactedCommand.php b/src/Command/ContactUncontactedCommand.php index b1ebae1..58e7731 100644 --- a/src/Command/ContactUncontactedCommand.php +++ b/src/Command/ContactUncontactedCommand.php @@ -28,11 +28,16 @@ class ContactUncontactedCommand extends Command private EntityManagerInterface $entityManager; private HttpClientInterface $httpClient; - public function __construct(EntityManagerInterface $entityManager, HttpClientInterface $httpClient) + private string $sms_gateway_api_key; + + public function __construct(EntityManagerInterface $entityManager, + HttpClientInterface $httpClient, + string $sms_gateway_api_key) { parent::__construct(); $this->entityManager = $entityManager; $this->httpClient = $httpClient; + $this->sms_gateway_api_key = $sms_gateway_api_key; } protected function configure(): void @@ -72,9 +77,9 @@ class ContactUncontactedCommand extends Command try { $response = $this->httpClient->request('GET', self::$apiEndpoint, [ 'query' => [ - 'producttoken' => $this->getParameter('SMS_GATEWAY_API_KEY'), + 'producttoken' => $this->sms_gateway_api_key, 'body' => 'Bitte starten Sie die Umfrage jetzt: https://umfragetool.ukbonn.de/login?id=QMBEFR_TEST Ihr UKB.', - 'to' => '004917672121270', + 'to' => $phoneNumber, 'from' => 'UKB', 'reference' => 'Test-Reference' ]