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

src/Service/KheopsService.php line 64

Open in your IDE?
  1. <?php
  2. namespace App\Service;
  3. use GuzzleHttp\Client;
  4. use GuzzleHttp\Exception\GuzzleException;
  5. use GuzzleHttp\RequestOptions;
  6. use Psr\Http\Message\ResponseInterface;
  7. class KheopsService
  8. {
  9.     private const BASE_URL 'https://srv8.3PI.fr';
  10.     private const ENDPOINTS = array(
  11.         'getItems' => '/Access/GetItems',
  12.         'getBatch' => '/Access/GetBatchByBarcode',
  13.         'getImage' => '/Access/GetImageBatch'
  14.     );
  15.     /**
  16.      * @param string $deliveryNoteCode
  17.      * @return array|null
  18.      * @throws GuzzleException
  19.      */
  20.     public function getItems(string $deliveryNoteCode): ?array
  21.     {
  22.         $response $this->call('POST'self::ENDPOINTS[__FUNCTION__], array('codeBarre' => $deliveryNoteCode));
  23.         return json_decode($response->getBody()->getContents());
  24.     }
  25.     /**
  26.      * @param string $barcode
  27.      * @return array|null
  28.      * @throws GuzzleException
  29.      */
  30.     public function getBatch(string $barcode): mixed
  31.     {
  32.         $response $this->call('GET'self::ENDPOINTS[__FUNCTION__], null, array('barcode' => $barcode));
  33.         return json_decode($response->getBody()->getContents());
  34.     }
  35.     /**
  36.      * @param string $id
  37.      * @return object|mixed
  38.      * @throws GuzzleException
  39.      */
  40.     public function getImage(string $id): mixed
  41.     {
  42.         $response $this->call('GET'self::ENDPOINTS[__FUNCTION__], null, array('idImage' => $id));
  43.         return json_decode($response->getBody()->getContents());
  44.     }
  45.     /**
  46.      * @param string $method
  47.      * @param string $endpoint
  48.      * @param array|null $bodyParams
  49.      * @param array $queryParams
  50.      * @return ResponseInterface
  51.      * @throws GuzzleException
  52.      */
  53.     private function call(string $methodstring $endpoint, array $bodyParams null, array $queryParams = array()): ResponseInterface
  54.     {
  55.         $httpClient = new Client();
  56.         return $httpClient->request($methodself::BASE_URL $endpoint '?' http_build_query($queryParams), array(RequestOptions::JSON => $bodyParams));
  57.     }
  58. }