Skip to content

Commit

Permalink
Aggiunta gestione validazione ssl
Browse files Browse the repository at this point in the history
  • Loading branch information
Armando Caprio committed Mar 18, 2022
1 parent 9fdbbd7 commit 4f8fccf
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 26 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ vendor/
composer.lock
.DS_Store
nbproject/*
.idea
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
"email": "[email protected]"
}
],
"type": "project",
"type": "library",
"require": {
"php": ">=7.0"
"php": ">=7.0",
"ext-json": "*",
"ext-curl": "*"
},
"require-dev": {
},
Expand Down
70 changes: 46 additions & 24 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@

namespace SHL\SdiClient;

use JsonSerializable;
use SHL\SdiClient\Exceptions\RequestFailureException;
use SHL\SdiClient\Types\DocumentInfo;
use SHL\SdiClient\Types\DocumentReceived;
use SHL\SdiClient\Types\DocumentSent;
use SHL\SdiClient\Types\DocumentSentNotification;
use SHL\SdiClient\Types\ErrorMessage;
use SHL\SdiClient\Types\File;
use SHL\SdiClient\Types\OutcomeSent;
use SHL\SdiClient\Types\User;
use SHL\SdiClient\Types\UserInfo;

class Client {
/**
Expand All @@ -30,6 +39,11 @@ class Client {
*/
private $TryConnectionTimeout = 120;

/**
* @var bool
*/
private $VerifyCertificate = true;


/**
* Costruisce il client con i parametri di connessione
Expand All @@ -49,6 +63,7 @@ public function __construct( $endpoint, $username, $apiToken ) {
*/
public function setTimeout( int $timeout ) {
$this->Timeout = $timeout;
return $this;
}


