]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/httpclient.php
Merge branch '0.8.x' into 0.9.x
[quix0rs-gnu-social.git] / lib / httpclient.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Utility for doing HTTP-related things
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  Action
23  * @package   StatusNet
24  * @author    Evan Prodromou <evan@status.net>
25  * @copyright 2009 StatusNet, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://status.net/
28  */
29
30 if (!defined('STATUSNET')) {
31     exit(1);
32 }
33
34 /**
35  * Useful structure for HTTP responses
36  *
37  * We make HTTP calls in several places, and we have several different
38  * ways of doing them. This class hides the specifics of what underlying
39  * library (curl or PHP-HTTP or whatever) that's used.
40  *
41  * @category HTTP
42  * @package  StatusNet
43  * @author   Evan Prodromou <evan@status.net>
44  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
45  * @link     http://status.net/
46  */
47
48 class HTTPResponse
49 {
50     public $code = null;
51     public $headers = array();
52     public $body = null;
53 }
54
55 /**
56  * Utility class for doing HTTP client stuff
57  *
58  * We make HTTP calls in several places, and we have several different
59  * ways of doing them. This class hides the specifics of what underlying
60  * library (curl or PHP-HTTP or whatever) that's used.
61  *
62  * @category HTTP
63  * @package  StatusNet
64  * @author   Evan Prodromou <evan@status.net>
65  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
66  * @link     http://status.net/
67  */
68
69 class HTTPClient
70 {
71     static $_client = null;
72
73     static function start()
74     {
75         if (!is_null(self::$_client)) {
76             return self::$_client;
77         }
78
79         $type = common_config('http', 'client');
80
81         switch ($type) {
82          case 'curl':
83             self::$_client = new CurlClient();
84             break;
85          default:
86             throw new Exception("Unknown HTTP client type '$type'");
87             break;
88         }
89
90         return self::$_client;
91     }
92
93     function head($url, $headers)
94     {
95         throw new Exception("HEAD method unimplemented");
96     }
97
98     function get($url, $headers)
99     {
100         throw new Exception("GET method unimplemented");
101     }
102
103     function post($url, $headers, $body)
104     {
105         throw new Exception("POST method unimplemented");
106     }
107
108     function put($url, $headers, $body)
109     {
110         throw new Exception("PUT method unimplemented");
111     }
112
113     function delete($url, $headers)
114     {
115         throw new Exception("DELETE method unimplemented");
116     }
117
118     function userAgent()
119     {
120         return "StatusNet/".STATUSNET_VERSION." (".STATUSNET_CODENAME.")";
121     }
122 }