Skip to content

Commit 4f8fccf

Browse files
author
Armando Caprio
committed
Aggiunta gestione validazione ssl
1 parent 9fdbbd7 commit 4f8fccf

File tree

3 files changed

+51
-26
lines changed

3 files changed

+51
-26
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ vendor/
22
composer.lock
33
.DS_Store
44
nbproject/*
5+
.idea

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
"email": "[email protected]"
99
}
1010
],
11-
"type": "project",
11+
"type": "library",
1212
"require": {
13-
"php": ">=7.0"
13+
"php": ">=7.0",
14+
"ext-json": "*",
15+
"ext-curl": "*"
1416
},
1517
"require-dev": {
1618
},

src/Client.php

Lines changed: 46 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,17 @@
22

33
namespace SHL\SdiClient;
44

5+
use JsonSerializable;
56
use SHL\SdiClient\Exceptions\RequestFailureException;
7+
use SHL\SdiClient\Types\DocumentInfo;
8+
use SHL\SdiClient\Types\DocumentReceived;
9+
use SHL\SdiClient\Types\DocumentSent;
10+
use SHL\SdiClient\Types\DocumentSentNotification;
611
use SHL\SdiClient\Types\ErrorMessage;
12+
use SHL\SdiClient\Types\File;
13+
use SHL\SdiClient\Types\OutcomeSent;
14+
use SHL\SdiClient\Types\User;
15+
use SHL\SdiClient\Types\UserInfo;
716

817
class Client {
918
/**
@@ -30,6 +39,11 @@ class Client {
3039
*/
3140
private $TryConnectionTimeout = 120;
3241

42+
/**
43+
* @var bool
44+
*/
45+
private $VerifyCertificate = true;
46+
3347

3448
/**
3549
* Costruisce il client con i parametri di connessione
@@ -49,6 +63,7 @@ public function __construct( $endpoint, $username, $apiToken ) {
4963
*/
5064
public function setTimeout( int $timeout ) {
5165
$this->Timeout = $timeout;
66+
return $this;
5267
}
5368

5469