Expand All @@ -58,18 +73,25 @@ public function setTimeout( int $timeout ) {
*/
public function setTryConnectionTimeout( int $tryConnectionTimeout ) {
$this->TryConnectionTimeout = $tryConnectionTimeout;
return $this;
}



public function disableCertificateCheck() {
$this->VerifyCertificate = false;
return $this;
}


/**
* Effettua la richiesta tramite curl
* @param string $verb Il verbo http
* @param string $request La richiesta
* @param \JsonSerializable $json I dati da inviare convertiti in json
* @param JsonSerializable $json I dati da inviare convertiti in json
* @return string
* @throws RequestFailureException
*/
private function curl( string $verb, string $request, \JsonSerializable $json = null ) {
private function curl( string $verb, string $request, JsonSerializable $json = null ) {
$ch = curl_init();
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, $verb );
curl_setopt( $ch, CURLOPT_URL, $this->Endpoint . $request );
Expand All @@ -84,8 +106,8 @@ private function curl( string $verb, string $request, \JsonSerializable $json =
'Authorization: ' . $this->Token,
]);

curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 2 );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, $this->VerifyCertificate );
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, $this->VerifyCertificate ? 2 : 0 );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1 );
curl_setopt( $ch, CURLOPT_TIMEOUT, $this->Timeout );
Expand Down Expand Up @@ -127,7 +149,7 @@ public function getUserList() {
/**
* Ritorna i dettagli di un utente in gestione
* @param int $id
* @return \SHL\SdiClient\Types\User
* @return User
*/
public function getUser( $id ) {
return new Types\User(
Expand All @@ -138,8 +160,8 @@ public function getUser( $id ) {

/**
* Crea un nuovo utente
* @param \SHL\SdiClient\Types\UserInfo $user
* @return \SHL\SdiClient\Types\User
* @param UserInfo $user
* @return User
*/
public function createUser( Types\UserInfo $user ) {
return new Types\User(
Expand All @@ -151,8 +173,8 @@ public function createUser( Types\UserInfo $user ) {
/**
* Modifica un utente in gestione
* @param int $userId
* @param \SHL\SdiClient\Types\UserInfo $user
* @return \SHL\SdiClient\Types\User
* @param UserInfo $user
* @return User
*/
public function editUser( $userId, Types\UserInfo $user ) {
return new Types\User(
Expand All @@ -165,7 +187,7 @@ public function editUser( $userId, Types\UserInfo $user ) {
* Modifica lo stato di attivazione di un utente in gestione
* @param int $userId
* @param bool $activeStatus
* @return \SHL\SdiClient\Types\User
* @return User
*/
public function editUserActiveStatus( $userId, bool $activeStatus ) {
$params = new Types\GenericType();
Expand Down Expand Up @@ -197,7 +219,7 @@ public function getDocumentSentList( $userId = null ) {
/**
* Ritorna i dettagli di un documento inviato
* @param int $id
* @return \SHL\SdiClient\Types\DocumentSent
* @return DocumentSent
*/
public function getDocumentSent( $id ) {
return new Types\DocumentSent(
Expand All @@ -208,8 +230,8 @@ public function getDocumentSent( $id ) {

/**
* Crea un nuovo documento da inviare allo sdi
* @param \SHL\SdiClient\Types\DocumentInfo $document
* @return \SHL\SdiClient\Types\DocumentSent
* @param DocumentInfo $document
* @return DocumentSent
*/
public function sendDocument( Types\DocumentInfo $document ) {
return new Types\DocumentSent(
Expand All @@ -233,7 +255,7 @@ public function getDocumentSentNotificationList( $documentId ) {
/**
* Ritorna i dettagli di una notifica di un documento
* @param int $id
* @return \SHL\SdiClient\Types\DocumentSentNotification
* @return DocumentSentNotification
*/
public function getDocumentSentNotification( $id ) {
return new Types\DocumentSentNotification(
Expand All @@ -245,7 +267,7 @@ public function getDocumentSentNotification( $id ) {
/**
* Ritorna l'allegato di una notifica
* @param int $id
* @return \SHL\SdiClient\Types\File
* @return File
*/
public function getDocumentSentNotificationFile( $id ) {
return new Types\File(
Expand Down Expand Up @@ -274,7 +296,7 @@ public function getDocumentReceivedList( $userId = null ) {
/**
* Ritorna i dettagli di un documento ricevuto
* @param int $id
* @return \SHL\SdiClient\Types\DocumentReceived
* @return DocumentReceived
*/
public function getDocumentReceived( $id ) {
return new Types\DocumentReceived(
Expand All @@ -286,7 +308,7 @@ public function getDocumentReceived( $id ) {
/**
* Ritorna il file del documento ricevuto
* @param int $id
* @return \SHL\SdiClient\Types\File
* @return File
*/
public function getDocumentReceivedFile( $id ) {
return new Types\File(
Expand All @@ -298,7 +320,7 @@ public function getDocumentReceivedFile( $id ) {
/**
* Ritorna il metafile del documento ricevuto
* @param int $id
* @return \SHL\SdiClient\Types\File
* @return File
*/
public function getDocumentReceivedMetafile( $id ) {
return new Types\File(
Expand Down Expand Up @@ -334,7 +356,7 @@ public function getDocumentReceivedNotification( $id ) {
/**
* Ritorna l'allegato di una notifica di un documento ricevuto
* @param int $id
* @return \SHL\SdiClient\Types\File
* @return File
*/
public function getDocumentReceivedNotificationFile( $id ) {
return new Types\File(
Expand All @@ -358,7 +380,7 @@ public function getOutcomeSentList( $documentId ) {
/**
* Ritorna i dettagli di una notifica di esito inviata
* @param int $id
* @return \SHL\SdiClient\Types\OutcomeSent
* @return OutcomeSent
*/
public function getOutcomeSent( $id ) {
return new Types\OutcomeSent(
Expand All @@ -370,7 +392,7 @@ public function getOutcomeSent( $id ) {
/**
* Ritorna l'allegato di una notifica di esito inviata
* @param int $id
* @return \SHL\SdiClient\Types\File
* @return File
*/
public function getOutcomeSentFile( $id ) {
return new Types\File(
Expand All @@ -382,7 +404,7 @@ public function getOutcomeSentFile( $id ) {
/**
* Ritorna il file che spiega l'errore di una notifica di esito inviata
* @param int $id
* @return \SHL\SdiClient\Types\File
* @return File
*/
public function getOutcomeSentErrorFile( $id ) {
$file = $this->curl( 'GET', '/outcome_sent/error_file/' . $id );
Expand All @@ -398,7 +420,7 @@ public function getOutcomeSentErrorFile( $id ) {
* Invia una nuova notifica di esito
* @param int $documentId L'id del documento ricevuto per il quale mandare la notifica
* @param \SHL\SdiClient\Types\OutcomeInfo $outcome
* @return \SHL\SdiClient\Types\OutcomeSent
* @return OutcomeSent
*/
public function sendOutcome( $documentId, Types\OutcomeInfo $outcome ) {
return new Types\OutcomeSent(
Expand Down

0 comments on commit 4f8fccf

Please sign in to comment.