src/Providers/DirectorProvider.php line 35

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Providers;
  4. use App\Model\PropertiesListing;
  5. use App\Model\Property;
  6. use Symfony\Component\HttpClient\HttpClient;
  7. class DirectorProvider
  8. {
  9.     private const ENDPOINT_GET '/unit/data/';
  10.     private const ENDPOINT_PROPERTIES '/unit/get-available-units';
  11.     private $client;
  12.     public function __construct(string $directorUrl)
  13.     {
  14.         $this->client HttpClient::createForBaseUri($directorUrl, []);
  15.     }
  16.     public function getData(int $idMyrooms): array
  17.     {
  18.         $response $this->client->request(
  19.             'GET',
  20.             self::ENDPOINT_GET.$idMyrooms,
  21.             [
  22.             ]
  23.         );
  24.         return $response->toArray();
  25.     }
  26.     public function getProperties(int $pageint $limitstring $search null): PropertiesListing
  27.     {
  28.         $response $this->client->request(
  29.             'GET',
  30.             self::ENDPOINT_PROPERTIES,
  31.             [
  32.                 'query' => [
  33.                     'page' => $page,
  34.                     'limit' => $limit,
  35.                 ]
  36.             ]
  37.         );
  38.         $propertiesListing = new PropertiesListing();
  39.         foreach($response->toArray() as $row) {
  40.             $propertiesListing->addProperties(Property::fromDirectorSearch($row));
  41.         }
  42.         //$propertiesListing->setTotal((int)$headers['x-wp-total'][0]);
  43.         //$propertiesListing->setTotalPages((int)$headers['x-wp-totalpages'][0]);
  44.         return $propertiesListing;
  45.     }
  46. }