[BUGFIX] Fatal error if pear package http_request2 is installed
[Packages/TYPO3.CMS.git] / t3lib / http / class.t3lib_http_request.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2011 Philipp Gampe <dev.typo3@philippgampe.info>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 if (!class_exists('HTTP_request2')) {
26 t3lib_div::requireOnce('HTTP/Request2.php');
27 }
28
29 /**
30 * HTTP Request Utility class
31 *
32 * Extends HTTP_Request2 and sets TYPO3 environment defaults
33 *
34 * @author Philipp Gampe <dev.typo3@philippgampe.info>
35 * @package TYPO3
36 * @subpackage t3lib
37 */
38 class t3lib_http_Request extends HTTP_Request2 {
39
40 /**
41 * Default constructor - sets TYPO3 defaults
42 *
43 * @param string|Net_Url2 $url Request URL
44 * @param string $method Request Method (GET, HEAD or POST). Redirects reset this to GET unless "strict_redirects" is set.
45 * @param array $config Configuration for this request instance
46 * @link http://pear.php.net/manual/en/package.http.http-request2.config.php
47 */
48 public function __construct($url = NULL, $method = self::METHOD_GET, array $config = array()) {
49
50 parent::__construct($url, $method);
51 $this->setConfiguration($config);
52 }
53
54 /**
55 * Sets the configuration
56 * Merges default values with provided $config and overrides all not provided values
57 * with there defaults from localconf.php or config_default.php.
58 *
59 * @param array $config Configuration options which override the default configuration
60 * @return void
61 * @link http://pear.php.net/manual/en/package.http.http-request2.config.php
62 */
63 public function setConfiguration(array $config = array()) {
64 // set a branded user-agent
65 $this->setHeader('user-agent', $GLOBALS['TYPO3_CONF_VARS']['HTTP']['userAgent']);
66
67 // set defaults from localconf.php or config_default.php
68 $default = array(
69 'adapter' => $GLOBALS['TYPO3_CONF_VARS']['HTTP']['adapter'],
70 'connect_timeout' => $GLOBALS['TYPO3_CONF_VARS']['HTTP']['connect_timeout'],
71 'timeout' => $GLOBALS['TYPO3_CONF_VARS']['HTTP']['timeout'],
72 'protocol_version' => $GLOBALS['TYPO3_CONF_VARS']['HTTP']['protocol_version'],
73
74 'follow_redirects' => (bool) $GLOBALS['TYPO3_CONF_VARS']['HTTP']['follow_redirects'],
75 'max_redirects' => $GLOBALS['TYPO3_CONF_VARS']['HTTP']['max_redirects'],
76 'strict_redirects' => (bool) $GLOBALS['TYPO3_CONF_VARS']['HTTP']['strict_redirects'],
77
78 'proxy_host' => $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_host'],
79 'proxy_port' => $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_port'],
80 'proxy_user' => $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_user'],
81 'proxy_password' => $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_password'],
82 'proxy_auth_scheme' => $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_auth_scheme'],
83
84 'ssl_verify_peer' => (bool) $GLOBALS['TYPO3_CONF_VARS']['HTTP']['ssl_verify_peer'],
85 'ssl_verify_host' => (bool) $GLOBALS['TYPO3_CONF_VARS']['HTTP']['ssl_verify_host'],
86 // we have to deal with Install Tool limitations and set this to NULL if it is empty
87 'ssl_cafile' => empty($GLOBALS['TYPO3_CONF_VARS']['HTTP']['ssl_cafile'])
88 ? NULL : $GLOBALS['TYPO3_CONF_VARS']['HTTP']['ssl_cafile'],
89 'ssl_capath' => empty($GLOBALS['TYPO3_CONF_VARS']['HTTP']['ssl_capath'])
90 ? NULL : $GLOBALS['TYPO3_CONF_VARS']['HTTP']['ssl_capath'],
91 'ssl_local_cert' => empty($GLOBALS['TYPO3_CONF_VARS']['HTTP']['ssl_local_cert'])
92 ? NULL : $GLOBALS['TYPO3_CONF_VARS']['HTTP']['ssl_local_cert'],
93 'ssl_passphrase' => empty($GLOBALS['TYPO3_CONF_VARS']['HTTP']['ssl_passphrase'])
94 ? NULL : $GLOBALS['TYPO3_CONF_VARS']['HTTP']['ssl_passphrase'],
95 );
96
97 $configuration = array_merge($default, $config);
98
99 $this->setConfig($configuration);
100
101 }
102
103 }
104 ?>