Voodoo\Core\Helpers::curlRequest PHP Method

curlRequest() public static method

To make a simple curl request For more advanced curl request, use the Guzzle library
public static curlRequest ( string $url, mixed $params = [], string $method = "GET", array $curlOptions = [] ) : Array
$url string
$params mixed
$method string (GET | POST | DELETE | PUT)
$curlOptions array
return Array [(string)response, (array)response_json, (array)headers]
    public static function curlRequest($url, $params = [], $method = "GET", array $curlOptions = [])
    {
        $ch = curl_init();
        $strParams = is_array($params) ? http_build_query($params) : $params;
        // Method
        switch (strtoupper($method)) {
            default:
            case "GET":
                $url .= (strpos($url, "?") === FALSE ? "?" : "&") . $strParams;
                break;
            case "POST":
                curl_setopt($ch, CURLOPT_POST, true);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
                break;
            case "PUT":
            case "DELETE":
                curl_setopt($ch, CURLOPT_CUSTOMREQUEST, strtoupper($method));
                curl_setopt($ch, CURLOPT_POSTFIELDS, $strParams);
                break;
        }
        // Secure Url
        if (preg_match("!^https://!", $url)) {
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
        }
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_ENCODING, 1);
        if (count($curlOptions)) {
            curl_setopt_array($ch, $curlOptions);
        }
        $response = curl_exec($ch);
        $headers = curl_getinfo($ch);
        $data = ["response" => $response, "response_json" => json_decode($response, true), "headers" => $headers];
        $error = curl_error($ch);
        $errorNo = curl_errno($ch);
        curl_close($ch);
        if ($data["response"] === FALSE) {
            throw new \Exception($error, $errorNo);
        } else {
            return $data;
        }
    }