<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
class CitySuggestController extends AbstractController
{
/**
* @Route("/city_suggest", name="city_suggest")
*/
public function index()
{
//@todo: make caching here
$request = Request::createFromGlobals();
$limit = $request->query->get('limit');
if(empty($limit)) $limit = 10;
$query = $request->query->get('q');
$avtd_query = 'https://api.avtodispetcher.ru/v1/cities?limit=' . $limit . '&q=' . urlencode($query);
if(mb_strlen($query) > 2)
$res = '{"data":' . file_get_contents($avtd_query) . '}';
else
$res = json_encode([]);
$response = new Response();
//$response->setContent(json_encode($array_of_suggestions));
$response->setContent($res);
$response->headers->set('Content-Type', 'application/json');
$response->headers->set('Access-Control-Allow-Origin', 'https://moto.tours');
return $response;
}
}