Public Member Functions | Protected Attributes

Robo47_Curl Class Reference

List of all members.

Public Member Functions

 __clone ()
 Clone Instance.
 __construct ($url=null, $returnTransfer=true)
 __destruct ()
 close ()
 exec ()
 getBody ($noHeaders=true)
 Returns Contents return by curl_exec.
 getCurl ()
 getErrno ()
 getError ()
 getHeaders ($asArray=false)
 getInfo ($option)
 getInfoArray (array $options)
 getOptions ()
 getVersion ($age=0)
 setCurl ($curl)
 Using set/getCurl can break getOptions !!
 setOption ($option, $value)
 setOptions (array $options)

Protected Attributes

 $_body = ''
 $_curl = null
 $_options = array()

Detailed Description

Definition at line 26 of file Curl.php.


Constructor & Destructor Documentation

Robo47_Curl::__construct ( url = null,
returnTransfer = true 
)
Parameters:
string $url
boolean $returnTransfer

Definition at line 53 of file Curl.php.

References setOption().

    {
        $this->_curl = curl_init();
        if ($url != null) {
            $this->setOption(CURLOPT_URL, $url);
        }
        $this->setOption(CURLOPT_RETURNTRANSFER, $returnTransfer);
    }

Here is the call graph for this function:

Robo47_Curl::__destruct (  ) 

Definition at line 233 of file Curl.php.

References close().

    {
        $this->close();
    }

Here is the call graph for this function:


Member Function Documentation

Robo47_Curl::__clone (  ) 

Clone Instance.

Returns:
Robo47_Curl

Definition at line 213 of file Curl.php.

References getOptions(), and setOptions().

    {
        // resource can't be cloned, so we need to init a new one
        $this->_curl = curl_init();
        // needed for setting old options to the new curl-resource
        $this->setOptions($this->getOptions());
    }

Here is the call graph for this function:

Robo47_Curl::close (  ) 
Returns:
Robo47_Curl *Provides Fluent Interface*

Definition at line 202 of file Curl.php.

Referenced by __destruct().

    {
        @curl_close($this->_curl);
        return $this;
    }

Here is the caller graph for this function:

Robo47_Curl::exec (  ) 
Returns:
Robo47_Curl *Provides Fluent Interface*

Definition at line 123 of file Curl.php.

    {
        $this->_body = curl_exec($this->_curl);
        return $this;
    }

Robo47_Curl::getBody ( noHeaders = true  ) 

Returns Contents return by curl_exec.

Parameters:
boolean $noHeaders
Returns:
string

Definition at line 135 of file Curl.php.

    {
        if (true === $noHeaders) {
            $pos = strpos($this->_body, "\r\n\r\n");
            if (false !== $pos) {
                return substr($this->_body, $pos);
            } else {
                throw new Robo47_Curl_Exception('unable to find body');
            }
        }
        return $this->_body;
    }

Robo47_Curl::getCurl (  ) 
Returns:
resource

Definition at line 241 of file Curl.php.

Referenced by Robo47_Curl_Multi::addHandle(), and Robo47_Curl_Multi::removeHandle().

    {
        return $this->_curl;
    }

Here is the caller graph for this function:

Robo47_Curl::getErrno (  ) 
Returns:
integer

Definition at line 194 of file Curl.php.

    {
        return curl_errno($this->_curl);
    }

Robo47_Curl::getError (  ) 
Returns:
string

Definition at line 186 of file Curl.php.

    {
        return curl_error($this->_curl);
    }

Robo47_Curl::getHeaders ( asArray = false  ) 
Parameters:
boolean $asArray
Returns:
string

Definition at line 152 of file Curl.php.

    {
        if (isset($this->_options[CURLOPT_HEADER]) &&
            $this->_options[CURLOPT_HEADER] == true) {

            $pos = strpos($this->_body, "\r\n\r\n");
            if ($pos !== false) {
                $headers = substr($this->_body, 0, $pos);
            } else {
                $headers = '';
            }
        } else {
            $headers = '';
        }
        if (true === $asArray) {
            $headers = explode("\n", $headers);
            $aHeaders = array();
            foreach ($headers as $line) {
                $pos = strpos($line, ':');
                if (false !== $pos) {
                    $headerName = trim(substr($line, 0, $pos));
                    $headerValue = trim(substr($line, $pos + 1));
                    $aHeaders[$headerName] = $headerValue;
                }
            }
            return $aHeaders;
        } else {
            return $headers;
        }
    }

Robo47_Curl::getInfo ( option  ) 
Parameters:
integer $option
Returns:
mixed

Definition at line 102 of file Curl.php.

    {
        return curl_getinfo($this->_curl, $option);
    }

Robo47_Curl::getInfoArray ( array $  options  ) 
Parameters:
array $options
Returns:
array

Definition at line 111 of file Curl.php.

    {
        $infos = array();
        foreach ($options as $option) {
            $infos[$option] = curl_getinfo($this->_curl, $option);
        }
        return $infos;
    }

Robo47_Curl::getOptions (  ) 
Returns:
array

Definition at line 93 of file Curl.php.

Referenced by __clone(), and setCurl().

    {
        return $this->_options;
    }

Here is the caller graph for this function:

Robo47_Curl::getVersion ( age = 0  ) 
Parameters:
integer $age
Returns:
mixed

Definition at line 225 of file Curl.php.

    {
        return curl_version($age);
    }

Robo47_Curl::setCurl ( curl  ) 

Using set/getCurl can break getOptions !!

Parameters:
resource $curl

Definition at line 252 of file Curl.php.

References getOptions(), and setOptions().

    {
        if (!is_resource($curl) || get_resource_type($curl) !== 'curl') {
            throw new Robo47_Curl_Exception('$curl is not an curl-resource');
        }
        $this->setOptions($this->getOptions());
        $this->_curl = $curl;
    }

Here is the call graph for this function:

Robo47_Curl::setOption ( option,
value 
)
Parameters:
integer $option
mixed $value
Returns:
Robo47_Curl *Provides Fluent Interface*

Definition at line 67 of file Curl.php.

Referenced by __construct(), and setOptions().

    {
        $success = curl_setopt($this->_curl, $option, $value);
        if (false === $success) {
            $message = 'Error Setting Option: ' . (string) $option;
            throw new Robo47_Curl_Exception($message);
        }
        $this->_options[$option] = $value;
        return $this;
    }

Here is the caller graph for this function:

Robo47_Curl::setOptions ( array $  options  ) 
Parameters:
array $options
Returns:
Robo47_Curl *Provides Fluent Interface*

Definition at line 82 of file Curl.php.

References setOption().

Referenced by __clone(), and setCurl().

    {
        foreach ($options as $option => $value) {
            $this->setOption($option, $value);
        }
        return $this;
    }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Robo47_Curl::$_body = '' [protected]

Definition at line 47 of file Curl.php.

Robo47_Curl::$_curl = null [protected]

Definition at line 41 of file Curl.php.

Robo47_Curl::$_options = array() [protected]

Definition at line 35 of file Curl.php.


The documentation for this class was generated from the following file: