protected function buildRequest()
    {
        if (self::STATE_NEW === $this->state)
        {
            throw new \RuntimeException(sprintf(
                '%s::execute - Could not execute request, curl has not been initialized.',
                get_class($this)
            ));
        }

        if (self::STATE_EXECUTED === $this->state)
            $this->close();

        if (self::STATE_CLOSED === $this->state)
            $this->initialize($this->currentRequestUrl, false);

        // Create curl handle resource
        $this->ch = curl_init($this->currentRequestUrl);
        if (false === $this->ch)
        {
            throw new \RuntimeException(sprintf(
                'Unable to initialize curl with url: %s',
                $this->getRequestUrl()
            ));
        }

        // Set the Header array (if any)
        if (count($this->requestHeaders) > 0)
        {
            $headers = array();
            foreach($this->requestHeaders as $k=>$v)
            {
                $headers[] = vsprintf('%s: %s', array($k, $v));
            }
            $this->setCurlOpt(CURLOPT_HTTPHEADER, $headers);
        }

        // Return the Request Header as part of the curl_info array unless they specify otherwise
        if (!$this->curlOptSet(CURLINFO_HEADER_OUT))
            $this->setCurlOpt(CURLINFO_HEADER_OUT, true);

        // If the user has opted to return the data, rather than save to file or output directly,
        // attempt to get headers back in the response for later use if they have not specified
        // otherwise.
        if ($this->getCurlOptValue(CURLOPT_RETURNTRANSFER) && !$this->curlOptSet(CURLOPT_HEADER))
            $this->setCurlOpt(CURLOPT_HEADER, true);

        // Set the CURLOPTS
        if (false === curl_setopt_array($this->ch, $this->curlOpts))
        {
            throw new \RuntimeException(sprintf(
                'Unable to specify curl options, please ensure you\'re passing in valid constants.  Specified opts: %s',
                json_encode($this->getCurlOpts())
            ));
        }
    }
protected function buildRequest()
    {
        if (self::STATE_NEW === $this->state)
        {
            throw new \RuntimeException(sprintf(
                '%s::execute - Could not execute request, curl has not been initialized.',
                get_class($this)
            ));
        }

        if (self::STATE_EXECUTED === $this->state)
            $this->close();

        if (self::STATE_CLOSED === $this->state)
            $this->initialize($this->currentRequestUrl, false);

        // Create curl handle resource
        $this->ch = curl_init($this->currentRequestUrl);
        if (false === $this->ch)
        {
            throw new \RuntimeException(sprintf(
                'Unable to initialize curl with url: %s',
                $this->getRequestUrl()
            ));
        }

        // Set the Header array (if any)
        if (count($this->requestHeaders) > 0)
        {
            $headers = array();
            foreach($this->requestHeaders as $k=>$v)
            {
                $headers[] = vsprintf('%s: %s', array($k, $v));
            }
            $this->setCurlOpt(CURLOPT_HTTPHEADER, $headers);
        }

        // Return the Request Header as part of the curl_info array unless they specify otherwise
        if (!$this->curlOptSet(CURLINFO_HEADER_OUT))
            $this->setCurlOpt(CURLINFO_HEADER_OUT, true);

        // If the user has opted to return the data, rather than save to file or output directly,
        // attempt to get headers back in the response for later use if they have not specified
        // otherwise.
        if ($this->getCurlOptValue(CURLOPT_RETURNTRANSFER) && !$this->curlOptSet(CURLOPT_HEADER))
            $this->setCurlOpt(CURLOPT_HEADER, true);

        // Set the CURLOPTS
        if (false === curl_setopt_array($this->ch, $this->curlOpts))
        {
            throw new \RuntimeException(sprintf(
                'Unable to specify curl options, please ensure you\'re passing in valid constants.  Specified opts: %s',
                json_encode($this->getCurlOpts())
            ));
        }
    }
protected function buildRequest ( ) { if ( self :: STATE_NEW === $ this -> state ) { throw new \ RuntimeException ( sprintf ( '%s::execute - Could not execute request, curl has not been initialized.' , get_class ( $ this ) ) ) ; } if ( self :: STATE_EXECUTED === $ this -> state ) $ this -> close ( ) ; if ( self :: STATE_CLOSED === $ this -> state ) $ this -> initialize ( $ this -> currentRequestUrl , false ) ; // Create curl handle resource $ this -> ch = curl_init ( $ this -> currentRequestUrl ) ; if ( false === $ this -> ch ) { throw new \ RuntimeException ( sprintf ( 'Unable to initialize curl with url: %s' , $ this -> getRequestUrl ( ) ) ) ; } // Set the Header array (if any) if ( count ( $ this -> requestHeaders ) > 0 ) { $ headers = array ( ) ; foreach ( $ this -> requestHeaders as $ k => $ v ) { $ headers [ ] = vsprintf ( '%s: %s' , array ( $ k , $ v ) ) ; } $ this -> setCurlOpt ( CURLOPT_HTTPHEADER , $ headers ) ; } // Return the Request Header as part of the curl_info array unless they specify otherwise if ( ! $ this -> curlOptSet ( CURLINFO_HEADER_OUT ) ) $ this -> setCurlOpt ( CURLINFO_HEADER_OUT , true ) ; // If the user has opted to return the data, rather than save to file or output directly, // attempt to get headers back in the response for later use if they have not specified // otherwise. if ( $ this -> getCurlOptValue ( CURLOPT_RETURNTRANSFER ) && ! $ this -> curlOptSet ( CURLOPT_HEADER ) ) $ this -> setCurlOpt ( CURLOPT_HEADER , true ) ; // Set the CURLOPTS if ( false === curl_setopt_array ( $ this -> ch , $ this -> curlOpts ) ) { throw new \ RuntimeException ( sprintf ( 'Unable to specify curl options, please ensure you\'re passing in valid constants.  Specified opts: %s' , json_encode ( $ this -> getCurlOpts ( ) ) ) ) ; } }
Attempts to set up the client for a request, throws an exception if it cannot
Attempts to set up the client for a request throws an exception if it cannot