Feat: Make CRM ids configurable
This commit is contained in:
@@ -43,3 +43,7 @@ MESSENGER_TRANSPORT_DSN=doctrine://default?auto_setup=0
|
||||
APP_BPN_USER=
|
||||
APP_BPN_PASSWORD=
|
||||
APP_BPN_ENDPOINT=
|
||||
|
||||
APP_BPN_CRM_ID_ADMIN=1292
|
||||
APP_BPN_CRM_ID_MANAGER=1293
|
||||
APP_BPN_CRM_ID_TEAMER=1070
|
||||
|
||||
+11
-6
@@ -3,14 +3,15 @@ parameters:
|
||||
bpn_username: '%env(APP_BPN_USER)%'
|
||||
bpn_password: '%env(APP_BPN_PASSWORD)%'
|
||||
|
||||
bpn_crm_id_admin: '%env(int:APP_BPN_CRM_ID_ADMIN)%'
|
||||
bpn_crm_id_manager: '%env(int:APP_BPN_CRM_ID_MANAGER)%'
|
||||
bpn_crm_id_teamer: '%env(int:APP_BPN_CRM_ID_TEAMER)%'
|
||||
|
||||
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.
|
||||
autowire: true
|
||||
autoconfigure: true
|
||||
|
||||
# makes classes in src/ available to be used as services
|
||||
# this creates a service per class whose id is the fully-qualified class name
|
||||
App\:
|
||||
resource: '../src/'
|
||||
exclude:
|
||||
@@ -20,4 +21,8 @@ services:
|
||||
|
||||
App\BusProNet\ApiClient:
|
||||
arguments:
|
||||
$options: { 'bpn_username': '%bpn_username%', 'bpn_password': '%bpn_password%', 'bpn_url': '%bpn_url%' }
|
||||
$options: { 'bpn_username': '%bpn_username%', 'bpn_password': '%bpn_password%', 'bpn_url': '%bpn_url%' }
|
||||
|
||||
App\BusProNet\ResponseParser:
|
||||
arguments:
|
||||
$options: { 'bpn_crm_id_admin': '%bpn_crm_id_admin%', 'bpn_crm_id_manager': '%bpn_crm_id_manager%', 'bpn_crm_id_teamer': '%bpn_crm_id_teamer%' }
|
||||
@@ -14,6 +14,7 @@ class ApiClient
|
||||
public function __construct(
|
||||
private readonly HttpClientInterface $httpClient,
|
||||
private readonly SerializerInterface $serializer,
|
||||
private readonly ResponseParser $responseParser,
|
||||
array $options
|
||||
) {
|
||||
$this->config = $this->resolveOptions($options);
|
||||
@@ -49,7 +50,7 @@ class ApiClient
|
||||
|
||||
$xml = $response->getContent();
|
||||
|
||||
return (new ResponseParser())->parseXmlString($xml);
|
||||
return $this->responseParser->parseXmlString($xml);
|
||||
} catch (\Throwable $e) {
|
||||
}
|
||||
|
||||
@@ -89,7 +90,7 @@ class ApiClient
|
||||
|
||||
$xml = $response->getContent();
|
||||
|
||||
return (new ResponseParser())->parseXmlString($xml);
|
||||
return $this->responseParser->parseXmlString($xml);
|
||||
} catch (\Throwable $e) {
|
||||
}
|
||||
|
||||
|
||||
@@ -4,10 +4,6 @@ namespace App\BusProNet\Model;
|
||||
|
||||
class CrmAttribute
|
||||
{
|
||||
public const ATTR_ID_ADMIN = 1071;
|
||||
public const ATTR_ID_MANAGER = 1072;
|
||||
public const ATTR_ID_TEAMER = 1070;
|
||||
|
||||
private ?int $id = null;
|
||||
private ?string $label = null;
|
||||
private bool $selected = false;
|
||||
|
||||
@@ -9,9 +9,17 @@ use App\BusProNet\Model\CrmAttributesResponse;
|
||||
use App\BusProNet\Model\CrmAttributeGroup;
|
||||
use App\BusProNet\Model\ProfileResponse;
|
||||
use App\BusProNet\Model\BaseResponse;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class ResponseParser
|
||||
{
|
||||
private array $config;
|
||||
|
||||
public function __construct(array $options)
|
||||
{
|
||||
$this->config = $this->resolveOptions($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ResponseParserException
|
||||
*/
|
||||
@@ -55,7 +63,7 @@ class ResponseParser
|
||||
$title = (string) $xml->xpath('adressdaten/titel')[0];
|
||||
|
||||
$gender = (string) $xml->xpath('adressdaten/geschlecht')[0];
|
||||
$gender = $gender === 'W' ? 'f' : strtolower($gender);
|
||||
$gender = strtolower($gender) === 'w' ? 'f' : strtolower($gender);
|
||||
|
||||
$date = $xml->xpath('adressdaten/geburtsdatum');
|
||||
$dateOfBirth = $date ?\DateTimeImmutable::createFromFormat('d.m.Y', (string) $date[0]) : null;
|
||||
@@ -122,13 +130,13 @@ class ResponseParser
|
||||
;
|
||||
$attributes[] = $attribute;
|
||||
|
||||
if (CrmAttribute::ATTR_ID_ADMIN === $attribute->getId() && true === $attribute->isSelected()) {
|
||||
if ($this->config['bpn_crm_id_admin'] === $attribute->getId() && true === $attribute->isSelected()) {
|
||||
$isAdmin = true;
|
||||
}
|
||||
if (CrmAttribute::ATTR_ID_MANAGER === $attribute->getId() && true === $attribute->isSelected()) {
|
||||
if ($this->config['bpn_crm_id_manager'] === $attribute->getId() && true === $attribute->isSelected()) {
|
||||
$isManager = true;
|
||||
}
|
||||
if (CrmAttribute::ATTR_ID_TEAMER === $attribute->getId() && true === $attribute->isSelected()) {
|
||||
if ($this->config['bpn_crm_id_teamer'] === $attribute->getId() && true === $attribute->isSelected()) {
|
||||
$isTeamer = true;
|
||||
}
|
||||
}
|
||||
@@ -146,4 +154,15 @@ class ResponseParser
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
private function resolveOptions(array $options): array
|
||||
{
|
||||
$optionsResolver = new OptionsResolver();
|
||||
$optionsResolver->setRequired(['bpn_crm_id_admin', 'bpn_crm_id_manager', 'bpn_crm_id_teamer']);
|
||||
$optionsResolver->setAllowedTypes('bpn_crm_id_admin', 'int');
|
||||
$optionsResolver->setAllowedTypes('bpn_crm_id_manager', 'int');
|
||||
$optionsResolver->setAllowedTypes('bpn_crm_id_teamer', 'int');
|
||||
|
||||
return $optionsResolver->resolve($options);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user