src/Common/Curl.php
public function send($url, array $params = array())
    {
        $out = array();

        $default = array(
            'get' => array(),
            'post' => array(),
            'headers' => array(),
            'cookies' => false,
            'gzip' => true,
        );

        $params = array_merge($default, $params);


        // Get Params //
        if (is_array($params['get']) && !empty($params['get'])) {
            $getParams = $this->getParams($params['get']);

            if (!empty($getParams)) {
                $url = $url . '?' . $getParams;
            }
        } elseif (is_string($params['get']) && !empty($params['get'])) {
            $url = $url . '?' . $params['get'];
        }


        // Curl Options //
        $options = array_replace(
            $this->getOptions(),
            array(
                CURLOPT_URL => $url,
                CURLOPT_USERAGENT => 'TwitterOAuth for v1.1 API (https://github.com/ricardoper/TwitterOAuth)',
            )
        );


        // Post Params //
        if (is_array($params['post']) && !empty($params['post'])) {
            $options[CURLOPT_POST] = count($params['post']);
            $options[CURLOPT_POSTFIELDS] = $this->getParams($params['post']);
        } elseif (is_string($params['post']) && !empty($params['post'])) {
            $options[CURLOPT_POST] = 1;
            $options[CURLOPT_POSTFIELDS] = $params['post'];
        }


        // Headers //
        if (is_array($params['headers']) && !empty($params['headers'])) {
            $options[CURLOPT_HTTPHEADER] = $params['headers'];
        }


        // Cookies Filename //
        if ($params['cookies'] !== false) {
            $options[CURLOPT_COOKIEJAR] = $params['cookies'];
            $options[CURLOPT_COOKIEFILE] = $params['cookies'];
        }


        // Gzip & Deflate //
        if ($params['gzip'] === true) {
            $options[CURLOPT_ENCODING] = 'gzip,deflate';
        }


        // Run Curl //
        $c = curl_init();

        curl_setopt_array($c, $options);

        $response = curl_exec($c);

        if (curl_errno($c) !== 0) {
            throw new CurlException(curl_error($c), curl_errno($c));
        }

        $cInfo = curl_getinfo($c);

        curl_close($c);


        // Process Response //
        $out['headers'] = $this->processHeaders(substr($response, 0, $cInfo['header_size']));

        $out['body'] = trim(substr($response, $cInfo['header_size']));

        unset($params, $options, $c, $cInfo, $response);

        return $out;
    }
public function send($url, array $params = array())
    {
        $out = array();

        $default = array(
            'get' => array(),
            'post' => array(),
            'headers' => array(),
            'cookies' => false,
            'gzip' => true,
        );

        $params = array_merge($default, $params);


        // Get Params //
        if (is_array($params['get']) && !empty($params['get'])) {
            $getParams = $this->getParams($params['get']);

            if (!empty($getParams)) {
                $url = $url . '?' . $getParams;
            }
        } elseif (is_string($params['get']) && !empty($params['get'])) {
            $url = $url . '?' . $params['get'];
        }


        // Curl Options //
        $options = array_replace(
            $this->getOptions(),
            array(
                CURLOPT_URL => $url,
                CURLOPT_USERAGENT => 'TwitterOAuth for v1.1 API (https://github.com/ricardoper/TwitterOAuth)',
            )
        );


        // Post Params //
        if (is_array($params['post']) && !empty($params['post'])) {
            $options[CURLOPT_POST] = count($params['post']);
            $options[CURLOPT_POSTFIELDS] = $this->getParams($params['post']);
        } elseif (is_string($params['post']) && !empty($params['post'])) {
            $options[CURLOPT_POST] = 1;
            $options[CURLOPT_POSTFIELDS] = $params['post'];
        }


        // Headers //
        if (is_array($params['headers']) && !empty($params['headers'])) {
            $options[CURLOPT_HTTPHEADER] = $params['headers'];
        }


        // Cookies Filename //
        if ($params['cookies'] !== false) {
            $options[CURLOPT_COOKIEJAR] = $params['cookies'];
            $options[CURLOPT_COOKIEFILE] = $params['cookies'];
        }


        // Gzip & Deflate //
        if ($params['gzip'] === true) {
            $options[CURLOPT_ENCODING] = 'gzip,deflate';
        }


        // Run Curl //
        $c = curl_init();

        curl_setopt_array($c, $options);

        $response = curl_exec($c);

        if (curl_errno($c) !== 0) {
            throw new CurlException(curl_error($c), curl_errno($c));
        }

        $cInfo = curl_getinfo($c);

        curl_close($c);


        // Process Response //
        $out['headers'] = $this->processHeaders(substr($response, 0, $cInfo['header_size']));

        $out['body'] = trim(substr($response, $cInfo['header_size']));

        unset($params, $options, $c, $cInfo, $response);

        return $out;
    }
