<?php
declare(strict_types=1);

namespace App\Controllers;

class CurlController
{
    function curlGet(string $url, array $headers = []): false|string
    {
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_TIMEOUT, 10);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
        curl_setopt($ch, CURLOPT_USERAGENT, "Eventos/1.0 (dev@mogiguacu.sp.gov.br)");
        
        if (!empty($headers)) {
            curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        }

        $response = curl_exec($ch);

        $error = curl_errno($ch) ? curl_error($ch) : null;
        curl_close($ch);

        return $error ? false : $response;
    }
}