src/Chatkit.php
protected function createRawCurl($request_method, $url, $body = null, $content_type = null, $jwt = null, $encode_json = false)
    {
        // Create or reuse existing curl handle
        if (null === $this->ch) {
            $this->ch = curl_init();
        }

        if ($this->ch === false) {
            throw new ConfigurationException('Could not initialise cURL!');
        }

        $ch = $this->ch;

        // curl handle is not reusable unless reset
        if (function_exists('curl_reset')) {
            curl_reset($ch);
        }

        $headers = array();

        if(!is_null($jwt)) {
            array_push($headers, 'Authorization: Bearer '.$jwt);
        }
        if(!is_null($content_type)) {
            array_push($headers, 'Content-Type: '.$content_type);
        }
        // Set cURL opts and execute request
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_TIMEOUT, $this->settings['timeout']);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $request_method);

        if (!is_null($body)) {
            if ($encode_json) {
                $body = json_encode($body, JSON_ERROR_UTF8);
                array_push($headers, 'Content-Type: application/json');
            }
            curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
            array_push($headers, 'Content-Length: '.strlen($body));
        }
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

        // Set custom curl options
        if (!empty($this->settings['curl_options'])) {
            foreach ($this->settings['curl_options'] as $option => $value) {
                curl_setopt($ch, $option, $value);
            }
        }

        return $ch;
    }
protected function createRawCurl($request_method, $url, $body = null, $content_type = null, $jwt = null, $encode_json = false)
    {
        // Create or reuse existing curl handle
        if (null === $this->ch) {
            $this->ch = curl_init();
        }

        if ($this->ch === false) {
            throw new ConfigurationException('Could not initialise cURL!');
        }

        $ch = $this->ch;

        // curl handle is not reusable unless reset
        if (function_exists('curl_reset')) {
            curl_reset($ch);
        }

        $headers = array();

        if(!is_null($jwt)) {
            array_push($headers, 'Authorization: Bearer '.$jwt);
        }
        if(!is_null($content_type)) {
            array_push($headers, 'Content-Type: '.$content_type);
        }
        // Set cURL opts and execute request
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_TIMEOUT, $this->settings['timeout']);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $request_method);

        if (!is_null($body)) {
            if ($encode_json) {
                $body = json_encode($body, JSON_ERROR_UTF8);
                array_push($headers, 'Content-Type: application/json');
            }
            curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
            array_push($headers, 'Content-Length: '.strlen($body));
        }
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

        // Set custom curl options
        if (!empty($this->settings['curl_options'])) {
            foreach ($this->settings['curl_options'] as $option => $value) {
                curl_setopt($ch, $option, $value);
            }
        }

        return $ch;
    }
protected function createRawCurl ( $ request_method , $ url , $ body = null , $ content_type = null , $ jwt = null , $ encode_json = false ) { // Create or reuse existing curl handle if ( null === $ this -> ch ) { $ this -> ch = curl_init ( ) ; } if ( $ this -> ch === false ) { throw new ConfigurationException ( 'Could not initialise cURL!' ) ; } $ ch = $ this -> ch ; // curl handle is not reusable unless reset if ( function_exists ( 'curl_reset' ) ) { curl_reset ( $ ch ) ; } $ headers = array ( ) ; if ( ! is_null ( $ jwt ) ) { array_push ( $ headers , 'Authorization: Bearer ' . $ jwt ) ; } if ( ! is_null ( $ content_type ) ) { array_push ( $ headers , 'Content-Type: ' . $ content_type ) ; } // Set cURL opts and execute request curl_setopt ( $ ch , CURLOPT_URL , $ url ) ; curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , 1 ) ; curl_setopt ( $ ch , CURLOPT_TIMEOUT , $ this -> settings [ 'timeout' ] ) ; curl_setopt ( $ ch , CURLOPT_CUSTOMREQUEST , $ request_method ) ; if ( ! is_null ( $ body ) ) { if ( $ encode_json ) { $ body = json_encode ( $ body , JSON_ERROR_UTF8 ) ; array_push ( $ headers , 'Content-Type: application/json' ) ; } curl_setopt ( $ ch , CURLOPT_POSTFIELDS , $ body ) ; array_push ( $ headers , 'Content-Length: ' . strlen ( $ body ) ) ; } curl_setopt ( $ ch , CURLOPT_HTTPHEADER , $ headers ) ; // Set custom curl options if ( ! empty ( $ this -> settings [ 'curl_options' ] ) ) { foreach ( $ this -> settings [ 'curl_options' ] as $ option => $ value ) { curl_setopt ( $ ch , $ option , $ value ) ; } } return $ ch ; }
Utility function used to create the curl object with common settings.
Utility function used to create the curl object with common settings .