public function send ( $ url , array $ params = array ( ) ) { $ out = array ( ) ; $ default = array ( 'get' => array ( ) , 'post' => array ( ) , 'headers' => array ( ) , 'cookies' => false , 'gzip' => true , ) ; $ params = array_merge ( $ default , $ params ) ; // Get Params // if ( is_array ( $ params [ 'get' ] ) && ! empty ( $ params [ 'get' ] ) ) { $ getParams = $ this -> getParams ( $ params [ 'get' ] ) ; if ( ! empty ( $ getParams ) ) { $ url = $ url . '?' . $ getParams ; } } elseif ( is_string ( $ params [ 'get' ] ) && ! empty ( $ params [ 'get' ] ) ) { $ url = $ url . '?' . $ params [ 'get' ] ; } // Curl Options // $ options = array_replace ( $ this -> getOptions ( ) , array ( CURLOPT_URL => $ url , CURLOPT_USERAGENT => 'TwitterOAuth for v1.1 API (https://github.com/ricardoper/TwitterOAuth)' , ) ) ; // Post Params // if ( is_array ( $ params [ 'post' ] ) && ! empty ( $ params [ 'post' ] ) ) { $ options [ CURLOPT_POST ] = count ( $ params [ 'post' ] ) ; $ options [ CURLOPT_POSTFIELDS ] = $ this -> getParams ( $ params [ 'post' ] ) ; } elseif ( is_string ( $ params [ 'post' ] ) && ! empty ( $ params [ 'post' ] ) ) { $ options [ CURLOPT_POST ] = 1 ; $ options [ CURLOPT_POSTFIELDS ] = $ params [ 'post' ] ; } // Headers // if ( is_array ( $ params [ 'headers' ] ) && ! empty ( $ params [ 'headers' ] ) ) { $ options [ CURLOPT_HTTPHEADER ] = $ params [ 'headers' ] ; } // Cookies Filename // if ( $ params [ 'cookies' ] !== false ) { $ options [ CURLOPT_COOKIEJAR ] = $ params [ 'cookies' ] ; $ options [ CURLOPT_COOKIEFILE ] = $ params [ 'cookies' ] ; } // Gzip & Deflate // if ( $ params [ 'gzip' ] === true ) { $ options [ CURLOPT_ENCODING ] = 'gzip,deflate' ; } // Run Curl // $ c = curl_init ( ) ; curl_setopt_array ( $ c , $ options ) ; $ response = curl_exec ( $ c ) ; if ( curl_errno ( $ c ) !== 0 ) { throw new CurlException ( curl_error ( $ c ) , curl_errno ( $ c ) ) ; } $ cInfo = curl_getinfo ( $ c ) ; curl_close ( $ c ) ; // Process Response // $ out [ 'headers' ] = $ this -> processHeaders ( substr ( $ response , 0 , $ cInfo [ 'header_size' ] ) ) ; $ out [ 'body' ] = trim ( substr ( $ response , $ cInfo [ 'header_size' ] ) ) ; unset ( $ params , $ options , $ c , $ cInfo , $ response ) ; return $ out ; }
Send a request

@param string $url Request URL
@param array $params Configuration array
@return array  Headers & Body
@throws CurlException
Send a request