Deprecated : Constant E_STRICT is deprecated in /home/pastorz/old-espace-client/vendor/symfony/error-handler/ErrorHandler.php on line 58
Deprecated : Constant E_STRICT is deprecated in /home/pastorz/old-espace-client/vendor/symfony/error-handler/ErrorHandler.php on line 76
Symfony Profiler
<?php
namespace App\Service ;
use GuzzleHttp\Client ;
use GuzzleHttp\Exception\GuzzleException ;
use GuzzleHttp\RequestOptions ;
use Psr\Http\Message\ResponseInterface ;
class KheopsService
{
private const BASE_URL = 'https://srv8.3PI.fr' ;
private const ENDPOINTS = array(
'getItems' => '/Access/GetItems' ,
'getBatch' => '/Access/GetBatchByBarcode' ,
'getImage' => '/Access/GetImageBatch'
);
/**
* @param string $deliveryNoteCode
* @return array|null
* @throws GuzzleException
*/
public function getItems ( string $deliveryNoteCode ): ?array
{
$response = $this -> call ( 'POST' , self :: ENDPOINTS [ __FUNCTION__ ], array( 'codeBarre' => $deliveryNoteCode ));
return json_decode ( $response -> getBody ()-> getContents ());
}
/**
* @param string $barcode
* @return array|null
* @throws GuzzleException
*/
public function getBatch ( string $barcode ): mixed
{
$response = $this -> call ( 'GET' , self :: ENDPOINTS [ __FUNCTION__ ], null , array( 'barcode' => $barcode ));
return json_decode ( $response -> getBody ()-> getContents ());
}
/**
* @param string $id
* @return object|mixed
* @throws GuzzleException
*/
public function getImage ( string $id ): mixed
{
$response = $this -> call ( 'GET' , self :: ENDPOINTS [ __FUNCTION__ ], null , array( 'idImage' => $id ));
return json_decode ( $response -> getBody ()-> getContents ());
}
/**
* @param string $method
* @param string $endpoint
* @param array|null $bodyParams
* @param array $queryParams
* @return ResponseInterface
* @throws GuzzleException
*/
private function call ( string $method , string $endpoint , array $bodyParams = null , array $queryParams = array()): ResponseInterface
{
$httpClient = new Client ();
return $httpClient -> request ( $method , self :: BASE_URL . $endpoint . '?' . http_build_query ( $queryParams ), array( RequestOptions :: JSON => $bodyParams ));
}
}