@@ -58,18 +73,25 @@ public function setTimeout( int $timeout ) {
5873
*/
5974
public function setTryConnectionTimeout( int $tryConnectionTimeout ) {
6075
$this->TryConnectionTimeout = $tryConnectionTimeout;
76+
return $this;
6177
}
62-
78+
79+
80+
public function disableCertificateCheck() {
81+
$this->VerifyCertificate = false;
82+
return $this;
83+
}
84+
6385

6486
/**
6587
* Effettua la richiesta tramite curl
6688
* @param string $verb Il verbo http
6789
* @param string $request La richiesta
68-
* @param \JsonSerializable $json I dati da inviare convertiti in json
90+
* @param JsonSerializable $json I dati da inviare convertiti in json
6991
* @return string
7092
* @throws RequestFailureException
7193
*/
72-
private function curl( string $verb, string $request, \JsonSerializable $json = null ) {
94+
private function curl( string $verb, string $request, JsonSerializable $json = null ) {
7395
$ch = curl_init();
7496
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, $verb );
7597
curl_setopt( $ch, CURLOPT_URL, $this->Endpoint . $request );
@@ -84,8 +106,8 @@ private function curl( string $verb, string $request, \JsonSerializable $json =
84106
'Authorization: ' . $this->Token,
85107
]);
86108

87-
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
88-
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 2 );
109+
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, $this->VerifyCertificate );
110+
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, $this->VerifyCertificate ? 2 : 0 );
89111
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
90112
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1 );
91113
curl_setopt( $ch, CURLOPT_TIMEOUT, $this->Timeout );
@@ -127,7 +149,7 @@ public function getUserList() {
127149
/**
128150
* Ritorna i dettagli di un utente in gestione
129151
* @param int $id
130-
* @return \SHL\SdiClient\Types\User
152+
* @return User
131153
*/
132154
public function getUser( $id ) {
133155
return new Types\User(
@@ -138,8 +160,8 @@ public function getUser( $id ) {
138160

139161
/**
140162
* Crea un nuovo utente
141-
* @param \SHL\SdiClient\Types\UserInfo $user
142-
* @return \SHL\SdiClient\Types\User
163+
* @param UserInfo $user
164+
* @return User
143165
*/
144166
public function createUser( Types\UserInfo $user ) {
145167
return new Types\User(
@@ -151,8 +173,8 @@ public function createUser( Types\UserInfo $user ) {
151173
/**
152174
* Modifica un utente in gestione
153175
* @param int $userId
154-
* @param \SHL\SdiClient\Types\UserInfo $user
155-
* @return \SHL\SdiClient\Types\User
176+
* @param UserInfo $user
177+
* @return User
156178
*/
157179
public function editUser( $userId, Types\UserInfo $user ) {
158180
return new Types\User(
@@ -165,7 +187,7 @@ public function editUser( $userId, Types\UserInfo $user ) {
165187
* Modifica lo stato di attivazione di un utente in gestione
166188
* @param int $userId
167189
* @param bool $activeStatus
168-
* @return \SHL\SdiClient\Types\User
190+
* @return User
169191
*/
170192
public function editUserActiveStatus( $userId, bool $activeStatus ) {
171193
$params = new Types\GenericType();
@@ -197,7 +219,7 @@ public function getDocumentSentList( $userId = null ) {
197219
/**
198220
* Ritorna i dettagli di un documento inviato
199221
* @param int $id
200-
* @return \SHL\SdiClient\Types\DocumentSent
222+
* @return DocumentSent
201223
*/
202224
public function getDocumentSent( $id ) {
203225
return new Types\DocumentSent(
@@ -208,8 +230,8 @@ public function getDocumentSent( $id ) {
208230

209231
/**
210232
* Crea un nuovo documento da inviare allo sdi
211-
* @param \SHL\SdiClient\Types\DocumentInfo $document
212-
* @return \SHL\SdiClient\Types\DocumentSent
233+
* @param DocumentInfo $document
234+
* @return DocumentSent
213235
*/
214236
public function sendDocument( Types\DocumentInfo $document ) {
215237
return new Types\DocumentSent(
@@ -233,7 +255,7 @@ public function getDocumentSentNotificationList( $documentId ) {
233255
/**
234256
* Ritorna i dettagli di una notifica di un documento
235257
* @param int $id
236-
* @return \SHL\SdiClient\Types\DocumentSentNotification
258+
* @return DocumentSentNotification
237259
*/
238260
public function getDocumentSentNotification( $id ) {
239261
return new Types\DocumentSentNotification(
@@ -245,7 +267,7 @@ public function getDocumentSentNotification( $id ) {
245267
/**
246268
* Ritorna l'allegato di una notifica
247269
* @param int $id
248-
* @return \SHL\SdiClient\Types\File
270+
* @return File
249271
*/
250272
public function getDocumentSentNotificationFile( $id ) {
251273
return new Types\File(
@@ -274,7 +296,7 @@ public function getDocumentReceivedList( $userId = null ) {
274296
/**
275297
* Ritorna i dettagli di un documento ricevuto
276298
* @param int $id
277-
* @return \SHL\SdiClient\Types\DocumentReceived
299+
* @return DocumentReceived
278300
*/
279301
public function getDocumentReceived( $id ) {
280302
return new Types\DocumentReceived(
@@ -286,7 +308,7 @@ public function getDocumentReceived( $id ) {
286308
/**
287309
* Ritorna il file del documento ricevuto
288310
* @param int $id
289-
* @return \SHL\SdiClient\Types\File
311+
* @return File
290312
*/
291313
public function getDocumentReceivedFile( $id ) {
292314
return new Types\File(
@@ -298,7 +320,7 @@ public function getDocumentReceivedFile( $id ) {
298320
/**
299321
* Ritorna il metafile del documento ricevuto
300322
* @param int $id
301-
* @return \SHL\SdiClient\Types\File
323+
* @return File
302324
*/
303325
public function getDocumentReceivedMetafile( $id ) {
304326
return new Types\File(
@@ -334,7 +356,7 @@ public function getDocumentReceivedNotification( $id ) {
334356
/**
335357
* Ritorna l'allegato di una notifica di un documento ricevuto
336358
* @param int $id
337-
* @return \SHL\SdiClient\Types\File
359+
* @return File
338360
*/
339361
public function getDocumentReceivedNotificationFile( $id ) {
340362
return new Types\File(
@@ -358,7 +380,7 @@ public function getOutcomeSentList( $documentId ) {
358380
/**
359381
* Ritorna i dettagli di una notifica di esito inviata
360382
* @param int $id
361-
* @return \SHL\SdiClient\Types\OutcomeSent
383+
* @return OutcomeSent
362384
*/
363385
public function getOutcomeSent( $id ) {
364386
return new Types\OutcomeSent(
@@ -370,7 +392,7 @@ public function getOutcomeSent( $id ) {
370392
/**
371393
* Ritorna l'allegato di una notifica di esito inviata
372394
* @param int $id
373-
* @return \SHL\SdiClient\Types\File
395+
* @return File
374396
*/
375397
public function getOutcomeSentFile( $id ) {
376398
return new Types\File(
@@ -382,7 +404,7 @@ public function getOutcomeSentFile( $id ) {
382404
/**
383405
* Ritorna il file che spiega l'errore di una notifica di esito inviata
384406
* @param int $id
385-
* @return \SHL\SdiClient\Types\File
407+
* @return File
386408
*/
387409
public function getOutcomeSentErrorFile( $id ) {
388410
$file = $this->curl( 'GET', '/outcome_sent/error_file/' . $id );
@@ -398,7 +420,7 @@ public function getOutcomeSentErrorFile( $id ) {
398420
* Invia una nuova notifica di esito
399421
* @param int $documentId L'id del documento ricevuto per il quale mandare la notifica
400422
* @param \SHL\SdiClient\Types\OutcomeInfo $outcome
401-
* @return \SHL\SdiClient\Types\OutcomeSent
423+
* @return OutcomeSent
402424
*/
403425
public function sendOutcome( $documentId, Types\OutcomeInfo $outcome ) {
404426
return new Types\OutcomeSent(

0 commit comments

Comments
 (0)