<?php
declare(strict_types=1);
namespace App\Providers;
use App\Model\PropertiesListing;
use App\Model\Property;
use Symfony\Component\HttpClient\HttpClient;
class DirectorProvider
{
private const ENDPOINT_GET = '/unit/data/';
private const ENDPOINT_PROPERTIES = '/unit/get-available-units';
private $client;
public function __construct(string $directorUrl)
{
$this->client = HttpClient::createForBaseUri($directorUrl, []);
}
public function getData(int $idMyrooms): array
{
$response = $this->client->request(
'GET',
self::ENDPOINT_GET.$idMyrooms,
[
]
);
return $response->toArray();
}
public function getProperties(int $page, int $limit, string $search = null): PropertiesListing
{
$response = $this->client->request(
'GET',
self::ENDPOINT_PROPERTIES,
[
'query' => [
'page' => $page,
'limit' => $limit,
]
]
);
$propertiesListing = new PropertiesListing();
foreach($response->toArray() as $row) {
$propertiesListing->addProperties(Property::fromDirectorSearch($row));
}
//$propertiesListing->setTotal((int)$headers['x-wp-total'][0]);
//$propertiesListing->setTotalPages((int)$headers['x-wp-totalpages'][0]);
return $propertiesListing;
}
}