<?php
namespace App\Controller\Front;
use App\Repository\ContentRepository;
use App\Repository\SliderHeaderRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\HttpClient\HttpClientInterface;
class HomeController extends AbstractController
{
const API_LINK = 'https://middleware-production.easy2pilot-v8.com/api/';
/**
* @var HttpClientInterface
*/
private HttpClientInterface $httpClient;
public function __construct(HttpClientInterface $httpClient)
{
$this->httpClient = $httpClient;
}
/**
* @Route("/", name="front_home")
*/
public function home(ContentRepository $contentRepository, SliderHeaderRepository $sliderHeaderRepository)
{
return $this->render('front/home.html.twig', [
'content_header' => $contentRepository->findOneBy(['page' => 'home', 'section' => 'header']),
'content_sale' => $contentRepository->findOneBy(['page' => 'home', 'section' => 'sale']),
'content_rent' => $contentRepository->findOneBy(['page' => 'home', 'section' => 'rent']),
'slider' => $sliderHeaderRepository->findOneBy(['page' => 'accueil']),
]);
}
private function getToken()
{
$response = $this->httpClient->request(
Request::METHOD_POST,
self::API_LINK . $this->getParameter('api_uuid').'/token', [
'headers' => [
'login' => $this->getParameter('api_login'),
'password' => $this->getParameter('api_password'),
],
]
);
return $response->toArray()['data']['token'];
}
}