Remote::send PHP Method

send() protected method

Sets up all curl options and sends the request
protected send ( ) : object
return object Response
    protected function send()
    {
        // start a curl request
        $curl = curl_init();
        // curl options
        $params = array(CURLOPT_URL => $this->options['url'], CURLOPT_ENCODING => $this->options['encoding'], CURLOPT_CONNECTTIMEOUT => $this->options['timeout'], CURLOPT_TIMEOUT => $this->options['timeout'], CURLOPT_AUTOREFERER => true, CURLOPT_RETURNTRANSFER => $this->options['body'], CURLOPT_FOLLOWLOCATION => true, CURLOPT_MAXREDIRS => 10, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_HEADER => false, CURLOPT_HEADERFUNCTION => array($this, 'header'));
        // add the progress
        if (is_callable($this->options['progress'])) {
            $params[CURLOPT_NOPROGRESS] = false;
            $params[CURLOPT_PROGRESSFUNCTION] = $this->options['progress'];
        }
        // add all headers
        if (!empty($this->options['headers'])) {
            $params[CURLOPT_HTTPHEADER] = $this->options['headers'];
        }
        // add the user agent
        if (!empty($this->options['agent'])) {
            $params[CURLOPT_USERAGENT] = $this->options['agent'];
        }
        // do some request specific stuff
        switch (strtolower($this->options['method'])) {
            case 'post':
                $params[CURLOPT_POST] = true;
                $params[CURLOPT_POSTFIELDS] = $this->postfields($this->options['data']);
                break;
            case 'put':
                $params[CURLOPT_CUSTOMREQUEST] = 'PUT';
                $params[CURLOPT_POSTFIELDS] = $this->postfields($this->options['data']);
                // put a file
                if ($this->options['file']) {
                    $params[CURLOPT_INFILE] = fopen($this->options['file'], 'r');
                    $params[CURLOPT_INFILESIZE] = f::size($this->options['file']);
                }
                break;
            case 'delete':
                $params[CURLOPT_CUSTOMREQUEST] = 'DELETE';
                $params[CURLOPT_POSTFIELDS] = $this->postfields($this->options['data']);
                break;
            case 'head':
                $params[CURLOPT_CUSTOMREQUEST] = 'HEAD';
                $params[CURLOPT_POSTFIELDS] = $this->postfields($this->options['data']);
                $params[CURLOPT_NOBODY] = true;
                break;
        }
        curl_setopt_array($curl, $params);
        $content = curl_exec($curl);
        $error = curl_errno($curl);
        $message = curl_error($curl);
        $info = curl_getinfo($curl);
        curl_close($curl);
        $this->response = new RemoteResponse();
        $this->response->headers = $this->headers;
        $this->response->error = $error;
        $this->response->message = $message;
        $this->response->content = $content;
        $this->response->code = $info['http_code'];
        $this->response->info = $info;
        return $this->response;
    }