22
33namespace  Drupal \os2forms_digital_post \Consumer ;
44
5+ use  Drupal \Core \Config \ImmutableConfig ;
56use  Drupal \Core \Config \ConfigFactoryInterface ;
67use  Drupal \Core \Lock \LockBackendInterface ;
78use  Drupal \Core \State \State ;
1718use  Drupal \os2forms_digital_post \Client \StructType \KontaktOplysningType ;
1819use  Drupal \os2forms_digital_post \Client \StructType \PrintAfsendBrevRequestType ;
1920use  Drupal \os2forms_digital_post \Client \StructType \SlutbrugerIdentitetType ;
20- use  Exception ;
2121use  ItkDev \Serviceplatformen \Certificate \AzureKeyVaultCertificateLocator ;
2222use  ItkDev \Serviceplatformen \Certificate \CertificateLocatorInterface ;
23- use  SoapFault ;
2423use  WsdlToPhp \PackageBase \AbstractSoapClientBase ;
2524use  GuzzleHttp \Client ;
2625use  Http \Factory \Guzzle \RequestFactory ;
2726use  ItkDev \AzureKeyVault \Authorisation \VaultToken ;
2827use  Http \Adapter \Guzzle6 \Client  as  GuzzleAdapter ;
2928use  ItkDev \AzureKeyVault \KeyVault \VaultSecret ;
3029
30+ /** 
31+  * Print service consumer. 
32+  */ 
3133class  PrintServiceConsumer {
32- 
33-   private  $ config
34-   private  $ guzzleClient
35-   private  $ lock
36-   private  $ state
34+   /** 
35+    * The config. 
36+    * 
37+    * @var \Drupal\Core\Config\ImmutableConfig 
38+    */ 
39+   private  ImmutableConfig $ config
40+ 
41+   /** 
42+    * The client. 
43+    * 
44+    * @var \GuzzleHttp\Client 
45+    */ 
46+   private  Client $ guzzleClient
47+ 
48+   /** 
49+    * The lock. 
50+    * 
51+    * @var \Drupal\Core\Lock\LockBackendInterface 
52+    */ 
53+   private  LockBackendInterface $ lock
54+ 
55+   /** 
56+    * The state. 
57+    * 
58+    * @var \Drupal\Core\State\State 
59+    */ 
60+   private  State $ state
61+ 
62+   /** 
63+    * The UUID generator. 
64+    * 
65+    * @var UuidInterface 
66+    */ 
3767  private  $ uuid
3868
69+   /** 
70+    * The lock name. 
71+    * 
72+    * @var string 
73+    */ 
3974  private  $ lockName'os2forms_digital_post_print_service ' ;
4075
76+   /** 
77+    * Constructor. 
78+    */ 
4179  public  function  __construct (ConfigFactoryInterface $ configFactoryClient $ guzzleClientLockBackendInterface $ lockState $ state
4280
4381    $ this config  = $ configFactoryget ('os2forms_digital_post ' );
@@ -47,25 +85,28 @@ public function __construct(ConfigFactoryInterface $configFactory, Client $guzzl
4785    $ this uuid  = \Drupal::service ('uuid ' );
4886  }
4987
88+   /** 
89+    * Afsend brev person. 
90+    */ 
5091  public  function  afsendBrevPerson (
51-     string  $ kanalValgnull ,
52-     string  $ prioritetnull ,
53-     string  $ cprNummerIdentifikatornull ,
54-     string  $ personNamenull ,
55-     string  $ coNavnnull ,
56-     string  $ streetNamenull ,
57-     string  $ streetBuildingIdentifiernull ,
58-     string  $ floorIdentifiernull ,
59-     string  $ suiteIdentifiernull ,
60-     string  $ mailDeliverySublocationIdentifiernull ,
61-     string  $ postCodeIdentifiernull ,
62-     string  $ districtSubdivisionIdentifiernull ,
63-     string  $ postOfficeBoxIdentifiernull ,
64-     string  $ countryIdentificationCodenull ,
65-     string  $ filFormatNavnnull ,
66-     string  $ meddelelseIndholdDatanull ,
67-     string  $ titelTekstnull ,
68-     string  $ brevDatonull 
92+     string  $ kanalValgNULL ,
93+     string  $ prioritetNULL ,
94+     string  $ cprNummerIdentifikatorNULL ,
95+     string  $ personNameNULL ,
96+     string  $ coNavnNULL ,
97+     string  $ streetNameNULL ,
98+     string  $ streetBuildingIdentifierNULL ,
99+     string  $ floorIdentifierNULL ,
100+     string  $ suiteIdentifierNULL ,
101+     string  $ mailDeliverySublocationIdentifierNULL ,
102+     string  $ postCodeIdentifierNULL ,
103+     string  $ districtSubdivisionIdentifierNULL ,
104+     string  $ postOfficeBoxIdentifierNULL ,
105+     string  $ countryIdentificationCodeNULL ,
106+     string  $ filFormatNavnNULL ,
107+     string  $ meddelelseIndholdDataNULL ,
108+     string  $ titelTekstNULL ,
109+     string  $ brevDatoNULL 
69110  ) {
70111
71112    if  (!$ this acquireLock ()) {
@@ -94,12 +135,12 @@ public function afsendBrevPerson(
94135      $ postCodeIdentifier
95136      $ districtSubdivisionIdentifier
96137      $ postOfficeBoxIdentifier
97-       null ,
98-       null ,
99-       null ,
100-       null ,
101-       null ,
102-       null ,
138+       NULL ,
139+       NULL ,
140+       NULL ,
141+       NULL ,
142+       NULL ,
143+       NULL ,
103144      $ countryIdentificationCodeType
104145    );
105146
@@ -114,10 +155,10 @@ public function afsendBrevPerson(
114155      $ forsendelsesModtager
115156      $ filFormatNavn
116157      $ meddelelseIndholdData
117-       null ,
158+       NULL ,
118159      $ dokumentParametre
119-       null ,
120-       null ,
160+       NULL ,
161+       NULL ,
121162      $ digitalPostParametre
122163    );
123164
@@ -140,21 +181,24 @@ public function afsendBrevPerson(
140181      AbstractSoapClientBase::WSDL_LOCATION  => $ this config ->get ('service_endpoint ' ),
141182    ]);
142183
143- 
144184    $ response$ clientafsendBrev ($ request
145185
146186    $ this releaseLock ();
147187
148-     if  (false  === $ response
188+     if  (FALSE  === $ response
149189      $ lastError$ clientgetLastError ();
150-       /* @var $soapError SoapFault  */ 
190+       /**  @var SoapFault  $soapError */ 
151191      $ soapError$ lastError'Drupal\os2forms_digital_post\Client\ServiceType\Afsend::afsendBrev ' ];
152-       throw  new  Exception ($ soapErrorgetMessage (), $ soapErrorgetCode ()); // Should maybe log this instead! 
192+       // Should maybe log this instead! 
193+       throw  new  \Exception ($ soapErrorgetMessage (), $ soapErrorgetCode ());
153194    }
154195
155196    return  $ responsegetResultat ();
156197  }
157198
199+   /** 
200+    * Get absolute path to certificate. 
201+    */ 
158202  private  function  getAzureKeyVaultCertificateLocator (
159203    string  $ tenantId
160204    string  $ applicationId
@@ -188,13 +232,16 @@ private function getAzureKeyVaultCertificateLocator(
188232    );
189233  }
190234
235+   /** 
236+    * Afsend digital post person. 
237+    */ 
191238  public  function  afsendDigitalPostPerson (
192-     string  $ kanalValgnull ,
193-     string  $ prioritetnull ,
194-     string  $ cprNummerIdentifikatornull ,
195-     string  $ filFormatNavnnull ,
196-     string  $ meddelelseIndholdDatanull ,
197-     string  $ titelTekstnull 
239+     string  $ kanalValgNULL ,
240+     string  $ prioritetNULL ,
241+     string  $ cprNummerIdentifikatorNULL ,
242+     string  $ filFormatNavnNULL ,
243+     string  $ meddelelseIndholdDataNULL ,
244+     string  $ titelTekstNULL 
198245  ): bool  {
199246
200247    if  (!$ this acquireLock ()) {
@@ -213,18 +260,18 @@ public function afsendDigitalPostPerson(
213260    $ forsendelsesModtagernew  ForsendelseModtagerType ($ slutBrugerIdentitetType
214261
215262    $ dokumentParametrenew  DokumentParametreType ($ titelTekst
216-     $ digitalPostParametrenew  DigitalPostParametreType (null , $ this config ->get ('digital_post_materiale_id ' ));
263+     $ digitalPostParametrenew  DigitalPostParametreType (NULL , $ this config ->get ('digital_post_materiale_id ' ));
217264
218265    $ forsendelsenew  ForsendelseIType (
219266      $ this generateAfsendelseIdentifikator (),
220-       null ,
267+       NULL ,
221268      $ forsendelsesModtager
222269      $ filFormatNavn
223270      $ meddelelseIndholdData
224-       null ,
271+       NULL ,
225272      $ dokumentParametre
226-       null ,
227-       null ,
273+       NULL ,
274+       NULL ,
228275      $ digitalPostParametre
229276    );
230277
@@ -247,21 +294,24 @@ public function afsendDigitalPostPerson(
247294      AbstractSoapClientBase::WSDL_LOCATION  => $ this config ->get ('service_endpoint ' ),
248295    ]);
249296
250- 
251297    $ response$ clientafsendBrev ($ request
252298
253299    $ this releaseLock ();
254300
255-     if  (false  === $ response
301+     if  (FALSE  === $ response
256302      $ lastError$ clientgetLastError ();
257-       /* @var $soapError SoapFault  */ 
303+       /**  @var SoapFault  $soapError */ 
258304      $ soapError$ lastError'Drupal\os2forms_digital_post\Client\ServiceType\Afsend::afsendBrev ' ];
259-       throw  new  \Exception ($ soapErrorgetMessage (), $ soapErrorgetCode ()); // Should maybe log this instead! 
305+       // Should maybe log this instead! 
306+       throw  new  \Exception ($ soapErrorgetMessage (), $ soapErrorgetCode ());
260307    }
261308
262309    return  $ responsegetResultat ();
263310  }
264311
312+   /** 
313+    * Generate afsendelse identifikator. 
314+    */ 
265315  protected  function  generateAfsendelseIdentifikator (): string  {
266316
267317    $ stateKey'os2forms_digital_post_last_letter_counter ' ;
@@ -276,19 +326,28 @@ protected function generateAfsendelseIdentifikator(): string {
276326
277327    return  $ this config ->get ('digital_post_system_id ' )
278328      . $ this config ->get ('digital_post_afsender_system ' )
279-       . $ nextLetterNumber
280-     ;
329+       . $ nextLetterNumber
281330  }
282331
332+   /** 
333+    * Acquire lock. 
334+    */ 
283335  protected  function  acquireLock (): bool  {
284336    return  $ this lock ->acquire ($ this lockName );
285337  }
286338
339+   /** 
340+    * Release lock. 
341+    */ 
287342  protected  function  releaseLock () {
288343    $ this lock ->release ($ this lockName );
289344  }
290345
346+   /** 
347+    * Wait lock. 
348+    */ 
291349  protected  function  waitLock (): bool  {
292350    return  $ this lock ->wait ($ this lockName );
293351  }
352+ 
294353}
0 commit comments