PageRenderTime 11ms CodeModel.GetById 6ms app.highlight 2ms RepoModel.GetById 0ms app.codeStats 1ms

/plugin/PBAPI/PBAPI/Request/curl.php

https://bitbucket.org/chamilo/chamilo-ext-repo-photobucket-dev/
PHP | 73 lines | 31 code | 10 blank | 32 comment | 4 complexity | 7ac93707136eead1eeb7d94d070fabc8 MD5 | raw file
 1<?php
 2use common\libraries\Path;
 3/**
 4 * Photobucket API 
 5 * Fluent interface for PHP5
 6 * CURL request interface
 7 * 
 8 * @author Photobucket
 9 * @package PBAPI
10 * @subpackage Request
11 * 
12 * @copyright Copyright Copyright (c) 2008, Photobucket, Inc.
13 * @license http://www.opensource.org/licenses/mit-license.php The MIT License
14 */
15
16/**
17 * Load Request parent
18 */
19require_once dirname(__FILE__) . '/../Request.php';
20
21/**
22 * CURL request strategy
23 * Requires CURL to be available and loaded
24 * 
25 * @package PBAPI
26 * @subpackage Request
27 */
28class PBAPI_Request_curl extends PBAPI_Request
29{
30
31    /**
32     * Do actual request
33     *
34     * @param string $method
35     * @param string $uri
36     * @param array $params
37     * @return string
38     */
39    protected function request($method, $uri, $params = array())
40    {
41        $url = $this->preRequest($method, $uri, $params);
42        
43        $curl_opts = $this->request_params;
44        
45        //overridable
46        if (empty($curl_opts[CURLOPT_USERAGENT]))
47            $curl_opts[CURLOPT_USERAGENT] = __CLASS__;
48        
49     //static
50        $curl_opts[CURLOPT_HEADER] = 0;
51        $curl_opts[CURLOPT_FOLLOWLOCATION] = 1;
52        $curl_opts[CURLOPT_RETURNTRANSFER] = 1;
53        $curl_opts[CURLOPT_CUSTOMREQUEST] = $method;
54        if ($method == 'POST')
55        {
56            $curl_opts[CURLOPT_POST] = 1;
57            $curl_opts[CURLOPT_POSTFIELDS] = $params;
58        }
59        $ch = curl_init($url);
60        curl_setopt_array($ch, $curl_opts);
61        $data = curl_exec($ch);
62        
63        if ($cerror = curl_errno($ch))
64        {
65            throw new PBAPI_Exception('CURL: ' . curl_error($ch), $cerror);
66        }
67        
68        curl_close($ch);
69        
70        return $data;
71    }
72
73}