GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — develop (#1957)
by
unknown
39:18 queued 26:49
created
libs/phpmailer/language/phpmailer.lang-en.php 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -7,14 +7,14 @@
 block discarded – undo
7 7
 $PHPMAILER_LANG = array();
8 8
 
9 9
 $PHPMAILER_LANG["provide_address"] = 'You must provide at least one ' .
10
-                                     'recipient email address.';
10
+									 'recipient email address.';
11 11
 $PHPMAILER_LANG["mailer_not_supported"] = ' mailer is not supported.';
12 12
 $PHPMAILER_LANG["execute"] = 'Could not execute: ';
13 13
 $PHPMAILER_LANG["instantiate"] = 'Could not instantiate mail function.';
14 14
 $PHPMAILER_LANG["authenticate"] = 'SMTP Error: Could not authenticate.';
15 15
 $PHPMAILER_LANG["from_failed"] = 'The following From address failed: ';
16 16
 $PHPMAILER_LANG["recipients_failed"] = 'SMTP Error: The following ' .
17
-                                       'recipients failed: ';
17
+									   'recipients failed: ';
18 18
 $PHPMAILER_LANG["data_not_accepted"] = 'SMTP Error: Data not accepted.';
19 19
 $PHPMAILER_LANG["connect_host"] = 'SMTP Error: Could not connect to SMTP host.';
20 20
 $PHPMAILER_LANG["file_access"] = 'Could not access file: ';
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -6,14 +6,14 @@
 block discarded – undo
6 6
 
7 7
 $PHPMAILER_LANG = array();
8 8
 
9
-$PHPMAILER_LANG["provide_address"] = 'You must provide at least one ' .
9
+$PHPMAILER_LANG["provide_address"] = 'You must provide at least one '.
10 10
                                      'recipient email address.';
11 11
 $PHPMAILER_LANG["mailer_not_supported"] = ' mailer is not supported.';
12 12
 $PHPMAILER_LANG["execute"] = 'Could not execute: ';
13 13
 $PHPMAILER_LANG["instantiate"] = 'Could not instantiate mail function.';
14 14
 $PHPMAILER_LANG["authenticate"] = 'SMTP Error: Could not authenticate.';
15 15
 $PHPMAILER_LANG["from_failed"] = 'The following From address failed: ';
16
-$PHPMAILER_LANG["recipients_failed"] = 'SMTP Error: The following ' .
16
+$PHPMAILER_LANG["recipients_failed"] = 'SMTP Error: The following '.
17 17
                                        'recipients failed: ';
18 18
 $PHPMAILER_LANG["data_not_accepted"] = 'SMTP Error: Data not accepted.';
19 19
 $PHPMAILER_LANG["connect_host"] = 'SMTP Error: Could not connect to SMTP host.';
Please login to merge, or discard this patch.
libs/PEAR.1.9.5/HTTP/Request2/Exception.php 1 patch
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -36,58 +36,58 @@
 block discarded – undo
36 36
  */
37 37
 class HTTP_Request2_Exception extends PEAR_Exception
38 38
 {
39
-    /** An invalid argument was passed to a method */
40
-    const INVALID_ARGUMENT   = 1;
41
-    /** Some required value was not available */
42
-    const MISSING_VALUE      = 2;
43
-    /** Request cannot be processed due to errors in PHP configuration */
44
-    const MISCONFIGURATION   = 3;
45
-    /** Error reading the local file */
46
-    const READ_ERROR         = 4;
39
+	/** An invalid argument was passed to a method */
40
+	const INVALID_ARGUMENT   = 1;
41
+	/** Some required value was not available */
42
+	const MISSING_VALUE      = 2;
43
+	/** Request cannot be processed due to errors in PHP configuration */
44
+	const MISCONFIGURATION   = 3;
45
+	/** Error reading the local file */
46
+	const READ_ERROR         = 4;
47 47
 
48
-    /** Server returned a response that does not conform to HTTP protocol */
49
-    const MALFORMED_RESPONSE = 10;
50
-    /** Failure decoding Content-Encoding or Transfer-Encoding of response */
51
-    const DECODE_ERROR       = 20;
52
-    /** Operation timed out */
53
-    const TIMEOUT            = 30;
54
-    /** Number of redirects exceeded 'max_redirects' configuration parameter */
55
-    const TOO_MANY_REDIRECTS = 40;
56
-    /** Redirect to a protocol other than http(s):// */
57
-    const NON_HTTP_REDIRECT  = 50;
48
+	/** Server returned a response that does not conform to HTTP protocol */
49
+	const MALFORMED_RESPONSE = 10;
50
+	/** Failure decoding Content-Encoding or Transfer-Encoding of response */
51
+	const DECODE_ERROR       = 20;
52
+	/** Operation timed out */
53
+	const TIMEOUT            = 30;
54
+	/** Number of redirects exceeded 'max_redirects' configuration parameter */
55
+	const TOO_MANY_REDIRECTS = 40;
56
+	/** Redirect to a protocol other than http(s):// */
57
+	const NON_HTTP_REDIRECT  = 50;
58 58
 
59
-    /**
60
-     * Native error code
61
-     * @var int
62
-     */
63
-    private $_nativeCode;
59
+	/**
60
+	 * Native error code
61
+	 * @var int
62
+	 */
63
+	private $_nativeCode;
64 64
 
65
-    /**
66
-     * Constructor, can set package error code and native error code
67
-     *
68
-     * @param string $message    exception message
69
-     * @param int    $code       package error code, one of class constants
70
-     * @param int    $nativeCode error code from underlying PHP extension
71
-     */
72
-    public function __construct($message = null, $code = null, $nativeCode = null)
73
-    {
74
-        parent::__construct($message, $code);
75
-        $this->_nativeCode = $nativeCode;
76
-    }
65
+	/**
66
+	 * Constructor, can set package error code and native error code
67
+	 *
68
+	 * @param string $message    exception message
69
+	 * @param int    $code       package error code, one of class constants
70
+	 * @param int    $nativeCode error code from underlying PHP extension
71
+	 */
72
+	public function __construct($message = null, $code = null, $nativeCode = null)
73
+	{
74
+		parent::__construct($message, $code);
75
+		$this->_nativeCode = $nativeCode;
76
+	}
77 77
 
78
-    /**
79
-     * Returns error code produced by underlying PHP extension
80
-     *
81
-     * For Socket Adapter this may contain error number returned by
82
-     * stream_socket_client(), for Curl Adapter this will contain error number
83
-     * returned by curl_errno()
84
-     *
85
-     * @return integer
86
-     */
87
-    public function getNativeCode()
88
-    {
89
-        return $this->_nativeCode;
90
-    }
78
+	/**
79
+	 * Returns error code produced by underlying PHP extension
80
+	 *
81
+	 * For Socket Adapter this may contain error number returned by
82
+	 * stream_socket_client(), for Curl Adapter this will contain error number
83
+	 * returned by curl_errno()
84
+	 *
85
+	 * @return integer
86
+	 */
87
+	public function getNativeCode()
88
+	{
89
+		return $this->_nativeCode;
90
+	}
91 91
 }
92 92
 
93 93
 /**
Please login to merge, or discard this patch.
libs/PEAR/HTTP/Request/Listener.php 1 patch
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -60,17 +60,17 @@  discard block
 block discarded – undo
60 60
     * A listener's identifier
61 61
     * @var string
62 62
     */
63
-    var $_id;
63
+	var $_id;
64 64
 
65 65
    /**
66 66
     * Constructor, sets the object's identifier
67 67
     *
68 68
     * @access public
69 69
     */
70
-    function HTTP_Request_Listener()
71
-    {
72
-        $this->_id = md5(uniqid('http_request_', 1));
73
-    }
70
+	function HTTP_Request_Listener()
71
+	{
72
+		$this->_id = md5(uniqid('http_request_', 1));
73
+	}
74 74
 
75 75
 
76 76
    /**
@@ -79,10 +79,10 @@  discard block
 block discarded – undo
79 79
     * @access public
80 80
     * @return string
81 81
     */
82
-    function getId()
83
-    {
84
-        return $this->_id;
85
-    }
82
+	function getId()
83
+	{
84
+		return $this->_id;
85
+	}
86 86
 
87 87
 
88 88
    /**
@@ -94,13 +94,13 @@  discard block
 block discarded – undo
94 94
     * @param    mixed   Additional data
95 95
     * @abstract
96 96
     */
97
-    function update(&$subject, $event, $data = null)
98
-    {
99
-        echo "Notified of event: '$event'\n";
100
-        if (null !== $data) {
101
-            echo "Additional data: ";
102
-            var_dump($data);
103
-        }
104
-    }
97
+	function update(&$subject, $event, $data = null)
98
+	{
99
+		echo "Notified of event: '$event'\n";
100
+		if (null !== $data) {
101
+			echo "Additional data: ";
102
+			var_dump($data);
103
+		}
104
+	}
105 105
 }
106 106
 ?>
Please login to merge, or discard this patch.
libs/PEAR.1.9/HTTP/Request2/Adapter/Socket.php 2 patches
Indentation   +719 added lines, -719 removed lines patch added patch discarded remove patch
@@ -62,19 +62,19 @@  discard block
 block discarded – undo
62 62
    /**
63 63
     * Regular expression for 'token' rule from RFC 2616
64 64
     */
65
-    const REGEXP_TOKEN = '[^\x00-\x1f\x7f-\xff()<>@,;:\\\\"/\[\]?={}\s]+';
65
+	const REGEXP_TOKEN = '[^\x00-\x1f\x7f-\xff()<>@,;:\\\\"/\[\]?={}\s]+';
66 66
 
67 67
    /**
68 68
     * Regular expression for 'quoted-string' rule from RFC 2616
69 69
     */
70
-    const REGEXP_QUOTED_STRING = '"(?:\\\\.|[^\\\\"])*"';
70
+	const REGEXP_QUOTED_STRING = '"(?:\\\\.|[^\\\\"])*"';
71 71
 
72 72
    /**
73 73
     * Connected sockets, needed for Keep-Alive support
74 74
     * @var  array
75 75
     * @see  connect()
76 76
     */
77
-    protected static $sockets = array();
77
+	protected static $sockets = array();
78 78
 
79 79
    /**
80 80
     * Data for digest authentication scheme
@@ -88,39 +88,39 @@  discard block
 block discarded – undo
88 88
     *
89 89
     * @var  array
90 90
     */
91
-    protected static $challenges = array();
91
+	protected static $challenges = array();
92 92
 
93 93
    /**
94 94
     * Connected socket
95 95
     * @var  resource
96 96
     * @see  connect()
97 97
     */
98
-    protected $socket;
98
+	protected $socket;
99 99
 
100 100
    /**
101 101
     * Challenge used for server digest authentication
102 102
     * @var  array
103 103
     */
104
-    protected $serverChallenge;
104
+	protected $serverChallenge;
105 105
 
106 106
    /**
107 107
     * Challenge used for proxy digest authentication
108 108
     * @var  array
109 109
     */
110
-    protected $proxyChallenge;
110
+	protected $proxyChallenge;
111 111
 
112 112
    /**
113 113
     * Sum of start time and global timeout, exception will be thrown if request continues past this time
114 114
     * @var  integer
115 115
     */
116
-    protected $deadline = null;
116
+	protected $deadline = null;
117 117
 
118 118
    /**
119 119
     * Remaining length of the current chunk, when reading chunked response
120 120
     * @var  integer
121 121
     * @see  readChunked()
122 122
     */
123
-    protected $chunkLength = 0;
123
+	protected $chunkLength = 0;
124 124
 
125 125
    /**
126 126
     * Remaining amount of redirections to follow
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
     *
131 131
     * @var  integer
132 132
     */
133
-    protected $redirectCountdown = null;
133
+	protected $redirectCountdown = null;
134 134
 
135 135
    /**
136 136
     * Sends request to the remote server and returns its response
@@ -139,69 +139,69 @@  discard block
 block discarded – undo
139 139
     * @return   HTTP_Request2_Response
140 140
     * @throws   HTTP_Request2_Exception
141 141
     */
142
-    public function sendRequest(HTTP_Request2 $request)
143
-    {
144
-        $this->request = $request;
145
-
146
-        // Use global request timeout if given, see feature requests #5735, #8964
147
-        if ($timeout = $request->getConfig('timeout')) {
148
-            $this->deadline = time() + $timeout;
149
-        } else {
150
-            $this->deadline = null;
151
-        }
152
-
153
-        try {
154
-            $keepAlive = $this->connect();
155
-            $headers   = $this->prepareHeaders();
156
-            if (false === @fwrite($this->socket, $headers, strlen($headers))) {
157
-                throw new HTTP_Request2_Exception('Error writing request');
158
-            }
159
-            // provide request headers to the observer, see request #7633
160
-            $this->request->setLastEvent('sentHeaders', $headers);
161
-            $this->writeBody();
162
-
163
-            if ($this->deadline && time() > $this->deadline) {
164
-                throw new HTTP_Request2_Exception(
165
-                    'Request timed out after ' .
166
-                    $request->getConfig('timeout') . ' second(s)'
167
-                );
168
-            }
169
-
170
-            $response = $this->readResponse();
171
-
172
-            if (!$this->canKeepAlive($keepAlive, $response)) {
173
-                $this->disconnect();
174
-            }
175
-
176
-            if ($this->shouldUseProxyDigestAuth($response)) {
177
-                return $this->sendRequest($request);
178
-            }
179
-            if ($this->shouldUseServerDigestAuth($response)) {
180
-                return $this->sendRequest($request);
181
-            }
182
-            if ($authInfo = $response->getHeader('authentication-info')) {
183
-                $this->updateChallenge($this->serverChallenge, $authInfo);
184
-            }
185
-            if ($proxyInfo = $response->getHeader('proxy-authentication-info')) {
186
-                $this->updateChallenge($this->proxyChallenge, $proxyInfo);
187
-            }
188
-
189
-        } catch (Exception $e) {
190
-            $this->disconnect();
191
-        }
192
-
193
-        unset($this->request, $this->requestBody);
194
-
195
-        if (!empty($e)) {
196
-            throw $e;
197
-        }
198
-
199
-        if (!$request->getConfig('follow_redirects') || !$response->isRedirect()) {
200
-            return $response;
201
-        } else {
202
-            return $this->handleRedirect($request, $response);
203
-        }
204
-    }
142
+	public function sendRequest(HTTP_Request2 $request)
143
+	{
144
+		$this->request = $request;
145
+
146
+		// Use global request timeout if given, see feature requests #5735, #8964
147
+		if ($timeout = $request->getConfig('timeout')) {
148
+			$this->deadline = time() + $timeout;
149
+		} else {
150
+			$this->deadline = null;
151
+		}
152
+
153
+		try {
154
+			$keepAlive = $this->connect();
155
+			$headers   = $this->prepareHeaders();
156
+			if (false === @fwrite($this->socket, $headers, strlen($headers))) {
157
+				throw new HTTP_Request2_Exception('Error writing request');
158
+			}
159
+			// provide request headers to the observer, see request #7633
160
+			$this->request->setLastEvent('sentHeaders', $headers);
161
+			$this->writeBody();
162
+
163
+			if ($this->deadline && time() > $this->deadline) {
164
+				throw new HTTP_Request2_Exception(
165
+					'Request timed out after ' .
166
+					$request->getConfig('timeout') . ' second(s)'
167
+				);
168
+			}
169
+
170
+			$response = $this->readResponse();
171
+
172
+			if (!$this->canKeepAlive($keepAlive, $response)) {
173
+				$this->disconnect();
174
+			}
175
+
176
+			if ($this->shouldUseProxyDigestAuth($response)) {
177
+				return $this->sendRequest($request);
178
+			}
179
+			if ($this->shouldUseServerDigestAuth($response)) {
180
+				return $this->sendRequest($request);
181
+			}
182
+			if ($authInfo = $response->getHeader('authentication-info')) {
183
+				$this->updateChallenge($this->serverChallenge, $authInfo);
184
+			}
185
+			if ($proxyInfo = $response->getHeader('proxy-authentication-info')) {
186
+				$this->updateChallenge($this->proxyChallenge, $proxyInfo);
187
+			}
188
+
189
+		} catch (Exception $e) {
190
+			$this->disconnect();
191
+		}
192
+
193
+		unset($this->request, $this->requestBody);
194
+
195
+		if (!empty($e)) {
196
+			throw $e;
197
+		}
198
+
199
+		if (!$request->getConfig('follow_redirects') || !$response->isRedirect()) {
200
+			return $response;
201
+		} else {
202
+			return $this->handleRedirect($request, $response);
203
+		}
204
+	}
205 205
 
206 206
    /**
207 207
     * Connects to the remote server
@@ -209,114 +209,114 @@  discard block
 block discarded – undo
209 209
     * @return   bool    whether the connection can be persistent
210 210
     * @throws   HTTP_Request2_Exception
211 211
     */
212
-    protected function connect()
213
-    {
214
-        $secure  = 0 == strcasecmp($this->request->getUrl()->getScheme(), 'https');
215
-        $tunnel  = HTTP_Request2::METHOD_CONNECT == $this->request->getMethod();
216
-        $headers = $this->request->getHeaders();
217
-        $reqHost = $this->request->getUrl()->getHost();
218
-        if (!($reqPort = $this->request->getUrl()->getPort())) {
219
-            $reqPort = $secure? 443: 80;
220
-        }
221
-
222
-        if ($host = $this->request->getConfig('proxy_host')) {
223
-            if (!($port = $this->request->getConfig('proxy_port'))) {
224
-                throw new HTTP_Request2_Exception('Proxy port not provided');
225
-            }
226
-            $proxy = true;
227
-        } else {
228
-            $host  = $reqHost;
229
-            $port  = $reqPort;
230
-            $proxy = false;
231
-        }
232
-
233
-        if ($tunnel && !$proxy) {
234
-            throw new HTTP_Request2_Exception(
235
-                "Trying to perform CONNECT request without proxy"
236
-            );
237
-        }
238
-        if ($secure && !in_array('ssl', stream_get_transports())) {
239
-            throw new HTTP_Request2_Exception(
240
-                'Need OpenSSL support for https:// requests'
241
-            );
242
-        }
243
-
244
-        // RFC 2068, section 19.7.1: A client MUST NOT send the Keep-Alive
245
-        // connection token to a proxy server...
246
-        if ($proxy && !$secure &&
247
-            !empty($headers['connection']) && 'Keep-Alive' == $headers['connection']
248
-        ) {
249
-            $this->request->setHeader('connection');
250
-        }
251
-
252
-        $keepAlive = ('1.1' == $this->request->getConfig('protocol_version') &&
253
-                      empty($headers['connection'])) ||
254
-                     (!empty($headers['connection']) &&
255
-                      'Keep-Alive' == $headers['connection']);
256
-        $host = ((!$secure || $proxy)? 'tcp://': 'ssl://') . $host;
257
-
258
-        $options = array();
259
-        if ($secure || $tunnel) {
260
-            foreach ($this->request->getConfig() as $name => $value) {
261
-                if ('ssl_' == substr($name, 0, 4) && null !== $value) {
262
-                    if ('ssl_verify_host' == $name) {
263
-                        if ($value) {
264
-                            $options['CN_match'] = $reqHost;
265
-                        }
266
-                    } else {
267
-                        $options[substr($name, 4)] = $value;
268
-                    }
269
-                }
270
-            }
271
-            ksort($options);
272
-        }
273
-
274
-        // Changing SSL context options after connection is established does *not*
275
-        // work, we need a new connection if options change
276
-        $remote    = $host . ':' . $port;
277
-        $socketKey = $remote . (($secure && $proxy)? "->{$reqHost}:{$reqPort}": '') .
278
-                     (empty($options)? '': ':' . serialize($options));
279
-        unset($this->socket);
280
-
281
-        // We use persistent connections and have a connected socket?
282
-        // Ensure that the socket is still connected, see bug #16149
283
-        if ($keepAlive && !empty(self::$sockets[$socketKey]) &&
284
-            !feof(self::$sockets[$socketKey])
285
-        ) {
286
-            $this->socket =& self::$sockets[$socketKey];
287
-
288
-        } elseif ($secure && $proxy && !$tunnel) {
289
-            $this->establishTunnel();
290
-            $this->request->setLastEvent(
291
-                'connect', "ssl://{$reqHost}:{$reqPort} via {$host}:{$port}"
292
-            );
293
-            self::$sockets[$socketKey] =& $this->socket;
294
-
295
-        } else {
296
-            // Set SSL context options if doing HTTPS request or creating a tunnel
297
-            $context = stream_context_create();
298
-            foreach ($options as $name => $value) {
299
-                if (!stream_context_set_option($context, 'ssl', $name, $value)) {
300
-                    throw new HTTP_Request2_Exception(
301
-                        "Error setting SSL context option '{$name}'"
302
-                    );
303
-                }
304
-            }
305
-            $this->socket = @stream_socket_client(
306
-                $remote, $errno, $errstr,
307
-                $this->request->getConfig('connect_timeout'),
308
-                STREAM_CLIENT_CONNECT, $context
309
-            );
310
-            if (!$this->socket) {
311
-                throw new HTTP_Request2_Exception(
312
-                    "Unable to connect to {$remote}. Error #{$errno}: {$errstr}"
313
-                );
314
-            }
315
-            $this->request->setLastEvent('connect', $remote);
316
-            self::$sockets[$socketKey] =& $this->socket;
317
-        }
318
-        return $keepAlive;
319
-    }
212
+	protected function connect()
213
+	{
214
+		$secure  = 0 == strcasecmp($this->request->getUrl()->getScheme(), 'https');
215
+		$tunnel  = HTTP_Request2::METHOD_CONNECT == $this->request->getMethod();
216
+		$headers = $this->request->getHeaders();
217
+		$reqHost = $this->request->getUrl()->getHost();
218
+		if (!($reqPort = $this->request->getUrl()->getPort())) {
219
+			$reqPort = $secure? 443: 80;
220
+		}
221
+
222
+		if ($host = $this->request->getConfig('proxy_host')) {
223
+			if (!($port = $this->request->getConfig('proxy_port'))) {
224
+				throw new HTTP_Request2_Exception('Proxy port not provided');
225
+			}
226
+			$proxy = true;
227
+		} else {
228
+			$host  = $reqHost;
229
+			$port  = $reqPort;
230
+			$proxy = false;
231
+		}
232
+
233
+		if ($tunnel && !$proxy) {
234
+			throw new HTTP_Request2_Exception(
235
+				"Trying to perform CONNECT request without proxy"
236
+			);
237
+		}
238
+		if ($secure && !in_array('ssl', stream_get_transports())) {
239
+			throw new HTTP_Request2_Exception(
240
+				'Need OpenSSL support for https:// requests'
241
+			);
242
+		}
243
+
244
+		// RFC 2068, section 19.7.1: A client MUST NOT send the Keep-Alive
245
+		// connection token to a proxy server...
246
+		if ($proxy && !$secure &&
247
+			!empty($headers['connection']) && 'Keep-Alive' == $headers['connection']
248
+		) {
249
+			$this->request->setHeader('connection');
250
+		}
251
+
252
+		$keepAlive = ('1.1' == $this->request->getConfig('protocol_version') &&
253
+					  empty($headers['connection'])) ||
254
+					 (!empty($headers['connection']) &&
255
+					  'Keep-Alive' == $headers['connection']);
256
+		$host = ((!$secure || $proxy)? 'tcp://': 'ssl://') . $host;
257
+
258
+		$options = array();
259
+		if ($secure || $tunnel) {
260
+			foreach ($this->request->getConfig() as $name => $value) {
261
+				if ('ssl_' == substr($name, 0, 4) && null !== $value) {
262
+					if ('ssl_verify_host' == $name) {
263
+						if ($value) {
264
+							$options['CN_match'] = $reqHost;
265
+						}
266
+					} else {
267
+						$options[substr($name, 4)] = $value;
268
+					}
269
+				}
270
+			}
271
+			ksort($options);
272
+		}
273
+
274
+		// Changing SSL context options after connection is established does *not*
275
+		// work, we need a new connection if options change
276
+		$remote    = $host . ':' . $port;
277
+		$socketKey = $remote . (($secure && $proxy)? "->{$reqHost}:{$reqPort}": '') .
278
+					 (empty($options)? '': ':' . serialize($options));
279
+		unset($this->socket);
280
+
281
+		// We use persistent connections and have a connected socket?
282
+		// Ensure that the socket is still connected, see bug #16149
283
+		if ($keepAlive && !empty(self::$sockets[$socketKey]) &&
284
+			!feof(self::$sockets[$socketKey])
285
+		) {
286
+			$this->socket =& self::$sockets[$socketKey];
287
+
288
+		} elseif ($secure && $proxy && !$tunnel) {
289
+			$this->establishTunnel();
290
+			$this->request->setLastEvent(
291
+				'connect', "ssl://{$reqHost}:{$reqPort} via {$host}:{$port}"
292
+			);
293
+			self::$sockets[$socketKey] =& $this->socket;
294
+
295
+		} else {
296
+			// Set SSL context options if doing HTTPS request or creating a tunnel
297
+			$context = stream_context_create();
298
+			foreach ($options as $name => $value) {
299
+				if (!stream_context_set_option($context, 'ssl', $name, $value)) {
300
+					throw new HTTP_Request2_Exception(
301
+						"Error setting SSL context option '{$name}'"
302
+					);
303
+				}
304
+			}
305
+			$this->socket = @stream_socket_client(
306
+				$remote, $errno, $errstr,
307
+				$this->request->getConfig('connect_timeout'),
308
+				STREAM_CLIENT_CONNECT, $context
309
+			);
310
+			if (!$this->socket) {
311
+				throw new HTTP_Request2_Exception(
312
+					"Unable to connect to {$remote}. Error #{$errno}: {$errstr}"
313
+				);
314
+			}
315
+			$this->request->setLastEvent('connect', $remote);
316
+			self::$sockets[$socketKey] =& $this->socket;
317
+		}
318
+		return $keepAlive;
319
+	}
320 320
 
321 321
    /**
322 322
     * Establishes a tunnel to a secure remote server via HTTP CONNECT request
@@ -328,40 +328,40 @@  discard block
 block discarded – undo
328 328
     * @link     http://tools.ietf.org/html/rfc2817#section-5.2
329 329
     * @throws   HTTP_Request2_Exception
330 330
     */
331
-    protected function establishTunnel()
332
-    {
333
-        $donor   = new self;
334
-        $connect = new HTTP_Request2(
335
-            $this->request->getUrl(), HTTP_Request2::METHOD_CONNECT,
336
-            array_merge($this->request->getConfig(),
337
-                        array('adapter' => $donor))
338
-        );
339
-        $response = $connect->send();
340
-        // Need any successful (2XX) response
341
-        if (200 > $response->getStatus() || 300 <= $response->getStatus()) {
342
-            throw new HTTP_Request2_Exception(
343
-                'Failed to connect via HTTPS proxy. Proxy response: ' .
344
-                $response->getStatus() . ' ' . $response->getReasonPhrase()
345
-            );
346
-        }
347
-        $this->socket = $donor->socket;
348
-
349
-        $modes = array(
350
-            STREAM_CRYPTO_METHOD_TLS_CLIENT,
351
-            STREAM_CRYPTO_METHOD_SSLv3_CLIENT,
352
-            STREAM_CRYPTO_METHOD_SSLv23_CLIENT,
353
-            STREAM_CRYPTO_METHOD_SSLv2_CLIENT
354
-        );
355
-
356
-        foreach ($modes as $mode) {
357
-            if (stream_socket_enable_crypto($this->socket, true, $mode)) {
358
-                return;
359
-            }
360
-        }
361
-        throw new HTTP_Request2_Exception(
362
-            'Failed to enable secure connection when connecting through proxy'
363
-        );
364
-    }
331
+	protected function establishTunnel()
332
+	{
333
+		$donor   = new self;
334
+		$connect = new HTTP_Request2(
335
+			$this->request->getUrl(), HTTP_Request2::METHOD_CONNECT,
336
+			array_merge($this->request->getConfig(),
337
+						array('adapter' => $donor))
338
+		);
339
+		$response = $connect->send();
340
+		// Need any successful (2XX) response
341
+		if (200 > $response->getStatus() || 300 <= $response->getStatus()) {
342
+			throw new HTTP_Request2_Exception(
343
+				'Failed to connect via HTTPS proxy. Proxy response: ' .
344
+				$response->getStatus() . ' ' . $response->getReasonPhrase()
345
+			);
346
+		}
347
+		$this->socket = $donor->socket;
348
+
349
+		$modes = array(
350
+			STREAM_CRYPTO_METHOD_TLS_CLIENT,
351
+			STREAM_CRYPTO_METHOD_SSLv3_CLIENT,
352
+			STREAM_CRYPTO_METHOD_SSLv23_CLIENT,
353
+			STREAM_CRYPTO_METHOD_SSLv2_CLIENT
354
+		);
355
+
356
+		foreach ($modes as $mode) {
357
+			if (stream_socket_enable_crypto($this->socket, true, $mode)) {
358
+				return;
359
+			}
360
+		}
361
+		throw new HTTP_Request2_Exception(
362
+			'Failed to enable secure connection when connecting through proxy'
363
+		);
364
+	}
365 365
 
366 366
    /**
367 367
     * Checks whether current connection may be reused or should be closed
@@ -371,34 +371,34 @@  discard block
 block discarded – undo
371 371
     * @param    HTTP_Request2_Response  response object to check
372 372
     * @return   boolean
373 373
     */
374
-    protected function canKeepAlive($requestKeepAlive, HTTP_Request2_Response $response)
375
-    {
376
-        // Do not close socket on successful CONNECT request
377
-        if (HTTP_Request2::METHOD_CONNECT == $this->request->getMethod() &&
378
-            200 <= $response->getStatus() && 300 > $response->getStatus()
379
-        ) {
380
-            return true;
381
-        }
382
-
383
-        $lengthKnown = 'chunked' == strtolower($response->getHeader('transfer-encoding')) ||
384
-                       null !== $response->getHeader('content-length');
385
-        $persistent  = 'keep-alive' == strtolower($response->getHeader('connection')) ||
386
-                       (null === $response->getHeader('connection') &&
387
-                        '1.1' == $response->getVersion());
388
-        return $requestKeepAlive && $lengthKnown && $persistent;
389
-    }
374
+	protected function canKeepAlive($requestKeepAlive, HTTP_Request2_Response $response)
375
+	{
376
+		// Do not close socket on successful CONNECT request
377
+		if (HTTP_Request2::METHOD_CONNECT == $this->request->getMethod() &&
378
+			200 <= $response->getStatus() && 300 > $response->getStatus()
379
+		) {
380
+			return true;
381
+		}
382
+
383
+		$lengthKnown = 'chunked' == strtolower($response->getHeader('transfer-encoding')) ||
384
+					   null !== $response->getHeader('content-length');
385
+		$persistent  = 'keep-alive' == strtolower($response->getHeader('connection')) ||
386
+					   (null === $response->getHeader('connection') &&
387
+						'1.1' == $response->getVersion());
388
+		return $requestKeepAlive && $lengthKnown && $persistent;
389
+	}
390 390
 
391 391
    /**
392 392
     * Disconnects from the remote server
393 393
     */
394
-    protected function disconnect()
395
-    {
396
-        if (is_resource($this->socket)) {
397
-            fclose($this->socket);
398
-            $this->socket = null;
399
-            $this->request->setLastEvent('disconnect');
400
-        }
401
-    }
394
+	protected function disconnect()
395
+	{
396
+		if (is_resource($this->socket)) {
397
+			fclose($this->socket);
398
+			$this->socket = null;
399
+			$this->request->setLastEvent('disconnect');
400
+		}
401
+	}
402 402
 
403 403
    /**
404 404
     * Handles HTTP redirection
@@ -412,49 +412,49 @@  discard block
 block discarded – undo
412 412
     * @return   HTTP_Request2_Response      Response from a new location
413 413
     * @throws   HTTP_Request2_Exception
414 414
     */
415
-    protected function handleRedirect(HTTP_Request2 $request,
416
-                                      HTTP_Request2_Response $response)
417
-    {
418
-        if (is_null($this->redirectCountdown)) {
419
-            $this->redirectCountdown = $request->getConfig('max_redirects');
420
-        }
421
-        if (0 == $this->redirectCountdown) {
422
-            // Copying cURL behaviour
423
-            throw new HTTP_Request2_Exception(
424
-                'Maximum (' . $request->getConfig('max_redirects') . ') redirects followed'
425
-            );
426
-        }
427
-        $redirectUrl = new Net_URL2(
428
-            $response->getHeader('location'),
429
-            array(Net_URL2::OPTION_USE_BRACKETS => $request->getConfig('use_brackets'))
430
-        );
431
-        // refuse non-HTTP redirect
432
-        if ($redirectUrl->isAbsolute()
433
-            && !in_array($redirectUrl->getScheme(), array('http', 'https'))
434
-        ) {
435
-            throw new HTTP_Request2_Exception(
436
-                'Refusing to redirect to a non-HTTP URL ' . $redirectUrl->__toString()
437
-            );
438
-        }
439
-        // Theoretically URL should be absolute (see http://tools.ietf.org/html/rfc2616#section-14.30),
440
-        // but in practice it is often not
441
-        if (!$redirectUrl->isAbsolute()) {
442
-            $redirectUrl = $request->getUrl()->resolve($redirectUrl);
443
-        }
444
-        $redirect = clone $request;
445
-        $redirect->setUrl($redirectUrl);
446
-        if (303 == $response->getStatus() || (!$request->getConfig('strict_redirects')
447
-             && in_array($response->getStatus(), array(301, 302)))
448
-        ) {
449
-            $redirect->setMethod(HTTP_Request2::METHOD_GET);
450
-            $redirect->setBody('');
451
-        }
452
-
453
-        if (0 < $this->redirectCountdown) {
454
-            $this->redirectCountdown--;
455
-        }
456
-        return $this->sendRequest($redirect);
457
-    }
415
+	protected function handleRedirect(HTTP_Request2 $request,
416
+									  HTTP_Request2_Response $response)
417
+	{
418
+		if (is_null($this->redirectCountdown)) {
419
+			$this->redirectCountdown = $request->getConfig('max_redirects');
420
+		}
421
+		if (0 == $this->redirectCountdown) {
422
+			// Copying cURL behaviour
423
+			throw new HTTP_Request2_Exception(
424
+				'Maximum (' . $request->getConfig('max_redirects') . ') redirects followed'
425
+			);
426
+		}
427
+		$redirectUrl = new Net_URL2(
428
+			$response->getHeader('location'),
429
+			array(Net_URL2::OPTION_USE_BRACKETS => $request->getConfig('use_brackets'))
430
+		);
431
+		// refuse non-HTTP redirect
432
+		if ($redirectUrl->isAbsolute()
433
+			&& !in_array($redirectUrl->getScheme(), array('http', 'https'))
434
+		) {
435
+			throw new HTTP_Request2_Exception(
436
+				'Refusing to redirect to a non-HTTP URL ' . $redirectUrl->__toString()
437
+			);
438
+		}
439
+		// Theoretically URL should be absolute (see http://tools.ietf.org/html/rfc2616#section-14.30),
440
+		// but in practice it is often not
441
+		if (!$redirectUrl->isAbsolute()) {
442
+			$redirectUrl = $request->getUrl()->resolve($redirectUrl);
443
+		}
444
+		$redirect = clone $request;
445
+		$redirect->setUrl($redirectUrl);
446
+		if (303 == $response->getStatus() || (!$request->getConfig('strict_redirects')
447
+			 && in_array($response->getStatus(), array(301, 302)))
448
+		) {
449
+			$redirect->setMethod(HTTP_Request2::METHOD_GET);
450
+			$redirect->setBody('');
451
+		}
452
+
453
+		if (0 < $this->redirectCountdown) {
454
+			$this->redirectCountdown--;
455
+		}
456
+		return $this->sendRequest($redirect);
457
+	}
458 458
 
459 459
    /**
460 460
     * Checks whether another request should be performed with server digest auth
@@ -473,52 +473,52 @@  discard block
 block discarded – undo
473 473
     * @return   boolean whether another request should be performed
474 474
     * @throws   HTTP_Request2_Exception in case of unsupported challenge parameters
475 475
     */
476
-    protected function shouldUseServerDigestAuth(HTTP_Request2_Response $response)
477
-    {
478
-        // no sense repeating a request if we don't have credentials
479
-        if (401 != $response->getStatus() || !$this->request->getAuth()) {
480
-            return false;
481
-        }
482
-        if (!$challenge = $this->parseDigestChallenge($response->getHeader('www-authenticate'))) {
483
-            return false;
484
-        }
485
-
486
-        $url    = $this->request->getUrl();
487
-        $scheme = $url->getScheme();
488
-        $host   = $scheme . '://' . $url->getHost();
489
-        if ($port = $url->getPort()) {
490
-            if ((0 == strcasecmp($scheme, 'http') && 80 != $port) ||
491
-                (0 == strcasecmp($scheme, 'https') && 443 != $port)
492
-            ) {
493
-                $host .= ':' . $port;
494
-            }
495
-        }
496
-
497
-        if (!empty($challenge['domain'])) {
498
-            $prefixes = array();
499
-            foreach (preg_split('/\\s+/', $challenge['domain']) as $prefix) {
500
-                // don't bother with different servers
501
-                if ('/' == substr($prefix, 0, 1)) {
502
-                    $prefixes[] = $host . $prefix;
503
-                }
504
-            }
505
-        }
506
-        if (empty($prefixes)) {
507
-            $prefixes = array($host . '/');
508
-        }
509
-
510
-        $ret = true;
511
-        foreach ($prefixes as $prefix) {
512
-            if (!empty(self::$challenges[$prefix]) &&
513
-                (empty($challenge['stale']) || strcasecmp('true', $challenge['stale']))
514
-            ) {
515
-                // probably credentials are invalid
516
-                $ret = false;
517
-            }
518
-            self::$challenges[$prefix] =& $challenge;
519
-        }
520
-        return $ret;
521
-    }
476
+	protected function shouldUseServerDigestAuth(HTTP_Request2_Response $response)
477
+	{
478
+		// no sense repeating a request if we don't have credentials
479
+		if (401 != $response->getStatus() || !$this->request->getAuth()) {
480
+			return false;
481
+		}
482
+		if (!$challenge = $this->parseDigestChallenge($response->getHeader('www-authenticate'))) {
483
+			return false;
484
+		}
485
+
486
+		$url    = $this->request->getUrl();
487
+		$scheme = $url->getScheme();
488
+		$host   = $scheme . '://' . $url->getHost();
489
+		if ($port = $url->getPort()) {
490
+			if ((0 == strcasecmp($scheme, 'http') && 80 != $port) ||
491
+				(0 == strcasecmp($scheme, 'https') && 443 != $port)
492
+			) {
493
+				$host .= ':' . $port;
494
+			}
495
+		}
496
+
497
+		if (!empty($challenge['domain'])) {
498
+			$prefixes = array();
499
+			foreach (preg_split('/\\s+/', $challenge['domain']) as $prefix) {
500
+				// don't bother with different servers
501
+				if ('/' == substr($prefix, 0, 1)) {
502
+					$prefixes[] = $host . $prefix;
503
+				}
504
+			}
505
+		}
506
+		if (empty($prefixes)) {
507
+			$prefixes = array($host . '/');
508
+		}
509
+
510
+		$ret = true;
511
+		foreach ($prefixes as $prefix) {
512
+			if (!empty(self::$challenges[$prefix]) &&
513
+				(empty($challenge['stale']) || strcasecmp('true', $challenge['stale']))
514
+			) {
515
+				// probably credentials are invalid
516
+				$ret = false;
517
+			}
518
+			self::$challenges[$prefix] =& $challenge;
519
+		}
520
+		return $ret;
521
+	}
522 522
 
523 523
    /**
524 524
     * Checks whether another request should be performed with proxy digest auth
@@ -537,28 +537,28 @@  discard block
 block discarded – undo
537 537
     * @return   boolean whether another request should be performed
538 538
     * @throws   HTTP_Request2_Exception in case of unsupported challenge parameters
539 539
     */
540
-    protected function shouldUseProxyDigestAuth(HTTP_Request2_Response $response)
541
-    {
542
-        if (407 != $response->getStatus() || !$this->request->getConfig('proxy_user')) {
543
-            return false;
544
-        }
545
-        if (!($challenge = $this->parseDigestChallenge($response->getHeader('proxy-authenticate')))) {
546
-            return false;
547
-        }
548
-
549
-        $key = 'proxy://' . $this->request->getConfig('proxy_host') .
550
-               ':' . $this->request->getConfig('proxy_port');
551
-
552
-        if (!empty(self::$challenges[$key]) &&
553
-            (empty($challenge['stale']) || strcasecmp('true', $challenge['stale']))
554
-        ) {
555
-            $ret = false;
556
-        } else {
557
-            $ret = true;
558
-        }
559
-        self::$challenges[$key] = $challenge;
560
-        return $ret;
561
-    }
540
+	protected function shouldUseProxyDigestAuth(HTTP_Request2_Response $response)
541
+	{
542
+		if (407 != $response->getStatus() || !$this->request->getConfig('proxy_user')) {
543
+			return false;
544
+		}
545
+		if (!($challenge = $this->parseDigestChallenge($response->getHeader('proxy-authenticate')))) {
546
+			return false;
547
+		}
548
+
549
+		$key = 'proxy://' . $this->request->getConfig('proxy_host') .
550
+			   ':' . $this->request->getConfig('proxy_port');
551
+
552
+		if (!empty(self::$challenges[$key]) &&
553
+			(empty($challenge['stale']) || strcasecmp('true', $challenge['stale']))
554
+		) {
555
+			$ret = false;
556
+		} else {
557
+			$ret = true;
558
+		}
559
+		self::$challenges[$key] = $challenge;
560
+		return $ret;
561
+	}
562 562
 
563 563
    /**
564 564
     * Extracts digest method challenge from (WWW|Proxy)-Authenticate header value
@@ -588,48 +588,48 @@  discard block
 block discarded – undo
588 588
     *                   no challenge is present in header value
589 589
     * @throws   HTTP_Request2_Exception in case of unsupported challenge parameters
590 590
     */
591
-    protected function parseDigestChallenge($headerValue)
592
-    {
593
-        $authParam   = '(' . self::REGEXP_TOKEN . ')\\s*=\\s*(' .
594
-                       self::REGEXP_TOKEN . '|' . self::REGEXP_QUOTED_STRING . ')';
595
-        $challenge   = "!(?<=^|\\s|,)Digest ({$authParam}\\s*(,\\s*|$))+!";
596
-        if (!preg_match($challenge, $headerValue, $matches)) {
597
-            return false;
598
-        }
599
-
600
-        preg_match_all('!' . $authParam . '!', $matches[0], $params);
601
-        $paramsAry   = array();
602
-        $knownParams = array('realm', 'domain', 'nonce', 'opaque', 'stale',
603
-                             'algorithm', 'qop');
604
-        for ($i = 0; $i < count($params[0]); $i++) {
605
-            // section 3.2.1: Any unrecognized directive MUST be ignored.
606
-            if (in_array($params[1][$i], $knownParams)) {
607
-                if ('"' == substr($params[2][$i], 0, 1)) {
608
-                    $paramsAry[$params[1][$i]] = substr($params[2][$i], 1, -1);
609
-                } else {
610
-                    $paramsAry[$params[1][$i]] = $params[2][$i];
611
-                }
612
-            }
613
-        }
614
-        // we only support qop=auth
615
-        if (!empty($paramsAry['qop']) &&
616
-            !in_array('auth', array_map('trim', explode(',', $paramsAry['qop'])))
617
-        ) {
618
-            throw new HTTP_Request2_Exception(
619
-                "Only 'auth' qop is currently supported in digest authentication, " .
620
-                "server requested '{$paramsAry['qop']}'"
621
-            );
622
-        }
623
-        // we only support algorithm=MD5
624
-        if (!empty($paramsAry['algorithm']) && 'MD5' != $paramsAry['algorithm']) {
625
-            throw new HTTP_Request2_Exception(
626
-                "Only 'MD5' algorithm is currently supported in digest authentication, " .
627
-                "server requested '{$paramsAry['algorithm']}'"
628
-            );
629
-        }
630
-
631
-        return $paramsAry;
632
-    }
591
+	protected function parseDigestChallenge($headerValue)
592
+	{
593
+		$authParam   = '(' . self::REGEXP_TOKEN . ')\\s*=\\s*(' .
594
+					   self::REGEXP_TOKEN . '|' . self::REGEXP_QUOTED_STRING . ')';
595
+		$challenge   = "!(?<=^|\\s|,)Digest ({$authParam}\\s*(,\\s*|$))+!";
596
+		if (!preg_match($challenge, $headerValue, $matches)) {
597
+			return false;
598
+		}
599
+
600
+		preg_match_all('!' . $authParam . '!', $matches[0], $params);
601
+		$paramsAry   = array();
602
+		$knownParams = array('realm', 'domain', 'nonce', 'opaque', 'stale',
603
+							 'algorithm', 'qop');
604
+		for ($i = 0; $i < count($params[0]); $i++) {
605
+			// section 3.2.1: Any unrecognized directive MUST be ignored.
606
+			if (in_array($params[1][$i], $knownParams)) {
607
+				if ('"' == substr($params[2][$i], 0, 1)) {
608
+					$paramsAry[$params[1][$i]] = substr($params[2][$i], 1, -1);
609
+				} else {
610
+					$paramsAry[$params[1][$i]] = $params[2][$i];
611
+				}
612
+			}
613
+		}
614
+		// we only support qop=auth
615
+		if (!empty($paramsAry['qop']) &&
616
+			!in_array('auth', array_map('trim', explode(',', $paramsAry['qop'])))
617
+		) {
618
+			throw new HTTP_Request2_Exception(
619
+				"Only 'auth' qop is currently supported in digest authentication, " .
620
+				"server requested '{$paramsAry['qop']}'"
621
+			);
622
+		}
623
+		// we only support algorithm=MD5
624
+		if (!empty($paramsAry['algorithm']) && 'MD5' != $paramsAry['algorithm']) {
625
+			throw new HTTP_Request2_Exception(
626
+				"Only 'MD5' algorithm is currently supported in digest authentication, " .
627
+				"server requested '{$paramsAry['algorithm']}'"
628
+			);
629
+		}
630
+
631
+		return $paramsAry;
632
+	}
633 633
 
634 634
    /**
635 635
     * Parses [Proxy-]Authentication-Info header value and updates challenge
@@ -638,26 +638,26 @@  discard block
 block discarded – undo
638 638
     * @param    string  value of [Proxy-]Authentication-Info header
639 639
     * @todo     validate server rspauth response
640 640
     */
641
-    protected function updateChallenge(&$challenge, $headerValue)
642
-    {
643
-        $authParam   = '!(' . self::REGEXP_TOKEN . ')\\s*=\\s*(' .
644
-                       self::REGEXP_TOKEN . '|' . self::REGEXP_QUOTED_STRING . ')!';
645
-        $paramsAry   = array();
646
-
647
-        preg_match_all($authParam, $headerValue, $params);
648
-        for ($i = 0; $i < count($params[0]); $i++) {
649
-            if ('"' == substr($params[2][$i], 0, 1)) {
650
-                $paramsAry[$params[1][$i]] = substr($params[2][$i], 1, -1);
651
-            } else {
652
-                $paramsAry[$params[1][$i]] = $params[2][$i];
653
-            }
654
-        }
655
-        // for now, just update the nonce value
656
-        if (!empty($paramsAry['nextnonce'])) {
657
-            $challenge['nonce'] = $paramsAry['nextnonce'];
658
-            $challenge['nc']    = 1;
659
-        }
660
-    }
641
+	protected function updateChallenge(&$challenge, $headerValue)
642
+	{
643
+		$authParam   = '!(' . self::REGEXP_TOKEN . ')\\s*=\\s*(' .
644
+					   self::REGEXP_TOKEN . '|' . self::REGEXP_QUOTED_STRING . ')!';
645
+		$paramsAry   = array();
646
+
647
+		preg_match_all($authParam, $headerValue, $params);
648
+		for ($i = 0; $i < count($params[0]); $i++) {
649
+			if ('"' == substr($params[2][$i], 0, 1)) {
650
+				$paramsAry[$params[1][$i]] = substr($params[2][$i], 1, -1);
651
+			} else {
652
+				$paramsAry[$params[1][$i]] = $params[2][$i];
653
+			}
654
+		}
655
+		// for now, just update the nonce value
656
+		if (!empty($paramsAry['nextnonce'])) {
657
+			$challenge['nonce'] = $paramsAry['nextnonce'];
658
+			$challenge['nc']    = 1;
659
+		}
660
+	}
661 661
 
662 662
    /**
663 663
     * Creates a value for [Proxy-]Authorization header when using digest authentication
@@ -669,40 +669,40 @@  discard block
 block discarded – undo
669 669
     * @return   string  value of [Proxy-]Authorization request header
670 670
     * @link     http://tools.ietf.org/html/rfc2617#section-3.2.2
671 671
     */
672
-    protected function createDigestResponse($user, $password, $url, &$challenge)
673
-    {
674
-        if (false !== ($q = strpos($url, '?')) &&
675
-            $this->request->getConfig('digest_compat_ie')
676
-        ) {
677
-            $url = substr($url, 0, $q);
678
-        }
679
-
680
-        $a1 = md5($user . ':' . $challenge['realm'] . ':' . $password);
681
-        $a2 = md5($this->request->getMethod() . ':' . $url);
682
-
683
-        if (empty($challenge['qop'])) {
684
-            $digest = md5($a1 . ':' . $challenge['nonce'] . ':' . $a2);
685
-        } else {
686
-            $challenge['cnonce'] = 'Req2.' . rand();
687
-            if (empty($challenge['nc'])) {
688
-                $challenge['nc'] = 1;
689
-            }
690
-            $nc     = sprintf('%08x', $challenge['nc']++);
691
-            $digest = md5($a1 . ':' . $challenge['nonce'] . ':' . $nc . ':' .
692
-                          $challenge['cnonce'] . ':auth:' . $a2);
693
-        }
694
-        return 'Digest username="' . str_replace(array('\\', '"'), array('\\\\', '\\"'), $user) . '", ' .
695
-               'realm="' . $challenge['realm'] . '", ' .
696
-               'nonce="' . $challenge['nonce'] . '", ' .
697
-               'uri="' . $url . '", ' .
698
-               'response="' . $digest . '"' .
699
-               (!empty($challenge['opaque'])?
700
-                ', opaque="' . $challenge['opaque'] . '"':
701
-                '') .
702
-               (!empty($challenge['qop'])?
703
-                ', qop="auth", nc=' . $nc . ', cnonce="' . $challenge['cnonce'] . '"':
704
-                '');
705
-    }
672
+	protected function createDigestResponse($user, $password, $url, &$challenge)
673
+	{
674
+		if (false !== ($q = strpos($url, '?')) &&
675
+			$this->request->getConfig('digest_compat_ie')
676
+		) {
677
+			$url = substr($url, 0, $q);
678
+		}
679
+
680
+		$a1 = md5($user . ':' . $challenge['realm'] . ':' . $password);
681
+		$a2 = md5($this->request->getMethod() . ':' . $url);
682
+
683
+		if (empty($challenge['qop'])) {
684
+			$digest = md5($a1 . ':' . $challenge['nonce'] . ':' . $a2);
685
+		} else {
686
+			$challenge['cnonce'] = 'Req2.' . rand();
687
+			if (empty($challenge['nc'])) {
688
+				$challenge['nc'] = 1;
689
+			}
690
+			$nc     = sprintf('%08x', $challenge['nc']++);
691
+			$digest = md5($a1 . ':' . $challenge['nonce'] . ':' . $nc . ':' .
692
+						  $challenge['cnonce'] . ':auth:' . $a2);
693
+		}
694
+		return 'Digest username="' . str_replace(array('\\', '"'), array('\\\\', '\\"'), $user) . '", ' .
695
+			   'realm="' . $challenge['realm'] . '", ' .
696
+			   'nonce="' . $challenge['nonce'] . '", ' .
697
+			   'uri="' . $url . '", ' .
698
+			   'response="' . $digest . '"' .
699
+			   (!empty($challenge['opaque'])?
700
+				', opaque="' . $challenge['opaque'] . '"':
701
+				'') .
702
+			   (!empty($challenge['qop'])?
703
+				', qop="auth", nc=' . $nc . ', cnonce="' . $challenge['cnonce'] . '"':
704
+				'');
705
+	}
706 706
 
707 707
    /**
708 708
     * Adds 'Authorization' header (if needed) to request headers array
@@ -712,41 +712,41 @@  discard block
 block discarded – undo
712 712
     * @param    string  request URL (needed for digest authentication)
713 713
     * @throws   HTTP_Request2_Exception
714 714
     */
715
-    protected function addAuthorizationHeader(&$headers, $requestHost, $requestUrl)
716
-    {
717
-        if (!($auth = $this->request->getAuth())) {
718
-            return;
719
-        }
720
-        switch ($auth['scheme']) {
721
-            case HTTP_Request2::AUTH_BASIC:
722
-                $headers['authorization'] =
723
-                    'Basic ' . base64_encode($auth['user'] . ':' . $auth['password']);
724
-                break;
725
-
726
-            case HTTP_Request2::AUTH_DIGEST:
727
-                unset($this->serverChallenge);
728
-                $fullUrl = ('/' == $requestUrl[0])?
729
-                           $this->request->getUrl()->getScheme() . '://' .
730
-                            $requestHost . $requestUrl:
731
-                           $requestUrl;
732
-                foreach (array_keys(self::$challenges) as $key) {
733
-                    if ($key == substr($fullUrl, 0, strlen($key))) {
734
-                        $headers['authorization'] = $this->createDigestResponse(
735
-                            $auth['user'], $auth['password'],
736
-                            $requestUrl, self::$challenges[$key]
737
-                        );
738
-                        $this->serverChallenge =& self::$challenges[$key];
739
-                        break;
740
-                    }
741
-                }
742
-                break;
743
-
744
-            default:
745
-                throw new HTTP_Request2_Exception(
746
-                    "Unknown HTTP authentication scheme '{$auth['scheme']}'"
747
-                );
748
-        }
749
-    }
715
+	protected function addAuthorizationHeader(&$headers, $requestHost, $requestUrl)
716
+	{
717
+		if (!($auth = $this->request->getAuth())) {
718
+			return;
719
+		}
720
+		switch ($auth['scheme']) {
721
+			case HTTP_Request2::AUTH_BASIC:
722
+				$headers['authorization'] =
723
+					'Basic ' . base64_encode($auth['user'] . ':' . $auth['password']);
724
+				break;
725
+
726
+			case HTTP_Request2::AUTH_DIGEST:
727
+				unset($this->serverChallenge);
728
+				$fullUrl = ('/' == $requestUrl[0])?
729
+						   $this->request->getUrl()->getScheme() . '://' .
730
+							$requestHost . $requestUrl:
731
+						   $requestUrl;
732
+				foreach (array_keys(self::$challenges) as $key) {
733
+					if ($key == substr($fullUrl, 0, strlen($key))) {
734
+						$headers['authorization'] = $this->createDigestResponse(
735
+							$auth['user'], $auth['password'],
736
+							$requestUrl, self::$challenges[$key]
737
+						);
738
+						$this->serverChallenge =& self::$challenges[$key];
739
+						break;
740
+					}
741
+				}
742
+				break;
743
+
744
+			default:
745
+				throw new HTTP_Request2_Exception(
746
+					"Unknown HTTP authentication scheme '{$auth['scheme']}'"
747
+				);
748
+		}
749
+	}
750 750
 
751 751
    /**
752 752
     * Adds 'Proxy-Authorization' header (if needed) to request headers array
@@ -755,43 +755,43 @@  discard block
 block discarded – undo
755 755
     * @param    string  request URL (needed for digest authentication)
756 756
     * @throws   HTTP_Request2_Exception
757 757
     */
758
-    protected function addProxyAuthorizationHeader(&$headers, $requestUrl)
759
-    {
760
-        if (!$this->request->getConfig('proxy_host') ||
761
-            !($user = $this->request->getConfig('proxy_user')) ||
762
-            (0 == strcasecmp('https', $this->request->getUrl()->getScheme()) &&
763
-             HTTP_Request2::METHOD_CONNECT != $this->request->getMethod())
764
-        ) {
765
-            return;
766
-        }
767
-
768
-        $password = $this->request->getConfig('proxy_password');
769
-        switch ($this->request->getConfig('proxy_auth_scheme')) {
770
-            case HTTP_Request2::AUTH_BASIC:
771
-                $headers['proxy-authorization'] =
772
-                    'Basic ' . base64_encode($user . ':' . $password);
773
-                break;
774
-
775
-            case HTTP_Request2::AUTH_DIGEST:
776
-                unset($this->proxyChallenge);
777
-                $proxyUrl = 'proxy://' . $this->request->getConfig('proxy_host') .
778
-                            ':' . $this->request->getConfig('proxy_port');
779
-                if (!empty(self::$challenges[$proxyUrl])) {
780
-                    $headers['proxy-authorization'] = $this->createDigestResponse(
781
-                        $user, $password,
782
-                        $requestUrl, self::$challenges[$proxyUrl]
783
-                    );
784
-                    $this->proxyChallenge =& self::$challenges[$proxyUrl];
785
-                }
786
-                break;
787
-
788
-            default:
789
-                throw new HTTP_Request2_Exception(
790
-                    "Unknown HTTP authentication scheme '" .
791
-                    $this->request->getConfig('proxy_auth_scheme') . "'"
792
-                );
793
-        }
794
-    }
758
+	protected function addProxyAuthorizationHeader(&$headers, $requestUrl)
759
+	{
760
+		if (!$this->request->getConfig('proxy_host') ||
761
+			!($user = $this->request->getConfig('proxy_user')) ||
762
+			(0 == strcasecmp('https', $this->request->getUrl()->getScheme()) &&
763
+			 HTTP_Request2::METHOD_CONNECT != $this->request->getMethod())
764
+		) {
765
+			return;
766
+		}
767
+
768
+		$password = $this->request->getConfig('proxy_password');
769
+		switch ($this->request->getConfig('proxy_auth_scheme')) {
770
+			case HTTP_Request2::AUTH_BASIC:
771
+				$headers['proxy-authorization'] =
772
+					'Basic ' . base64_encode($user . ':' . $password);
773
+				break;
774
+
775
+			case HTTP_Request2::AUTH_DIGEST:
776
+				unset($this->proxyChallenge);
777
+				$proxyUrl = 'proxy://' . $this->request->getConfig('proxy_host') .
778
+							':' . $this->request->getConfig('proxy_port');
779
+				if (!empty(self::$challenges[$proxyUrl])) {
780
+					$headers['proxy-authorization'] = $this->createDigestResponse(
781
+						$user, $password,
782
+						$requestUrl, self::$challenges[$proxyUrl]
783
+					);
784
+					$this->proxyChallenge =& self::$challenges[$proxyUrl];
785
+				}
786
+				break;
787
+
788
+			default:
789
+				throw new HTTP_Request2_Exception(
790
+					"Unknown HTTP authentication scheme '" .
791
+					$this->request->getConfig('proxy_auth_scheme') . "'"
792
+				);
793
+		}
794
+	}
795 795
 
796 796
 
797 797
    /**
@@ -800,88 +800,88 @@  discard block
 block discarded – undo
800 800
     * @return   string
801 801
     * @throws   HTTP_Request2_Exception
802 802
     */
803
-    protected function prepareHeaders()
804
-    {
805
-        $headers = $this->request->getHeaders();
806
-        $url     = $this->request->getUrl();
807
-        $connect = HTTP_Request2::METHOD_CONNECT == $this->request->getMethod();
808
-        $host    = $url->getHost();
809
-
810
-        $defaultPort = 0 == strcasecmp($url->getScheme(), 'https')? 443: 80;
811
-        if (($port = $url->getPort()) && $port != $defaultPort || $connect) {
812
-            $host .= ':' . (empty($port)? $defaultPort: $port);
813
-        }
814
-        // Do not overwrite explicitly set 'Host' header, see bug #16146
815
-        if (!isset($headers['host'])) {
816
-            $headers['host'] = $host;
817
-        }
818
-
819
-        if ($connect) {
820
-            $requestUrl = $host;
821
-
822
-        } else {
823
-            if (!$this->request->getConfig('proxy_host') ||
824
-                0 == strcasecmp($url->getScheme(), 'https')
825
-            ) {
826
-                $requestUrl = '';
827
-            } else {
828
-                $requestUrl = $url->getScheme() . '://' . $host;
829
-            }
830
-            $path        = $url->getPath();
831
-            $query       = $url->getQuery();
832
-            $requestUrl .= (empty($path)? '/': $path) . (empty($query)? '': '?' . $query);
833
-        }
834
-
835
-        if ('1.1' == $this->request->getConfig('protocol_version') &&
836
-            extension_loaded('zlib') && !isset($headers['accept-encoding'])
837
-        ) {
838
-            $headers['accept-encoding'] = 'gzip, deflate';
839
-        }
840
-
841
-        $this->addAuthorizationHeader($headers, $host, $requestUrl);
842
-        $this->addProxyAuthorizationHeader($headers, $requestUrl);
843
-        $this->calculateRequestLength($headers);
844
-
845
-        $headersStr = $this->request->getMethod() . ' ' . $requestUrl . ' HTTP/' .
846
-                      $this->request->getConfig('protocol_version') . "\r\n";
847
-        foreach ($headers as $name => $value) {
848
-            $canonicalName = implode('-', array_map('ucfirst', explode('-', $name)));
849
-            $headersStr   .= $canonicalName . ': ' . $value . "\r\n";
850
-        }
851
-        return $headersStr . "\r\n";
852
-    }
803
+	protected function prepareHeaders()
804
+	{
805
+		$headers = $this->request->getHeaders();
806
+		$url     = $this->request->getUrl();
807
+		$connect = HTTP_Request2::METHOD_CONNECT == $this->request->getMethod();
808
+		$host    = $url->getHost();
809
+
810
+		$defaultPort = 0 == strcasecmp($url->getScheme(), 'https')? 443: 80;
811
+		if (($port = $url->getPort()) && $port != $defaultPort || $connect) {
812
+			$host .= ':' . (empty($port)? $defaultPort: $port);
813
+		}
814
+		// Do not overwrite explicitly set 'Host' header, see bug #16146
815
+		if (!isset($headers['host'])) {
816
+			$headers['host'] = $host;
817
+		}
818
+
819
+		if ($connect) {
820
+			$requestUrl = $host;
821
+
822
+		} else {
823
+			if (!$this->request->getConfig('proxy_host') ||
824
+				0 == strcasecmp($url->getScheme(), 'https')
825
+			) {
826
+				$requestUrl = '';
827
+			} else {
828
+				$requestUrl = $url->getScheme() . '://' . $host;
829
+			}
830
+			$path        = $url->getPath();
831
+			$query       = $url->getQuery();
832
+			$requestUrl .= (empty($path)? '/': $path) . (empty($query)? '': '?' . $query);
833
+		}
834
+
835
+		if ('1.1' == $this->request->getConfig('protocol_version') &&
836
+			extension_loaded('zlib') && !isset($headers['accept-encoding'])
837
+		) {
838
+			$headers['accept-encoding'] = 'gzip, deflate';
839
+		}
840
+
841
+		$this->addAuthorizationHeader($headers, $host, $requestUrl);
842
+		$this->addProxyAuthorizationHeader($headers, $requestUrl);
843
+		$this->calculateRequestLength($headers);
844
+
845
+		$headersStr = $this->request->getMethod() . ' ' . $requestUrl . ' HTTP/' .
846
+					  $this->request->getConfig('protocol_version') . "\r\n";
847
+		foreach ($headers as $name => $value) {
848
+			$canonicalName = implode('-', array_map('ucfirst', explode('-', $name)));
849
+			$headersStr   .= $canonicalName . ': ' . $value . "\r\n";
850
+		}
851
+		return $headersStr . "\r\n";
852
+	}
853 853
 
854 854
    /**
855 855
     * Sends the request body
856 856
     *
857 857
     * @throws   HTTP_Request2_Exception
858 858
     */
859
-    protected function writeBody()
860
-    {
861
-        if (in_array($this->request->getMethod(), self::$bodyDisallowed) ||
862
-            0 == $this->contentLength
863
-        ) {
864
-            return;
865
-        }
866
-
867
-        $position   = 0;
868
-        $bufferSize = $this->request->getConfig('buffer_size');
869
-        while ($position < $this->contentLength) {
870
-            if (is_string($this->requestBody)) {
871
-                $str = substr($this->requestBody, $position, $bufferSize);
872
-            } elseif (is_resource($this->requestBody)) {
873
-                $str = fread($this->requestBody, $bufferSize);
874
-            } else {
875
-                $str = $this->requestBody->read($bufferSize);
876
-            }
877
-            if (false === @fwrite($this->socket, $str, strlen($str))) {
878
-                throw new HTTP_Request2_Exception('Error writing request');
879
-            }
880
-            // Provide the length of written string to the observer, request #7630
881
-            $this->request->setLastEvent('sentBodyPart', strlen($str));
882
-            $position += strlen($str);
883
-        }
884
-    }
859
+	protected function writeBody()
860
+	{
861
+		if (in_array($this->request->getMethod(), self::$bodyDisallowed) ||
862
+			0 == $this->contentLength
863
+		) {
864
+			return;
865
+		}
866
+
867
+		$position   = 0;
868
+		$bufferSize = $this->request->getConfig('buffer_size');
869
+		while ($position < $this->contentLength) {
870
+			if (is_string($this->requestBody)) {
871
+				$str = substr($this->requestBody, $position, $bufferSize);
872
+			} elseif (is_resource($this->requestBody)) {
873
+				$str = fread($this->requestBody, $bufferSize);
874
+			} else {
875
+				$str = $this->requestBody->read($bufferSize);
876
+			}
877
+			if (false === @fwrite($this->socket, $str, strlen($str))) {
878
+				throw new HTTP_Request2_Exception('Error writing request');
879
+			}
880
+			// Provide the length of written string to the observer, request #7630
881
+			$this->request->setLastEvent('sentBodyPart', strlen($str));
882
+			$position += strlen($str);
883
+		}
884
+	}
885 885
 
886 886
    /**
887 887
     * Reads the remote server's response
@@ -889,70 +889,70 @@  discard block
 block discarded – undo
889 889
     * @return   HTTP_Request2_Response
890 890
     * @throws   HTTP_Request2_Exception
891 891
     */
892
-    protected function readResponse()
893
-    {
894
-        $bufferSize = $this->request->getConfig('buffer_size');
895
-
896
-        do {
897
-            $response = new HTTP_Request2_Response($this->readLine($bufferSize), true);
898
-            do {
899
-                $headerLine = $this->readLine($bufferSize);
900
-                $response->parseHeaderLine($headerLine);
901
-            } while ('' != $headerLine);
902
-        } while (in_array($response->getStatus(), array(100, 101)));
903
-
904
-        $this->request->setLastEvent('receivedHeaders', $response);
905
-
906
-        // No body possible in such responses
907
-        if (HTTP_Request2::METHOD_HEAD == $this->request->getMethod() ||
908
-            (HTTP_Request2::METHOD_CONNECT == $this->request->getMethod() &&
909
-             200 <= $response->getStatus() && 300 > $response->getStatus()) ||
910
-            in_array($response->getStatus(), array(204, 304))
911
-        ) {
912
-            return $response;
913
-        }
914
-
915
-        $chunked = 'chunked' == $response->getHeader('transfer-encoding');
916
-        $length  = $response->getHeader('content-length');
917
-        $hasBody = false;
918
-        if ($chunked || null === $length || 0 < intval($length)) {
919
-            // RFC 2616, section 4.4:
920
-            // 3. ... If a message is received with both a
921
-            // Transfer-Encoding header field and a Content-Length header field,
922
-            // the latter MUST be ignored.
923
-            $toRead = ($chunked || null === $length)? null: $length;
924
-            $this->chunkLength = 0;
925
-
926
-            while (!feof($this->socket) && (is_null($toRead) || 0 < $toRead)) {
927
-                if ($chunked) {
928
-                    $data = $this->readChunked($bufferSize);
929
-                } elseif (is_null($toRead)) {
930
-                    $data = $this->fread($bufferSize);
931
-                } else {
932
-                    $data    = $this->fread(min($toRead, $bufferSize));
933
-                    $toRead -= strlen($data);
934
-                }
935
-                if ('' == $data && (!$this->chunkLength || feof($this->socket))) {
936
-                    break;
937
-                }
938
-
939
-                $hasBody = true;
940
-                if ($this->request->getConfig('store_body')) {
941
-                    $response->appendBody($data);
942
-                }
943
-                if (!in_array($response->getHeader('content-encoding'), array('identity', null))) {
944
-                    $this->request->setLastEvent('receivedEncodedBodyPart', $data);
945
-                } else {
946
-                    $this->request->setLastEvent('receivedBodyPart', $data);
947
-                }
948
-            }
949
-        }
950
-
951
-        if ($hasBody) {
952
-            $this->request->setLastEvent('receivedBody', $response);
953
-        }
954
-        return $response;
955
-    }
892
+	protected function readResponse()
893
+	{
894
+		$bufferSize = $this->request->getConfig('buffer_size');
895
+
896
+		do {
897
+			$response = new HTTP_Request2_Response($this->readLine($bufferSize), true);
898
+			do {
899
+				$headerLine = $this->readLine($bufferSize);
900
+				$response->parseHeaderLine($headerLine);
901
+			} while ('' != $headerLine);
902
+		} while (in_array($response->getStatus(), array(100, 101)));
903
+
904
+		$this->request->setLastEvent('receivedHeaders', $response);
905
+
906
+		// No body possible in such responses
907
+		if (HTTP_Request2::METHOD_HEAD == $this->request->getMethod() ||
908
+			(HTTP_Request2::METHOD_CONNECT == $this->request->getMethod() &&
909
+			 200 <= $response->getStatus() && 300 > $response->getStatus()) ||
910
+			in_array($response->getStatus(), array(204, 304))
911
+		) {
912
+			return $response;
913
+		}
914
+
915
+		$chunked = 'chunked' == $response->getHeader('transfer-encoding');
916
+		$length  = $response->getHeader('content-length');
917
+		$hasBody = false;
918
+		if ($chunked || null === $length || 0 < intval($length)) {
919
+			// RFC 2616, section 4.4:
920
+			// 3. ... If a message is received with both a
921
+			// Transfer-Encoding header field and a Content-Length header field,
922
+			// the latter MUST be ignored.
923
+			$toRead = ($chunked || null === $length)? null: $length;
924
+			$this->chunkLength = 0;
925
+
926
+			while (!feof($this->socket) && (is_null($toRead) || 0 < $toRead)) {
927
+				if ($chunked) {
928
+					$data = $this->readChunked($bufferSize);
929
+				} elseif (is_null($toRead)) {
930
+					$data = $this->fread($bufferSize);
931
+				} else {
932
+					$data    = $this->fread(min($toRead, $bufferSize));
933
+					$toRead -= strlen($data);
934
+				}
935
+				if ('' == $data && (!$this->chunkLength || feof($this->socket))) {
936
+					break;
937
+				}
938
+
939
+				$hasBody = true;
940
+				if ($this->request->getConfig('store_body')) {
941
+					$response->appendBody($data);
942
+				}
943
+				if (!in_array($response->getHeader('content-encoding'), array('identity', null))) {
944
+					$this->request->setLastEvent('receivedEncodedBodyPart', $data);
945
+				} else {
946
+					$this->request->setLastEvent('receivedBodyPart', $data);
947
+				}
948
+			}
949
+		}
950
+
951
+		if ($hasBody) {
952
+			$this->request->setLastEvent('receivedBody', $response);
953
+		}
954
+		return $response;
955
+	}
956 956
 
957 957
    /**
958 958
     * Reads until either the end of the socket or a newline, whichever comes first
@@ -964,27 +964,27 @@  discard block
 block discarded – undo
964 964
     * @return   Available data up to the newline (not including newline)
965 965
     * @throws   HTTP_Request2_Exception     In case of timeout
966 966
     */
967
-    protected function readLine($bufferSize)
968
-    {
969
-        $line = '';
970
-        while (!feof($this->socket)) {
971
-            if ($this->deadline) {
972
-                stream_set_timeout($this->socket, max($this->deadline - time(), 1));
973
-            }
974
-            $line .= @fgets($this->socket, $bufferSize);
975
-            $info  = stream_get_meta_data($this->socket);
976
-            if ($info['timed_out'] || $this->deadline && time() > $this->deadline) {
977
-                $reason = $this->deadline
978
-                          ? 'after ' . $this->request->getConfig('timeout') . ' second(s)'
979
-                          : 'due to default_socket_timeout php.ini setting';
980
-                throw new HTTP_Request2_Exception("Request timed out {$reason}");
981
-            }
982
-            if (substr($line, -1) == "\n") {
983
-                return rtrim($line, "\r\n");
984
-            }
985
-        }
986
-        return $line;
987
-    }
967
+	protected function readLine($bufferSize)
968
+	{
969
+		$line = '';
970
+		while (!feof($this->socket)) {
971
+			if ($this->deadline) {
972
+				stream_set_timeout($this->socket, max($this->deadline - time(), 1));
973
+			}
974
+			$line .= @fgets($this->socket, $bufferSize);
975
+			$info  = stream_get_meta_data($this->socket);
976
+			if ($info['timed_out'] || $this->deadline && time() > $this->deadline) {
977
+				$reason = $this->deadline
978
+						  ? 'after ' . $this->request->getConfig('timeout') . ' second(s)'
979
+						  : 'due to default_socket_timeout php.ini setting';
980
+				throw new HTTP_Request2_Exception("Request timed out {$reason}");
981
+			}
982
+			if (substr($line, -1) == "\n") {
983
+				return rtrim($line, "\r\n");
984
+			}
985
+		}
986
+		return $line;
987
+	}
988 988
 
989 989
    /**
990 990
     * Wrapper around fread(), handles global request timeout
@@ -993,21 +993,21 @@  discard block
 block discarded – undo
993 993
     * @return   Data read from socket
994 994
     * @throws   HTTP_Request2_Exception     In case of timeout
995 995
     */
996
-    protected function fread($length)
997
-    {
998
-        if ($this->deadline) {
999
-            stream_set_timeout($this->socket, max($this->deadline - time(), 1));
1000
-        }
1001
-        $data = fread($this->socket, $length);
1002
-        $info = stream_get_meta_data($this->socket);
1003
-        if ($info['timed_out'] || $this->deadline && time() > $this->deadline) {
1004
-            $reason = $this->deadline
1005
-                      ? 'after ' . $this->request->getConfig('timeout') . ' second(s)'
1006
-                      : 'due to default_socket_timeout php.ini setting';
1007
-            throw new HTTP_Request2_Exception("Request timed out {$reason}");
1008
-        }
1009
-        return $data;
1010
-    }
996
+	protected function fread($length)
997
+	{
998
+		if ($this->deadline) {
999
+			stream_set_timeout($this->socket, max($this->deadline - time(), 1));
1000
+		}
1001
+		$data = fread($this->socket, $length);
1002
+		$info = stream_get_meta_data($this->socket);
1003
+		if ($info['timed_out'] || $this->deadline && time() > $this->deadline) {
1004
+			$reason = $this->deadline
1005
+					  ? 'after ' . $this->request->getConfig('timeout') . ' second(s)'
1006
+					  : 'due to default_socket_timeout php.ini setting';
1007
+			throw new HTTP_Request2_Exception("Request timed out {$reason}");
1008
+		}
1009
+		return $data;
1010
+	}
1011 1011
 
1012 1012
    /**
1013 1013
     * Reads a part of response body encoded with chunked Transfer-Encoding
@@ -1016,31 +1016,31 @@  discard block
 block discarded – undo
1016 1016
     * @return   string
1017 1017
     * @throws   HTTP_Request2_Exception
1018 1018
     */
1019
-    protected function readChunked($bufferSize)
1020
-    {
1021
-        // at start of the next chunk?
1022
-        if (0 == $this->chunkLength) {
1023
-            $line = $this->readLine($bufferSize);
1024
-            if (!preg_match('/^([0-9a-f]+)/i', $line, $matches)) {
1025
-                throw new HTTP_Request2_Exception(
1026
-                    "Cannot decode chunked response, invalid chunk length '{$line}'"
1027
-                );
1028
-            } else {
1029
-                $this->chunkLength = hexdec($matches[1]);
1030
-                // Chunk with zero length indicates the end
1031
-                if (0 == $this->chunkLength) {
1032
-                    $this->readLine($bufferSize);
1033
-                    return '';
1034
-                }
1035
-            }
1036
-        }
1037
-        $data = $this->fread(min($this->chunkLength, $bufferSize));
1038
-        $this->chunkLength -= strlen($data);
1039
-        if (0 == $this->chunkLength) {
1040
-            $this->readLine($bufferSize); // Trailing CRLF
1041
-        }
1042
-        return $data;
1043
-    }
1019
+	protected function readChunked($bufferSize)
1020
+	{
1021
+		// at start of the next chunk?
1022
+		if (0 == $this->chunkLength) {
1023
+			$line = $this->readLine($bufferSize);
1024
+			if (!preg_match('/^([0-9a-f]+)/i', $line, $matches)) {
1025
+				throw new HTTP_Request2_Exception(
1026
+					"Cannot decode chunked response, invalid chunk length '{$line}'"
1027
+				);
1028
+			} else {
1029
+				$this->chunkLength = hexdec($matches[1]);
1030
+				// Chunk with zero length indicates the end
1031
+				if (0 == $this->chunkLength) {
1032
+					$this->readLine($bufferSize);
1033
+					return '';
1034
+				}
1035
+			}
1036
+		}
1037
+		$data = $this->fread(min($this->chunkLength, $bufferSize));
1038
+		$this->chunkLength -= strlen($data);
1039
+		if (0 == $this->chunkLength) {
1040
+			$this->readLine($bufferSize); // Trailing CRLF
1041
+		}
1042
+		return $data;
1043
+	}
1044 1044
 }
1045 1045
 
1046 1046
 ?>
1047 1047
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +65 added lines, -68 removed lines patch added patch discarded remove patch
@@ -162,8 +162,8 @@  discard block
 block discarded – undo
162 162
 
163 163
             if ($this->deadline && time() > $this->deadline) {
164 164
                 throw new HTTP_Request2_Exception(
165
-                    'Request timed out after ' .
166
-                    $request->getConfig('timeout') . ' second(s)'
165
+                    'Request timed out after '.
166
+                    $request->getConfig('timeout').' second(s)'
167 167
                 );
168 168
             }
169 169
 
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
         $headers = $this->request->getHeaders();
217 217
         $reqHost = $this->request->getUrl()->getHost();
218 218
         if (!($reqPort = $this->request->getUrl()->getPort())) {
219
-            $reqPort = $secure? 443: 80;
219
+            $reqPort = $secure ? 443 : 80;
220 220
         }
221 221
 
222 222
         if ($host = $this->request->getConfig('proxy_host')) {
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
                       empty($headers['connection'])) ||
254 254
                      (!empty($headers['connection']) &&
255 255
                       'Keep-Alive' == $headers['connection']);
256
-        $host = ((!$secure || $proxy)? 'tcp://': 'ssl://') . $host;
256
+        $host = ((!$secure || $proxy) ? 'tcp://' : 'ssl://').$host;
257 257
 
258 258
         $options = array();
259 259
         if ($secure || $tunnel) {
@@ -273,9 +273,9 @@  discard block
 block discarded – undo
273 273
 
274 274
         // Changing SSL context options after connection is established does *not*
275 275
         // work, we need a new connection if options change
276
-        $remote    = $host . ':' . $port;
277
-        $socketKey = $remote . (($secure && $proxy)? "->{$reqHost}:{$reqPort}": '') .
278
-                     (empty($options)? '': ':' . serialize($options));
276
+        $remote    = $host.':'.$port;
277
+        $socketKey = $remote.(($secure && $proxy) ? "->{$reqHost}:{$reqPort}" : '').
278
+                     (empty($options) ? '' : ':'.serialize($options));
279 279
         unset($this->socket);
280 280
 
281 281
         // We use persistent connections and have a connected socket?
@@ -283,14 +283,14 @@  discard block
 block discarded – undo
283 283
         if ($keepAlive && !empty(self::$sockets[$socketKey]) &&
284 284
             !feof(self::$sockets[$socketKey])
285 285
         ) {
286
-            $this->socket =& self::$sockets[$socketKey];
286
+            $this->socket = & self::$sockets[$socketKey];
287 287
 
288 288
         } elseif ($secure && $proxy && !$tunnel) {
289 289
             $this->establishTunnel();
290 290
             $this->request->setLastEvent(
291 291
                 'connect', "ssl://{$reqHost}:{$reqPort} via {$host}:{$port}"
292 292
             );
293
-            self::$sockets[$socketKey] =& $this->socket;
293
+            self::$sockets[$socketKey] = & $this->socket;
294 294
 
295 295
         } else {
296 296
             // Set SSL context options if doing HTTPS request or creating a tunnel
@@ -313,7 +313,7 @@  discard block
 block discarded – undo
313 313
                 );
314 314
             }
315 315
             $this->request->setLastEvent('connect', $remote);
316
-            self::$sockets[$socketKey] =& $this->socket;
316
+            self::$sockets[$socketKey] = & $this->socket;
317 317
         }
318 318
         return $keepAlive;
319 319
     }
@@ -340,8 +340,8 @@  discard block
 block discarded – undo
340 340
         // Need any successful (2XX) response
341 341
         if (200 > $response->getStatus() || 300 <= $response->getStatus()) {
342 342
             throw new HTTP_Request2_Exception(
343
-                'Failed to connect via HTTPS proxy. Proxy response: ' .
344
-                $response->getStatus() . ' ' . $response->getReasonPhrase()
343
+                'Failed to connect via HTTPS proxy. Proxy response: '.
344
+                $response->getStatus().' '.$response->getReasonPhrase()
345 345
             );
346 346
         }
347 347
         $this->socket = $donor->socket;
@@ -421,7 +421,7 @@  discard block
 block discarded – undo
421 421
         if (0 == $this->redirectCountdown) {
422 422
             // Copying cURL behaviour
423 423
             throw new HTTP_Request2_Exception(
424
-                'Maximum (' . $request->getConfig('max_redirects') . ') redirects followed'
424
+                'Maximum ('.$request->getConfig('max_redirects').') redirects followed'
425 425
             );
426 426
         }
427 427
         $redirectUrl = new Net_URL2(
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
             && !in_array($redirectUrl->getScheme(), array('http', 'https'))
434 434
         ) {
435 435
             throw new HTTP_Request2_Exception(
436
-                'Refusing to redirect to a non-HTTP URL ' . $redirectUrl->__toString()
436
+                'Refusing to redirect to a non-HTTP URL '.$redirectUrl->__toString()
437 437
             );
438 438
         }
439 439
         // Theoretically URL should be absolute (see http://tools.ietf.org/html/rfc2616#section-14.30),
@@ -485,12 +485,12 @@  discard block
 block discarded – undo
485 485
 
486 486
         $url    = $this->request->getUrl();
487 487
         $scheme = $url->getScheme();
488
-        $host   = $scheme . '://' . $url->getHost();
488
+        $host   = $scheme.'://'.$url->getHost();
489 489
         if ($port = $url->getPort()) {
490 490
             if ((0 == strcasecmp($scheme, 'http') && 80 != $port) ||
491 491
                 (0 == strcasecmp($scheme, 'https') && 443 != $port)
492 492
             ) {
493
-                $host .= ':' . $port;
493
+                $host .= ':'.$port;
494 494
             }
495 495
         }
496 496
 
@@ -499,12 +499,12 @@  discard block
 block discarded – undo
499 499
             foreach (preg_split('/\\s+/', $challenge['domain']) as $prefix) {
500 500
                 // don't bother with different servers
501 501
                 if ('/' == substr($prefix, 0, 1)) {
502
-                    $prefixes[] = $host . $prefix;
502
+                    $prefixes[] = $host.$prefix;
503 503
                 }
504 504
             }
505 505
         }
506 506
         if (empty($prefixes)) {
507
-            $prefixes = array($host . '/');
507
+            $prefixes = array($host.'/');
508 508
         }
509 509
 
510 510
         $ret = true;
@@ -515,7 +515,7 @@  discard block
 block discarded – undo
515 515
                 // probably credentials are invalid
516 516
                 $ret = false;
517 517
             }
518
-            self::$challenges[$prefix] =& $challenge;
518
+            self::$challenges[$prefix] = & $challenge;
519 519
         }
520 520
         return $ret;
521 521
     }
@@ -546,8 +546,8 @@  discard block
 block discarded – undo
546 546
             return false;
547 547
         }
548 548
 
549
-        $key = 'proxy://' . $this->request->getConfig('proxy_host') .
550
-               ':' . $this->request->getConfig('proxy_port');
549
+        $key = 'proxy://'.$this->request->getConfig('proxy_host').
550
+               ':'.$this->request->getConfig('proxy_port');
551 551
 
552 552
         if (!empty(self::$challenges[$key]) &&
553 553
             (empty($challenge['stale']) || strcasecmp('true', $challenge['stale']))
@@ -590,14 +590,14 @@  discard block
 block discarded – undo
590 590
     */
591 591
     protected function parseDigestChallenge($headerValue)
592 592
     {
593
-        $authParam   = '(' . self::REGEXP_TOKEN . ')\\s*=\\s*(' .
594
-                       self::REGEXP_TOKEN . '|' . self::REGEXP_QUOTED_STRING . ')';
593
+        $authParam   = '('.self::REGEXP_TOKEN.')\\s*=\\s*('.
594
+                       self::REGEXP_TOKEN.'|'.self::REGEXP_QUOTED_STRING.')';
595 595
         $challenge   = "!(?<=^|\\s|,)Digest ({$authParam}\\s*(,\\s*|$))+!";
596 596
         if (!preg_match($challenge, $headerValue, $matches)) {
597 597
             return false;
598 598
         }
599 599
 
600
-        preg_match_all('!' . $authParam . '!', $matches[0], $params);
600
+        preg_match_all('!'.$authParam.'!', $matches[0], $params);
601 601
         $paramsAry   = array();
602 602
         $knownParams = array('realm', 'domain', 'nonce', 'opaque', 'stale',
603 603
                              'algorithm', 'qop');
@@ -616,14 +616,14 @@  discard block
 block discarded – undo
616 616
             !in_array('auth', array_map('trim', explode(',', $paramsAry['qop'])))
617 617
         ) {
618 618
             throw new HTTP_Request2_Exception(
619
-                "Only 'auth' qop is currently supported in digest authentication, " .
619
+                "Only 'auth' qop is currently supported in digest authentication, ".
620 620
                 "server requested '{$paramsAry['qop']}'"
621 621
             );
622 622
         }
623 623
         // we only support algorithm=MD5
624 624
         if (!empty($paramsAry['algorithm']) && 'MD5' != $paramsAry['algorithm']) {
625 625
             throw new HTTP_Request2_Exception(
626
-                "Only 'MD5' algorithm is currently supported in digest authentication, " .
626
+                "Only 'MD5' algorithm is currently supported in digest authentication, ".
627 627
                 "server requested '{$paramsAry['algorithm']}'"
628 628
             );
629 629
         }
@@ -640,8 +640,8 @@  discard block
 block discarded – undo
640 640
     */
641 641
     protected function updateChallenge(&$challenge, $headerValue)
642 642
     {
643
-        $authParam   = '!(' . self::REGEXP_TOKEN . ')\\s*=\\s*(' .
644
-                       self::REGEXP_TOKEN . '|' . self::REGEXP_QUOTED_STRING . ')!';
643
+        $authParam   = '!('.self::REGEXP_TOKEN.')\\s*=\\s*('.
644
+                       self::REGEXP_TOKEN.'|'.self::REGEXP_QUOTED_STRING.')!';
645 645
         $paramsAry   = array();
646 646
 
647 647
         preg_match_all($authParam, $headerValue, $params);
@@ -677,31 +677,29 @@  discard block
 block discarded – undo
677 677
             $url = substr($url, 0, $q);
678 678
         }
679 679
 
680
-        $a1 = md5($user . ':' . $challenge['realm'] . ':' . $password);
681
-        $a2 = md5($this->request->getMethod() . ':' . $url);
680
+        $a1 = md5($user.':'.$challenge['realm'].':'.$password);
681
+        $a2 = md5($this->request->getMethod().':'.$url);
682 682
 
683 683
         if (empty($challenge['qop'])) {
684
-            $digest = md5($a1 . ':' . $challenge['nonce'] . ':' . $a2);
684
+            $digest = md5($a1.':'.$challenge['nonce'].':'.$a2);
685 685
         } else {
686
-            $challenge['cnonce'] = 'Req2.' . rand();
686
+            $challenge['cnonce'] = 'Req2.'.rand();
687 687
             if (empty($challenge['nc'])) {
688 688
                 $challenge['nc'] = 1;
689 689
             }
690 690
             $nc     = sprintf('%08x', $challenge['nc']++);
691
-            $digest = md5($a1 . ':' . $challenge['nonce'] . ':' . $nc . ':' .
692
-                          $challenge['cnonce'] . ':auth:' . $a2);
691
+            $digest = md5($a1.':'.$challenge['nonce'].':'.$nc.':'.
692
+                          $challenge['cnonce'].':auth:'.$a2);
693 693
         }
694
-        return 'Digest username="' . str_replace(array('\\', '"'), array('\\\\', '\\"'), $user) . '", ' .
695
-               'realm="' . $challenge['realm'] . '", ' .
696
-               'nonce="' . $challenge['nonce'] . '", ' .
697
-               'uri="' . $url . '", ' .
698
-               'response="' . $digest . '"' .
699
-               (!empty($challenge['opaque'])?
700
-                ', opaque="' . $challenge['opaque'] . '"':
701
-                '') .
702
-               (!empty($challenge['qop'])?
703
-                ', qop="auth", nc=' . $nc . ', cnonce="' . $challenge['cnonce'] . '"':
704
-                '');
694
+        return 'Digest username="'.str_replace(array('\\', '"'), array('\\\\', '\\"'), $user).'", '.
695
+               'realm="'.$challenge['realm'].'", '.
696
+               'nonce="'.$challenge['nonce'].'", '.
697
+               'uri="'.$url.'", '.
698
+               'response="'.$digest.'"'.
699
+               (!empty($challenge['opaque']) ?
700
+                ', opaque="'.$challenge['opaque'].'"' : '').
701
+               (!empty($challenge['qop']) ?
702
+                ', qop="auth", nc='.$nc.', cnonce="'.$challenge['cnonce'].'"' : '');
705 703
     }
706 704
 
707 705
    /**
@@ -720,22 +718,21 @@  discard block
 block discarded – undo
720 718
         switch ($auth['scheme']) {
721 719
             case HTTP_Request2::AUTH_BASIC:
722 720
                 $headers['authorization'] =
723
-                    'Basic ' . base64_encode($auth['user'] . ':' . $auth['password']);
721
+                    'Basic '.base64_encode($auth['user'].':'.$auth['password']);
724 722
                 break;
725 723
 
726 724
             case HTTP_Request2::AUTH_DIGEST:
727 725
                 unset($this->serverChallenge);
728
-                $fullUrl = ('/' == $requestUrl[0])?
729
-                           $this->request->getUrl()->getScheme() . '://' .
730
-                            $requestHost . $requestUrl:
731
-                           $requestUrl;
726
+                $fullUrl = ('/' == $requestUrl[0]) ?
727
+                           $this->request->getUrl()->getScheme().'://'.
728
+                            $requestHost.$requestUrl : $requestUrl;
732 729
                 foreach (array_keys(self::$challenges) as $key) {
733 730
                     if ($key == substr($fullUrl, 0, strlen($key))) {
734 731
                         $headers['authorization'] = $this->createDigestResponse(
735 732
                             $auth['user'], $auth['password'],
736 733
                             $requestUrl, self::$challenges[$key]
737 734
                         );
738
-                        $this->serverChallenge =& self::$challenges[$key];
735
+                        $this->serverChallenge = & self::$challenges[$key];
739 736
                         break;
740 737
                     }
741 738
                 }
@@ -769,26 +766,26 @@  discard block
 block discarded – undo
769 766
         switch ($this->request->getConfig('proxy_auth_scheme')) {
770 767
             case HTTP_Request2::AUTH_BASIC:
771 768
                 $headers['proxy-authorization'] =
772
-                    'Basic ' . base64_encode($user . ':' . $password);
769
+                    'Basic '.base64_encode($user.':'.$password);
773 770
                 break;
774 771
 
775 772
             case HTTP_Request2::AUTH_DIGEST:
776 773
                 unset($this->proxyChallenge);
777
-                $proxyUrl = 'proxy://' . $this->request->getConfig('proxy_host') .
778
-                            ':' . $this->request->getConfig('proxy_port');
774
+                $proxyUrl = 'proxy://'.$this->request->getConfig('proxy_host').
775
+                            ':'.$this->request->getConfig('proxy_port');
779 776
                 if (!empty(self::$challenges[$proxyUrl])) {
780 777
                     $headers['proxy-authorization'] = $this->createDigestResponse(
781 778
                         $user, $password,
782 779
                         $requestUrl, self::$challenges[$proxyUrl]
783 780
                     );
784
-                    $this->proxyChallenge =& self::$challenges[$proxyUrl];
781
+                    $this->proxyChallenge = & self::$challenges[$proxyUrl];
785 782
                 }
786 783
                 break;
787 784
 
788 785
             default:
789 786
                 throw new HTTP_Request2_Exception(
790
-                    "Unknown HTTP authentication scheme '" .
791
-                    $this->request->getConfig('proxy_auth_scheme') . "'"
787
+                    "Unknown HTTP authentication scheme '".
788
+                    $this->request->getConfig('proxy_auth_scheme')."'"
792 789
                 );
793 790
         }
794 791
     }
@@ -807,9 +804,9 @@  discard block
 block discarded – undo
807 804
         $connect = HTTP_Request2::METHOD_CONNECT == $this->request->getMethod();
808 805
         $host    = $url->getHost();
809 806
 
810
-        $defaultPort = 0 == strcasecmp($url->getScheme(), 'https')? 443: 80;
807
+        $defaultPort = 0 == strcasecmp($url->getScheme(), 'https') ? 443 : 80;
811 808
         if (($port = $url->getPort()) && $port != $defaultPort || $connect) {
812
-            $host .= ':' . (empty($port)? $defaultPort: $port);
809
+            $host .= ':'.(empty($port) ? $defaultPort : $port);
813 810
         }
814 811
         // Do not overwrite explicitly set 'Host' header, see bug #16146
815 812
         if (!isset($headers['host'])) {
@@ -825,11 +822,11 @@  discard block
 block discarded – undo
825 822
             ) {
826 823
                 $requestUrl = '';
827 824
             } else {
828
-                $requestUrl = $url->getScheme() . '://' . $host;
825
+                $requestUrl = $url->getScheme().'://'.$host;
829 826
             }
830 827
             $path        = $url->getPath();
831 828
             $query       = $url->getQuery();
832
-            $requestUrl .= (empty($path)? '/': $path) . (empty($query)? '': '?' . $query);
829
+            $requestUrl .= (empty($path) ? '/' : $path).(empty($query) ? '' : '?'.$query);
833 830
         }
834 831
 
835 832
         if ('1.1' == $this->request->getConfig('protocol_version') &&
@@ -842,13 +839,13 @@  discard block
 block discarded – undo
842 839
         $this->addProxyAuthorizationHeader($headers, $requestUrl);
843 840
         $this->calculateRequestLength($headers);
844 841
 
845
-        $headersStr = $this->request->getMethod() . ' ' . $requestUrl . ' HTTP/' .
846
-                      $this->request->getConfig('protocol_version') . "\r\n";
842
+        $headersStr = $this->request->getMethod().' '.$requestUrl.' HTTP/'.
843
+                      $this->request->getConfig('protocol_version')."\r\n";
847 844
         foreach ($headers as $name => $value) {
848 845
             $canonicalName = implode('-', array_map('ucfirst', explode('-', $name)));
849
-            $headersStr   .= $canonicalName . ': ' . $value . "\r\n";
846
+            $headersStr   .= $canonicalName.': '.$value."\r\n";
850 847
         }
851
-        return $headersStr . "\r\n";
848
+        return $headersStr."\r\n";
852 849
     }
853 850
 
854 851
    /**
@@ -920,7 +917,7 @@  discard block
 block discarded – undo
920 917
             // 3. ... If a message is received with both a
921 918
             // Transfer-Encoding header field and a Content-Length header field,
922 919
             // the latter MUST be ignored.
923
-            $toRead = ($chunked || null === $length)? null: $length;
920
+            $toRead = ($chunked || null === $length) ? null : $length;
924 921
             $this->chunkLength = 0;
925 922
 
926 923
             while (!feof($this->socket) && (is_null($toRead) || 0 < $toRead)) {
@@ -975,7 +972,7 @@  discard block
 block discarded – undo
975 972
             $info  = stream_get_meta_data($this->socket);
976 973
             if ($info['timed_out'] || $this->deadline && time() > $this->deadline) {
977 974
                 $reason = $this->deadline
978
-                          ? 'after ' . $this->request->getConfig('timeout') . ' second(s)'
975
+                          ? 'after '.$this->request->getConfig('timeout').' second(s)'
979 976
                           : 'due to default_socket_timeout php.ini setting';
980 977
                 throw new HTTP_Request2_Exception("Request timed out {$reason}");
981 978
             }
@@ -1002,7 +999,7 @@  discard block
 block discarded – undo
1002 999
         $info = stream_get_meta_data($this->socket);
1003 1000
         if ($info['timed_out'] || $this->deadline && time() > $this->deadline) {
1004 1001
             $reason = $this->deadline
1005
-                      ? 'after ' . $this->request->getConfig('timeout') . ' second(s)'
1002
+                      ? 'after '.$this->request->getConfig('timeout').' second(s)'
1006 1003
                       : 'due to default_socket_timeout php.ini setting';
1007 1004
             throw new HTTP_Request2_Exception("Request timed out {$reason}");
1008 1005
         }
Please login to merge, or discard this patch.
libs/PEAR.1.9/PEAR.php 2 patches
Indentation   +1016 added lines, -1016 removed lines patch added patch discarded remove patch
@@ -34,16 +34,16 @@  discard block
 block discarded – undo
34 34
 define('PEAR_ERROR_EXCEPTION', 32);
35 35
 /**#@-*/
36 36
 define('PEAR_ZE2', (function_exists('version_compare') &&
37
-                    version_compare(zend_version(), "2-dev", "ge")));
37
+					version_compare(zend_version(), "2-dev", "ge")));
38 38
 
39 39
 if (substr(PHP_OS, 0, 3) == 'WIN') {
40
-    define('OS_WINDOWS', true);
41
-    define('OS_UNIX',    false);
42
-    define('PEAR_OS',    'Windows');
40
+	define('OS_WINDOWS', true);
41
+	define('OS_UNIX',    false);
42
+	define('PEAR_OS',    'Windows');
43 43
 } else {
44
-    define('OS_WINDOWS', false);
45
-    define('OS_UNIX',    true);
46
-    define('PEAR_OS',    'Unix'); // blatant assumption
44
+	define('OS_WINDOWS', false);
45
+	define('OS_UNIX',    true);
46
+	define('PEAR_OS',    'Unix'); // blatant assumption
47 47
 }
48 48
 
49 49
 $GLOBALS['_PEAR_default_error_mode']     = PEAR_ERROR_RETURN;
@@ -86,728 +86,728 @@  discard block
 block discarded – undo
86 86
  */
87 87
 class PEAR
88 88
 {
89
-    // {{{ properties
90
-
91
-    /**
92
-     * Whether to enable internal debug messages.
93
-     *
94
-     * @var     bool
95
-     * @access  private
96
-     */
97
-    var $_debug = false;
98
-
99
-    /**
100
-     * Default error mode for this object.
101
-     *
102
-     * @var     int
103
-     * @access  private
104
-     */
105
-    var $_default_error_mode = null;
106
-
107
-    /**
108
-     * Default error options used for this object when error mode
109
-     * is PEAR_ERROR_TRIGGER.
110
-     *
111
-     * @var     int
112
-     * @access  private
113
-     */
114
-    var $_default_error_options = null;
115
-
116
-    /**
117
-     * Default error handler (callback) for this object, if error mode is
118
-     * PEAR_ERROR_CALLBACK.
119
-     *
120
-     * @var     string
121
-     * @access  private
122
-     */
123
-    var $_default_error_handler = '';
124
-
125
-    /**
126
-     * Which class to use for error objects.
127
-     *
128
-     * @var     string
129
-     * @access  private
130
-     */
131
-    var $_error_class = 'PEAR_Error';
132
-
133
-    /**
134
-     * An array of expected errors.
135
-     *
136
-     * @var     array
137
-     * @access  private
138
-     */
139
-    var $_expected_errors = array();
140
-
141
-    // }}}
142
-
143
-    // {{{ constructor
144
-
145
-    /**
146
-     * Constructor.  Registers this object in
147
-     * $_PEAR_destructor_object_list for destructor emulation if a
148
-     * destructor object exists.
149
-     *
150
-     * @param string $error_class  (optional) which class to use for
151
-     *        error objects, defaults to PEAR_Error.
152
-     * @access public
153
-     * @return void
154
-     */
155
-    function PEAR($error_class = null)
156
-    {
157
-        $classname = strtolower(get_class($this));
158
-        if ($this->_debug) {
159
-            print "PEAR constructor called, class=$classname\n";
160
-        }
161
-        if ($error_class !== null) {
162
-            $this->_error_class = $error_class;
163
-        }
164
-        while ($classname && strcasecmp($classname, "pear")) {
165
-            $destructor = "_$classname";
166
-            if (method_exists($this, $destructor)) {
167
-                global $_PEAR_destructor_object_list;
168
-                $_PEAR_destructor_object_list[] = &$this;
169
-                if (!isset($GLOBALS['_PEAR_SHUTDOWN_REGISTERED'])) {
170
-                    register_shutdown_function("_PEAR_call_destructors");
171
-                    $GLOBALS['_PEAR_SHUTDOWN_REGISTERED'] = true;
172
-                }
173
-                break;
174
-            } else {
175
-                $classname = get_parent_class($classname);
176
-            }
177
-        }
178
-    }
179
-
180
-    // }}}
181
-    // {{{ destructor
182
-
183
-    /**
184
-     * Destructor (the emulated type of...).  Does nothing right now,
185
-     * but is included for forward compatibility, so subclass
186
-     * destructors should always call it.
187
-     *
188
-     * See the note in the class desciption about output from
189
-     * destructors.
190
-     *
191
-     * @access public
192
-     * @return void
193
-     */
194
-    function _PEAR() {
195
-        if ($this->_debug) {
196
-            printf("PEAR destructor called, class=%s\n", strtolower(get_class($this)));
197
-        }
198
-    }
199
-
200
-    // }}}
201
-    // {{{ getStaticProperty()
202
-
203
-    /**
204
-    * If you have a class that's mostly/entirely static, and you need static
205
-    * properties, you can use this method to simulate them. Eg. in your method(s)
206
-    * do this: $myVar = &PEAR::getStaticProperty('myclass', 'myVar');
207
-    * You MUST use a reference, or they will not persist!
208
-    *
209
-    * @access public
210
-    * @param  string $class  The calling classname, to prevent clashes
211
-    * @param  string $var    The variable to retrieve.
212
-    * @return mixed   A reference to the variable. If not set it will be
213
-    *                 auto initialised to NULL.
214
-    */
215
-    function &getStaticProperty($class, $var)
216
-    {
217
-        static $properties;
218
-        if (!isset($properties[$class])) {
219
-            $properties[$class] = array();
220
-        }
221
-
222
-        if (!array_key_exists($var, $properties[$class])) {
223
-            $properties[$class][$var] = null;
224
-        }
225
-
226
-        return $properties[$class][$var];
227
-    }
228
-
229
-    // }}}
230
-    // {{{ registerShutdownFunc()
231
-
232
-    /**
233
-    * Use this function to register a shutdown method for static
234
-    * classes.
235
-    *
236
-    * @access public
237
-    * @param  mixed $func  The function name (or array of class/method) to call
238
-    * @param  mixed $args  The arguments to pass to the function
239
-    * @return void
240
-    */
241
-    function registerShutdownFunc($func, $args = array())
242
-    {
243
-        // if we are called statically, there is a potential
244
-        // that no shutdown func is registered.  Bug #6445
245
-        if (!isset($GLOBALS['_PEAR_SHUTDOWN_REGISTERED'])) {
246
-            register_shutdown_function("_PEAR_call_destructors");
247
-            $GLOBALS['_PEAR_SHUTDOWN_REGISTERED'] = true;
248
-        }
249
-        $GLOBALS['_PEAR_shutdown_funcs'][] = array($func, $args);
250
-    }
251
-
252
-    // }}}
253
-    // {{{ isError()
254
-
255
-    /**
256
-     * Tell whether a value is a PEAR error.
257
-     *
258
-     * @param   mixed $data   the value to test
259
-     * @param   int   $code   if $data is an error object, return true
260
-     *                        only if $code is a string and
261
-     *                        $obj->getMessage() == $code or
262
-     *                        $code is an integer and $obj->getCode() == $code
263
-     * @access  public
264
-     * @return  bool    true if parameter is an error
265
-     */
266
-    function isError($data, $code = null)
267
-    {
268
-        if (!is_a($data, 'PEAR_Error')) {
269
-            return false;
270
-        }
271
-
272
-        if (is_null($code)) {
273
-            return true;
274
-        } elseif (is_string($code)) {
275
-            return $data->getMessage() == $code;
276
-        }
277
-
278
-        return $data->getCode() == $code;
279
-    }
280
-
281
-    // }}}
282
-    // {{{ setErrorHandling()
283
-
284
-    /**
285
-     * Sets how errors generated by this object should be handled.
286
-     * Can be invoked both in objects and statically.  If called
287
-     * statically, setErrorHandling sets the default behaviour for all
288
-     * PEAR objects.  If called in an object, setErrorHandling sets
289
-     * the default behaviour for that object.
290
-     *
291
-     * @param int $mode
292
-     *        One of PEAR_ERROR_RETURN, PEAR_ERROR_PRINT,
293
-     *        PEAR_ERROR_TRIGGER, PEAR_ERROR_DIE,
294
-     *        PEAR_ERROR_CALLBACK or PEAR_ERROR_EXCEPTION.
295
-     *
296
-     * @param mixed $options
297
-     *        When $mode is PEAR_ERROR_TRIGGER, this is the error level (one
298
-     *        of E_USER_NOTICE, E_USER_WARNING or E_USER_ERROR).
299
-     *
300
-     *        When $mode is PEAR_ERROR_CALLBACK, this parameter is expected
301
-     *        to be the callback function or method.  A callback
302
-     *        function is a string with the name of the function, a
303
-     *        callback method is an array of two elements: the element
304
-     *        at index 0 is the object, and the element at index 1 is
305
-     *        the name of the method to call in the object.
306
-     *
307
-     *        When $mode is PEAR_ERROR_PRINT or PEAR_ERROR_DIE, this is
308
-     *        a printf format string used when printing the error
309
-     *        message.
310
-     *
311
-     * @access public
312
-     * @return void
313
-     * @see PEAR_ERROR_RETURN
314
-     * @see PEAR_ERROR_PRINT
315
-     * @see PEAR_ERROR_TRIGGER
316
-     * @see PEAR_ERROR_DIE
317
-     * @see PEAR_ERROR_CALLBACK
318
-     * @see PEAR_ERROR_EXCEPTION
319
-     *
320
-     * @since PHP 4.0.5
321
-     */
322
-
323
-    function setErrorHandling($mode = null, $options = null)
324
-    {
325
-        if (isset($this) && is_a($this, 'PEAR')) {
326
-            $setmode     = &$this->_default_error_mode;
327
-            $setoptions  = &$this->_default_error_options;
328
-        } else {
329
-            $setmode     = &$GLOBALS['_PEAR_default_error_mode'];
330
-            $setoptions  = &$GLOBALS['_PEAR_default_error_options'];
331
-        }
332
-
333
-        switch ($mode) {
334
-            case PEAR_ERROR_EXCEPTION:
335
-            case PEAR_ERROR_RETURN:
336
-            case PEAR_ERROR_PRINT:
337
-            case PEAR_ERROR_TRIGGER:
338
-            case PEAR_ERROR_DIE:
339
-            case null:
340
-                $setmode = $mode;
341
-                $setoptions = $options;
342
-                break;
343
-
344
-            case PEAR_ERROR_CALLBACK:
345
-                $setmode = $mode;
346
-                // class/object method callback
347
-                if (is_callable($options)) {
348
-                    $setoptions = $options;
349
-                } else {
350
-                    trigger_error("invalid error callback", E_USER_WARNING);
351
-                }
352
-                break;
353
-
354
-            default:
355
-                trigger_error("invalid error mode", E_USER_WARNING);
356
-                break;
357
-        }
358
-    }
359
-
360
-    // }}}
361
-    // {{{ expectError()
362
-
363
-    /**
364
-     * This method is used to tell which errors you expect to get.
365
-     * Expected errors are always returned with error mode
366
-     * PEAR_ERROR_RETURN.  Expected error codes are stored in a stack,
367
-     * and this method pushes a new element onto it.  The list of
368
-     * expected errors are in effect until they are popped off the
369
-     * stack with the popExpect() method.
370
-     *
371
-     * Note that this method can not be called statically
372
-     *
373
-     * @param mixed $code a single error code or an array of error codes to expect
374
-     *
375
-     * @return int     the new depth of the "expected errors" stack
376
-     * @access public
377
-     */
378
-    function expectError($code = '*')
379
-    {
380
-        if (is_array($code)) {
381
-            array_push($this->_expected_errors, $code);
382
-        } else {
383
-            array_push($this->_expected_errors, array($code));
384
-        }
385
-        return sizeof($this->_expected_errors);
386
-    }
387
-
388
-    // }}}
389
-    // {{{ popExpect()
390
-
391
-    /**
392
-     * This method pops one element off the expected error codes
393
-     * stack.
394
-     *
395
-     * @return array   the list of error codes that were popped
396
-     */
397
-    function popExpect()
398
-    {
399
-        return array_pop($this->_expected_errors);
400
-    }
401
-
402
-    // }}}
403
-    // {{{ _checkDelExpect()
404
-
405
-    /**
406
-     * This method checks unsets an error code if available
407
-     *
408
-     * @param mixed error code
409
-     * @return bool true if the error code was unset, false otherwise
410
-     * @access private
411
-     * @since PHP 4.3.0
412
-     */
413
-    function _checkDelExpect($error_code)
414
-    {
415
-        $deleted = false;
416
-
417
-        foreach ($this->_expected_errors AS $key => $error_array) {
418
-            if (in_array($error_code, $error_array)) {
419
-                unset($this->_expected_errors[$key][array_search($error_code, $error_array)]);
420
-                $deleted = true;
421
-            }
422
-
423
-            // clean up empty arrays
424
-            if (0 == count($this->_expected_errors[$key])) {
425
-                unset($this->_expected_errors[$key]);
426
-            }
427
-        }
428
-        return $deleted;
429
-    }
430
-
431
-    // }}}
432
-    // {{{ delExpect()
433
-
434
-    /**
435
-     * This method deletes all occurences of the specified element from
436
-     * the expected error codes stack.
437
-     *
438
-     * @param  mixed $error_code error code that should be deleted
439
-     * @return mixed list of error codes that were deleted or error
440
-     * @access public
441
-     * @since PHP 4.3.0
442
-     */
443
-    function delExpect($error_code)
444
-    {
445
-        $deleted = false;
446
-        if ((is_array($error_code) && (0 != count($error_code)))) {
447
-            // $error_code is a non-empty array here;
448
-            // we walk through it trying to unset all
449
-            // values
450
-            foreach($error_code as $key => $error) {
451
-                if ($this->_checkDelExpect($error)) {
452
-                    $deleted =  true;
453
-                } else {
454
-                    $deleted = false;
455
-                }
456
-            }
457
-            return $deleted ? true : PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME
458
-        } elseif (!empty($error_code)) {
459
-            // $error_code comes alone, trying to unset it
460
-            if ($this->_checkDelExpect($error_code)) {
461
-                return true;
462
-            } else {
463
-                return PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME
464
-            }
465
-        }
466
-
467
-        // $error_code is empty
468
-        return PEAR::raiseError("The expected error you submitted is empty"); // IMPROVE ME
469
-    }
470
-
471
-    // }}}
472
-    // {{{ raiseError()
473
-
474
-    /**
475
-     * This method is a wrapper that returns an instance of the
476
-     * configured error class with this object's default error
477
-     * handling applied.  If the $mode and $options parameters are not
478
-     * specified, the object's defaults are used.
479
-     *
480
-     * @param mixed $message a text error message or a PEAR error object
481
-     *
482
-     * @param int $code      a numeric error code (it is up to your class
483
-     *                  to define these if you want to use codes)
484
-     *
485
-     * @param int $mode      One of PEAR_ERROR_RETURN, PEAR_ERROR_PRINT,
486
-     *                  PEAR_ERROR_TRIGGER, PEAR_ERROR_DIE,
487
-     *                  PEAR_ERROR_CALLBACK, PEAR_ERROR_EXCEPTION.
488
-     *
489
-     * @param mixed $options If $mode is PEAR_ERROR_TRIGGER, this parameter
490
-     *                  specifies the PHP-internal error level (one of
491
-     *                  E_USER_NOTICE, E_USER_WARNING or E_USER_ERROR).
492
-     *                  If $mode is PEAR_ERROR_CALLBACK, this
493
-     *                  parameter specifies the callback function or
494
-     *                  method.  In other error modes this parameter
495
-     *                  is ignored.
496
-     *
497
-     * @param string $userinfo If you need to pass along for example debug
498
-     *                  information, this parameter is meant for that.
499
-     *
500
-     * @param string $error_class The returned error object will be
501
-     *                  instantiated from this class, if specified.
502
-     *
503
-     * @param bool $skipmsg If true, raiseError will only pass error codes,
504
-     *                  the error message parameter will be dropped.
505
-     *
506
-     * @access public
507
-     * @return object   a PEAR error object
508
-     * @see PEAR::setErrorHandling
509
-     * @since PHP 4.0.5
510
-     */
511
-    function &raiseError($message = null,
512
-                         $code = null,
513
-                         $mode = null,
514
-                         $options = null,
515
-                         $userinfo = null,
516
-                         $error_class = null,
517
-                         $skipmsg = false)
518
-    {
519
-        // The error is yet a PEAR error object
520
-        if (is_object($message)) {
521
-            $code        = $message->getCode();
522
-            $userinfo    = $message->getUserInfo();
523
-            $error_class = $message->getType();
524
-            $message->error_message_prefix = '';
525
-            $message     = $message->getMessage();
526
-        }
527
-
528
-        if (isset($this) && isset($this->_expected_errors) && sizeof($this->_expected_errors) > 0 && sizeof($exp = end($this->_expected_errors))) {
529
-            if ($exp[0] == "*" ||
530
-                (is_int(reset($exp)) && in_array($code, $exp)) ||
531
-                (is_string(reset($exp)) && in_array($message, $exp))) {
532
-                $mode = PEAR_ERROR_RETURN;
533
-            }
534
-        }
535
-
536
-        // No mode given, try global ones
537
-        if ($mode === null) {
538
-            // Class error handler
539
-            if (isset($this) && isset($this->_default_error_mode)) {
540
-                $mode    = $this->_default_error_mode;
541
-                $options = $this->_default_error_options;
542
-            // Global error handler
543
-            } elseif (isset($GLOBALS['_PEAR_default_error_mode'])) {
544
-                $mode    = $GLOBALS['_PEAR_default_error_mode'];
545
-                $options = $GLOBALS['_PEAR_default_error_options'];
546
-            }
547
-        }
548
-
549
-        if ($error_class !== null) {
550
-            $ec = $error_class;
551
-        } elseif (isset($this) && isset($this->_error_class)) {
552
-            $ec = $this->_error_class;
553
-        } else {
554
-            $ec = 'PEAR_Error';
555
-        }
556
-
557
-        if (intval(PHP_VERSION) < 5) {
558
-            // little non-eval hack to fix bug #12147
559
-            include 'PEAR/FixPHP5PEARWarnings.php';
560
-            return $a;
561
-        }
562
-
563
-        if ($skipmsg) {
564
-            $a = new $ec($code, $mode, $options, $userinfo);
565
-        } else {
566
-            $a = new $ec($message, $code, $mode, $options, $userinfo);
567
-        }
568
-
569
-        return $a;
570
-    }
571
-
572
-    // }}}
573
-    // {{{ throwError()
574
-
575
-    /**
576
-     * Simpler form of raiseError with fewer options.  In most cases
577
-     * message, code and userinfo are enough.
578
-     *
579
-     * @param string $message
580
-     *
581
-     */
582
-    function &throwError($message = null,
583
-                         $code = null,
584
-                         $userinfo = null)
585
-    {
586
-        if (isset($this) && is_a($this, 'PEAR')) {
587
-            $a = &$this->raiseError($message, $code, null, null, $userinfo);
588
-            return $a;
589
-        }
590
-
591
-        $a = &PEAR::raiseError($message, $code, null, null, $userinfo);
592
-        return $a;
593
-    }
594
-
595
-    // }}}
596
-    function staticPushErrorHandling($mode, $options = null)
597
-    {
598
-        $stack = &$GLOBALS['_PEAR_error_handler_stack'];
599
-        $def_mode    = &$GLOBALS['_PEAR_default_error_mode'];
600
-        $def_options = &$GLOBALS['_PEAR_default_error_options'];
601
-        $stack[] = array($def_mode, $def_options);
602
-        switch ($mode) {
603
-            case PEAR_ERROR_EXCEPTION:
604
-            case PEAR_ERROR_RETURN:
605
-            case PEAR_ERROR_PRINT:
606
-            case PEAR_ERROR_TRIGGER:
607
-            case PEAR_ERROR_DIE:
608
-            case null:
609
-                $def_mode = $mode;
610
-                $def_options = $options;
611
-                break;
612
-
613
-            case PEAR_ERROR_CALLBACK:
614
-                $def_mode = $mode;
615
-                // class/object method callback
616
-                if (is_callable($options)) {
617
-                    $def_options = $options;
618
-                } else {
619
-                    trigger_error("invalid error callback", E_USER_WARNING);
620
-                }
621
-                break;
622
-
623
-            default:
624
-                trigger_error("invalid error mode", E_USER_WARNING);
625
-                break;
626
-        }
627
-        $stack[] = array($mode, $options);
628
-        return true;
629
-    }
630
-
631
-    function staticPopErrorHandling()
632
-    {
633
-        $stack = &$GLOBALS['_PEAR_error_handler_stack'];
634
-        $setmode     = &$GLOBALS['_PEAR_default_error_mode'];
635
-        $setoptions  = &$GLOBALS['_PEAR_default_error_options'];
636
-        array_pop($stack);
637
-        list($mode, $options) = $stack[sizeof($stack) - 1];
638
-        array_pop($stack);
639
-        switch ($mode) {
640
-            case PEAR_ERROR_EXCEPTION:
641
-            case PEAR_ERROR_RETURN:
642
-            case PEAR_ERROR_PRINT:
643
-            case PEAR_ERROR_TRIGGER:
644
-            case PEAR_ERROR_DIE:
645
-            case null:
646
-                $setmode = $mode;
647
-                $setoptions = $options;
648
-                break;
649
-
650
-            case PEAR_ERROR_CALLBACK:
651
-                $setmode = $mode;
652
-                // class/object method callback
653
-                if (is_callable($options)) {
654
-                    $setoptions = $options;
655
-                } else {
656
-                    trigger_error("invalid error callback", E_USER_WARNING);
657
-                }
658
-                break;
659
-
660
-            default:
661
-                trigger_error("invalid error mode", E_USER_WARNING);
662
-                break;
663
-        }
664
-        return true;
665
-    }
666
-
667
-    // {{{ pushErrorHandling()
668
-
669
-    /**
670
-     * Push a new error handler on top of the error handler options stack. With this
671
-     * you can easily override the actual error handler for some code and restore
672
-     * it later with popErrorHandling.
673
-     *
674
-     * @param mixed $mode (same as setErrorHandling)
675
-     * @param mixed $options (same as setErrorHandling)
676
-     *
677
-     * @return bool Always true
678
-     *
679
-     * @see PEAR::setErrorHandling
680
-     */
681
-    function pushErrorHandling($mode, $options = null)
682
-    {
683
-        $stack = &$GLOBALS['_PEAR_error_handler_stack'];
684
-        if (isset($this) && is_a($this, 'PEAR')) {
685
-            $def_mode    = &$this->_default_error_mode;
686
-            $def_options = &$this->_default_error_options;
687
-        } else {
688
-            $def_mode    = &$GLOBALS['_PEAR_default_error_mode'];
689
-            $def_options = &$GLOBALS['_PEAR_default_error_options'];
690
-        }
691
-        $stack[] = array($def_mode, $def_options);
692
-
693
-        if (isset($this) && is_a($this, 'PEAR')) {
694
-            $this->setErrorHandling($mode, $options);
695
-        } else {
696
-            PEAR::setErrorHandling($mode, $options);
697
-        }
698
-        $stack[] = array($mode, $options);
699
-        return true;
700
-    }
701
-
702
-    // }}}
703
-    // {{{ popErrorHandling()
704
-
705
-    /**
706
-    * Pop the last error handler used
707
-    *
708
-    * @return bool Always true
709
-    *
710
-    * @see PEAR::pushErrorHandling
711
-    */
712
-    function popErrorHandling()
713
-    {
714
-        $stack = &$GLOBALS['_PEAR_error_handler_stack'];
715
-        array_pop($stack);
716
-        list($mode, $options) = $stack[sizeof($stack) - 1];
717
-        array_pop($stack);
718
-        if (isset($this) && is_a($this, 'PEAR')) {
719
-            $this->setErrorHandling($mode, $options);
720
-        } else {
721
-            PEAR::setErrorHandling($mode, $options);
722
-        }
723
-        return true;
724
-    }
725
-
726
-    // }}}
727
-    // {{{ loadExtension()
728
-
729
-    /**
730
-    * OS independant PHP extension load. Remember to take care
731
-    * on the correct extension name for case sensitive OSes.
732
-    *
733
-    * @param string $ext The extension name
734
-    * @return bool Success or not on the dl() call
735
-    */
736
-    function loadExtension($ext)
737
-    {
738
-        if (!extension_loaded($ext)) {
739
-            // if either returns true dl() will produce a FATAL error, stop that
740
-            if ((ini_get('enable_dl') != 1) || (ini_get('safe_mode') == 1)) {
741
-                return false;
742
-            }
743
-
744
-            if (OS_WINDOWS) {
745
-                $suffix = '.dll';
746
-            } elseif (PHP_OS == 'HP-UX') {
747
-                $suffix = '.sl';
748
-            } elseif (PHP_OS == 'AIX') {
749
-                $suffix = '.a';
750
-            } elseif (PHP_OS == 'OSX') {
751
-                $suffix = '.bundle';
752
-            } else {
753
-                $suffix = '.so';
754
-            }
755
-
756
-            return @dl('php_'.$ext.$suffix) || @dl($ext.$suffix);
757
-        }
758
-
759
-        return true;
760
-    }
761
-
762
-    // }}}
89
+	// {{{ properties
90
+
91
+	/**
92
+	 * Whether to enable internal debug messages.
93
+	 *
94
+	 * @var     bool
95
+	 * @access  private
96
+	 */
97
+	var $_debug = false;
98
+
99
+	/**
100
+	 * Default error mode for this object.
101
+	 *
102
+	 * @var     int
103
+	 * @access  private
104
+	 */
105
+	var $_default_error_mode = null;
106
+
107
+	/**
108
+	 * Default error options used for this object when error mode
109
+	 * is PEAR_ERROR_TRIGGER.
110
+	 *
111
+	 * @var     int
112
+	 * @access  private
113
+	 */
114
+	var $_default_error_options = null;
115
+
116
+	/**
117
+	 * Default error handler (callback) for this object, if error mode is
118
+	 * PEAR_ERROR_CALLBACK.
119
+	 *
120
+	 * @var     string
121
+	 * @access  private
122
+	 */
123
+	var $_default_error_handler = '';
124
+
125
+	/**
126
+	 * Which class to use for error objects.
127
+	 *
128
+	 * @var     string
129
+	 * @access  private
130
+	 */
131
+	var $_error_class = 'PEAR_Error';
132
+
133
+	/**
134
+	 * An array of expected errors.
135
+	 *
136
+	 * @var     array
137
+	 * @access  private
138
+	 */
139
+	var $_expected_errors = array();
140
+
141
+	// }}}
142
+
143
+	// {{{ constructor
144
+
145
+	/**
146
+	 * Constructor.  Registers this object in
147
+	 * $_PEAR_destructor_object_list for destructor emulation if a
148
+	 * destructor object exists.
149
+	 *
150
+	 * @param string $error_class  (optional) which class to use for
151
+	 *        error objects, defaults to PEAR_Error.
152
+	 * @access public
153
+	 * @return void
154
+	 */
155
+	function PEAR($error_class = null)
156
+	{
157
+		$classname = strtolower(get_class($this));
158
+		if ($this->_debug) {
159
+			print "PEAR constructor called, class=$classname\n";
160
+		}
161
+		if ($error_class !== null) {
162
+			$this->_error_class = $error_class;
163
+		}
164
+		while ($classname && strcasecmp($classname, "pear")) {
165
+			$destructor = "_$classname";
166
+			if (method_exists($this, $destructor)) {
167
+				global $_PEAR_destructor_object_list;
168
+				$_PEAR_destructor_object_list[] = &$this;
169
+				if (!isset($GLOBALS['_PEAR_SHUTDOWN_REGISTERED'])) {
170
+					register_shutdown_function("_PEAR_call_destructors");
171
+					$GLOBALS['_PEAR_SHUTDOWN_REGISTERED'] = true;
172
+				}
173
+				break;
174
+			} else {
175
+				$classname = get_parent_class($classname);
176
+			}
177
+		}
178
+	}
179
+
180
+	// }}}
181
+	// {{{ destructor
182
+
183
+	/**
184
+	 * Destructor (the emulated type of...).  Does nothing right now,
185
+	 * but is included for forward compatibility, so subclass
186
+	 * destructors should always call it.
187
+	 *
188
+	 * See the note in the class desciption about output from
189
+	 * destructors.
190
+	 *
191
+	 * @access public
192
+	 * @return void
193
+	 */
194
+	function _PEAR() {
195
+		if ($this->_debug) {
196
+			printf("PEAR destructor called, class=%s\n", strtolower(get_class($this)));
197
+		}
198
+	}
199
+
200
+	// }}}
201
+	// {{{ getStaticProperty()
202
+
203
+	/**
204
+	 * If you have a class that's mostly/entirely static, and you need static
205
+	 * properties, you can use this method to simulate them. Eg. in your method(s)
206
+	 * do this: $myVar = &PEAR::getStaticProperty('myclass', 'myVar');
207
+	 * You MUST use a reference, or they will not persist!
208
+	 *
209
+	 * @access public
210
+	 * @param  string $class  The calling classname, to prevent clashes
211
+	 * @param  string $var    The variable to retrieve.
212
+	 * @return mixed   A reference to the variable. If not set it will be
213
+	 *                 auto initialised to NULL.
214
+	 */
215
+	function &getStaticProperty($class, $var)
216
+	{
217
+		static $properties;
218
+		if (!isset($properties[$class])) {
219
+			$properties[$class] = array();
220
+		}
221
+
222
+		if (!array_key_exists($var, $properties[$class])) {
223
+			$properties[$class][$var] = null;
224
+		}
225
+
226
+		return $properties[$class][$var];
227
+	}
228
+
229
+	// }}}
230
+	// {{{ registerShutdownFunc()
231
+
232
+	/**
233
+	 * Use this function to register a shutdown method for static
234
+	 * classes.
235
+	 *
236
+	 * @access public
237
+	 * @param  mixed $func  The function name (or array of class/method) to call
238
+	 * @param  mixed $args  The arguments to pass to the function
239
+	 * @return void
240
+	 */
241
+	function registerShutdownFunc($func, $args = array())
242
+	{
243
+		// if we are called statically, there is a potential
244
+		// that no shutdown func is registered.  Bug #6445
245
+		if (!isset($GLOBALS['_PEAR_SHUTDOWN_REGISTERED'])) {
246
+			register_shutdown_function("_PEAR_call_destructors");
247
+			$GLOBALS['_PEAR_SHUTDOWN_REGISTERED'] = true;
248
+		}
249
+		$GLOBALS['_PEAR_shutdown_funcs'][] = array($func, $args);
250
+	}
251
+
252
+	// }}}
253
+	// {{{ isError()
254
+
255
+	/**
256
+	 * Tell whether a value is a PEAR error.
257
+	 *
258
+	 * @param   mixed $data   the value to test
259
+	 * @param   int   $code   if $data is an error object, return true
260
+	 *                        only if $code is a string and
261
+	 *                        $obj->getMessage() == $code or
262
+	 *                        $code is an integer and $obj->getCode() == $code
263
+	 * @access  public
264
+	 * @return  bool    true if parameter is an error
265
+	 */
266
+	function isError($data, $code = null)
267
+	{
268
+		if (!is_a($data, 'PEAR_Error')) {
269
+			return false;
270
+		}
271
+
272
+		if (is_null($code)) {
273
+			return true;
274
+		} elseif (is_string($code)) {
275
+			return $data->getMessage() == $code;
276
+		}
277
+
278
+		return $data->getCode() == $code;
279
+	}
280
+
281
+	// }}}
282
+	// {{{ setErrorHandling()
283
+
284
+	/**
285
+	 * Sets how errors generated by this object should be handled.
286
+	 * Can be invoked both in objects and statically.  If called
287
+	 * statically, setErrorHandling sets the default behaviour for all
288
+	 * PEAR objects.  If called in an object, setErrorHandling sets
289
+	 * the default behaviour for that object.
290
+	 *
291
+	 * @param int $mode
292
+	 *        One of PEAR_ERROR_RETURN, PEAR_ERROR_PRINT,
293
+	 *        PEAR_ERROR_TRIGGER, PEAR_ERROR_DIE,
294
+	 *        PEAR_ERROR_CALLBACK or PEAR_ERROR_EXCEPTION.
295
+	 *
296
+	 * @param mixed $options
297
+	 *        When $mode is PEAR_ERROR_TRIGGER, this is the error level (one
298
+	 *        of E_USER_NOTICE, E_USER_WARNING or E_USER_ERROR).
299
+	 *
300
+	 *        When $mode is PEAR_ERROR_CALLBACK, this parameter is expected
301
+	 *        to be the callback function or method.  A callback
302
+	 *        function is a string with the name of the function, a
303
+	 *        callback method is an array of two elements: the element
304
+	 *        at index 0 is the object, and the element at index 1 is
305
+	 *        the name of the method to call in the object.
306
+	 *
307
+	 *        When $mode is PEAR_ERROR_PRINT or PEAR_ERROR_DIE, this is
308
+	 *        a printf format string used when printing the error
309
+	 *        message.
310
+	 *
311
+	 * @access public
312
+	 * @return void
313
+	 * @see PEAR_ERROR_RETURN
314
+	 * @see PEAR_ERROR_PRINT
315
+	 * @see PEAR_ERROR_TRIGGER
316
+	 * @see PEAR_ERROR_DIE
317
+	 * @see PEAR_ERROR_CALLBACK
318
+	 * @see PEAR_ERROR_EXCEPTION
319
+	 *
320
+	 * @since PHP 4.0.5
321
+	 */
322
+
323
+	function setErrorHandling($mode = null, $options = null)
324
+	{
325
+		if (isset($this) && is_a($this, 'PEAR')) {
326
+			$setmode     = &$this->_default_error_mode;
327
+			$setoptions  = &$this->_default_error_options;
328
+		} else {
329
+			$setmode     = &$GLOBALS['_PEAR_default_error_mode'];
330
+			$setoptions  = &$GLOBALS['_PEAR_default_error_options'];
331
+		}
332
+
333
+		switch ($mode) {
334
+			case PEAR_ERROR_EXCEPTION:
335
+			case PEAR_ERROR_RETURN:
336
+			case PEAR_ERROR_PRINT:
337
+			case PEAR_ERROR_TRIGGER:
338
+			case PEAR_ERROR_DIE:
339
+			case null:
340
+				$setmode = $mode;
341
+				$setoptions = $options;
342
+				break;
343
+
344
+			case PEAR_ERROR_CALLBACK:
345
+				$setmode = $mode;
346
+				// class/object method callback
347
+				if (is_callable($options)) {
348
+					$setoptions = $options;
349
+				} else {
350
+					trigger_error("invalid error callback", E_USER_WARNING);
351
+				}
352
+				break;
353
+
354
+			default:
355
+				trigger_error("invalid error mode", E_USER_WARNING);
356
+				break;
357
+		}
358
+	}
359
+
360
+	// }}}
361
+	// {{{ expectError()
362
+
363
+	/**
364
+	 * This method is used to tell which errors you expect to get.
365
+	 * Expected errors are always returned with error mode
366
+	 * PEAR_ERROR_RETURN.  Expected error codes are stored in a stack,
367
+	 * and this method pushes a new element onto it.  The list of
368
+	 * expected errors are in effect until they are popped off the
369
+	 * stack with the popExpect() method.
370
+	 *
371
+	 * Note that this method can not be called statically
372
+	 *
373
+	 * @param mixed $code a single error code or an array of error codes to expect
374
+	 *
375
+	 * @return int     the new depth of the "expected errors" stack
376
+	 * @access public
377
+	 */
378
+	function expectError($code = '*')
379
+	{
380
+		if (is_array($code)) {
381
+			array_push($this->_expected_errors, $code);
382
+		} else {
383
+			array_push($this->_expected_errors, array($code));
384
+		}
385
+		return sizeof($this->_expected_errors);
386
+	}
387
+
388
+	// }}}
389
+	// {{{ popExpect()
390
+
391
+	/**
392
+	 * This method pops one element off the expected error codes
393
+	 * stack.
394
+	 *
395
+	 * @return array   the list of error codes that were popped
396
+	 */
397
+	function popExpect()
398
+	{
399
+		return array_pop($this->_expected_errors);
400
+	}
401
+
402
+	// }}}
403
+	// {{{ _checkDelExpect()
404
+
405
+	/**
406
+	 * This method checks unsets an error code if available
407
+	 *
408
+	 * @param mixed error code
409
+	 * @return bool true if the error code was unset, false otherwise
410
+	 * @access private
411
+	 * @since PHP 4.3.0
412
+	 */
413
+	function _checkDelExpect($error_code)
414
+	{
415
+		$deleted = false;
416
+
417
+		foreach ($this->_expected_errors AS $key => $error_array) {
418
+			if (in_array($error_code, $error_array)) {
419
+				unset($this->_expected_errors[$key][array_search($error_code, $error_array)]);
420
+				$deleted = true;
421
+			}
422
+
423
+			// clean up empty arrays
424
+			if (0 == count($this->_expected_errors[$key])) {
425
+				unset($this->_expected_errors[$key]);
426
+			}
427
+		}
428
+		return $deleted;
429
+	}
430
+
431
+	// }}}
432
+	// {{{ delExpect()
433
+
434
+	/**
435
+	 * This method deletes all occurences of the specified element from
436
+	 * the expected error codes stack.
437
+	 *
438
+	 * @param  mixed $error_code error code that should be deleted
439
+	 * @return mixed list of error codes that were deleted or error
440
+	 * @access public
441
+	 * @since PHP 4.3.0
442
+	 */
443
+	function delExpect($error_code)
444
+	{
445
+		$deleted = false;
446
+		if ((is_array($error_code) && (0 != count($error_code)))) {
447
+			// $error_code is a non-empty array here;
448
+			// we walk through it trying to unset all
449
+			// values
450
+			foreach($error_code as $key => $error) {
451
+				if ($this->_checkDelExpect($error)) {
452
+					$deleted =  true;
453
+				} else {
454
+					$deleted = false;
455
+				}
456
+			}
457
+			return $deleted ? true : PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME
458
+		} elseif (!empty($error_code)) {
459
+			// $error_code comes alone, trying to unset it
460
+			if ($this->_checkDelExpect($error_code)) {
461
+				return true;
462
+			} else {
463
+				return PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME
464
+			}
465
+		}
466
+
467
+		// $error_code is empty
468
+		return PEAR::raiseError("The expected error you submitted is empty"); // IMPROVE ME
469
+	}
470
+
471
+	// }}}
472
+	// {{{ raiseError()
473
+
474
+	/**
475
+	 * This method is a wrapper that returns an instance of the
476
+	 * configured error class with this object's default error
477
+	 * handling applied.  If the $mode and $options parameters are not
478
+	 * specified, the object's defaults are used.
479
+	 *
480
+	 * @param mixed $message a text error message or a PEAR error object
481
+	 *
482
+	 * @param int $code      a numeric error code (it is up to your class
483
+	 *                  to define these if you want to use codes)
484
+	 *
485
+	 * @param int $mode      One of PEAR_ERROR_RETURN, PEAR_ERROR_PRINT,
486
+	 *                  PEAR_ERROR_TRIGGER, PEAR_ERROR_DIE,
487
+	 *                  PEAR_ERROR_CALLBACK, PEAR_ERROR_EXCEPTION.
488
+	 *
489
+	 * @param mixed $options If $mode is PEAR_ERROR_TRIGGER, this parameter
490
+	 *                  specifies the PHP-internal error level (one of
491
+	 *                  E_USER_NOTICE, E_USER_WARNING or E_USER_ERROR).
492
+	 *                  If $mode is PEAR_ERROR_CALLBACK, this
493
+	 *                  parameter specifies the callback function or
494
+	 *                  method.  In other error modes this parameter
495
+	 *                  is ignored.
496
+	 *
497
+	 * @param string $userinfo If you need to pass along for example debug
498
+	 *                  information, this parameter is meant for that.
499
+	 *
500
+	 * @param string $error_class The returned error object will be
501
+	 *                  instantiated from this class, if specified.
502
+	 *
503
+	 * @param bool $skipmsg If true, raiseError will only pass error codes,
504
+	 *                  the error message parameter will be dropped.
505
+	 *
506
+	 * @access public
507
+	 * @return object   a PEAR error object
508
+	 * @see PEAR::setErrorHandling
509
+	 * @since PHP 4.0.5
510
+	 */
511
+	function &raiseError($message = null,
512
+						 $code = null,
513
+						 $mode = null,
514
+						 $options = null,
515
+						 $userinfo = null,
516
+						 $error_class = null,
517
+						 $skipmsg = false)
518
+	{
519
+		// The error is yet a PEAR error object
520
+		if (is_object($message)) {
521
+			$code        = $message->getCode();
522
+			$userinfo    = $message->getUserInfo();
523
+			$error_class = $message->getType();
524
+			$message->error_message_prefix = '';
525
+			$message     = $message->getMessage();
526
+		}
527
+
528
+		if (isset($this) && isset($this->_expected_errors) && sizeof($this->_expected_errors) > 0 && sizeof($exp = end($this->_expected_errors))) {
529
+			if ($exp[0] == "*" ||
530
+				(is_int(reset($exp)) && in_array($code, $exp)) ||
531
+				(is_string(reset($exp)) && in_array($message, $exp))) {
532
+				$mode = PEAR_ERROR_RETURN;
533
+			}
534
+		}
535
+
536
+		// No mode given, try global ones
537
+		if ($mode === null) {
538
+			// Class error handler
539
+			if (isset($this) && isset($this->_default_error_mode)) {
540
+				$mode    = $this->_default_error_mode;
541
+				$options = $this->_default_error_options;
542
+			// Global error handler
543
+			} elseif (isset($GLOBALS['_PEAR_default_error_mode'])) {
544
+				$mode    = $GLOBALS['_PEAR_default_error_mode'];
545
+				$options = $GLOBALS['_PEAR_default_error_options'];
546
+			}
547
+		}
548
+
549
+		if ($error_class !== null) {
550
+			$ec = $error_class;
551
+		} elseif (isset($this) && isset($this->_error_class)) {
552
+			$ec = $this->_error_class;
553
+		} else {
554
+			$ec = 'PEAR_Error';
555
+		}
556
+
557
+		if (intval(PHP_VERSION) < 5) {
558
+			// little non-eval hack to fix bug #12147
559
+			include 'PEAR/FixPHP5PEARWarnings.php';
560
+			return $a;
561
+		}
562
+
563
+		if ($skipmsg) {
564
+			$a = new $ec($code, $mode, $options, $userinfo);
565
+		} else {
566
+			$a = new $ec($message, $code, $mode, $options, $userinfo);
567
+		}
568
+
569
+		return $a;
570
+	}
571
+
572
+	// }}}
573
+	// {{{ throwError()
574
+
575
+	/**
576
+	 * Simpler form of raiseError with fewer options.  In most cases
577
+	 * message, code and userinfo are enough.
578
+	 *
579
+	 * @param string $message
580
+	 *
581
+	 */
582
+	function &throwError($message = null,
583
+						 $code = null,
584
+						 $userinfo = null)
585
+	{
586
+		if (isset($this) && is_a($this, 'PEAR')) {
587
+			$a = &$this->raiseError($message, $code, null, null, $userinfo);
588
+			return $a;
589
+		}
590
+
591
+		$a = &PEAR::raiseError($message, $code, null, null, $userinfo);
592
+		return $a;
593
+	}
594
+
595
+	// }}}
596
+	function staticPushErrorHandling($mode, $options = null)
597
+	{
598
+		$stack = &$GLOBALS['_PEAR_error_handler_stack'];
599
+		$def_mode    = &$GLOBALS['_PEAR_default_error_mode'];
600
+		$def_options = &$GLOBALS['_PEAR_default_error_options'];
601
+		$stack[] = array($def_mode, $def_options);
602
+		switch ($mode) {
603
+			case PEAR_ERROR_EXCEPTION:
604
+			case PEAR_ERROR_RETURN:
605
+			case PEAR_ERROR_PRINT:
606
+			case PEAR_ERROR_TRIGGER:
607
+			case PEAR_ERROR_DIE:
608
+			case null:
609
+				$def_mode = $mode;
610
+				$def_options = $options;
611
+				break;
612
+
613
+			case PEAR_ERROR_CALLBACK:
614
+				$def_mode = $mode;
615
+				// class/object method callback
616
+				if (is_callable($options)) {
617
+					$def_options = $options;
618
+				} else {
619
+					trigger_error("invalid error callback", E_USER_WARNING);
620
+				}
621
+				break;
622
+
623
+			default:
624
+				trigger_error("invalid error mode", E_USER_WARNING);
625
+				break;
626
+		}
627
+		$stack[] = array($mode, $options);
628
+		return true;
629
+	}
630
+
631
+	function staticPopErrorHandling()
632
+	{
633
+		$stack = &$GLOBALS['_PEAR_error_handler_stack'];
634
+		$setmode     = &$GLOBALS['_PEAR_default_error_mode'];
635
+		$setoptions  = &$GLOBALS['_PEAR_default_error_options'];
636
+		array_pop($stack);
637
+		list($mode, $options) = $stack[sizeof($stack) - 1];
638
+		array_pop($stack);
639
+		switch ($mode) {
640
+			case PEAR_ERROR_EXCEPTION:
641
+			case PEAR_ERROR_RETURN:
642
+			case PEAR_ERROR_PRINT:
643
+			case PEAR_ERROR_TRIGGER:
644
+			case PEAR_ERROR_DIE:
645
+			case null:
646
+				$setmode = $mode;
647
+				$setoptions = $options;
648
+				break;
649
+
650
+			case PEAR_ERROR_CALLBACK:
651
+				$setmode = $mode;
652
+				// class/object method callback
653
+				if (is_callable($options)) {
654
+					$setoptions = $options;
655
+				} else {
656
+					trigger_error("invalid error callback", E_USER_WARNING);
657
+				}
658
+				break;
659
+
660
+			default:
661
+				trigger_error("invalid error mode", E_USER_WARNING);
662
+				break;
663
+		}
664
+		return true;
665
+	}
666
+
667
+	// {{{ pushErrorHandling()
668
+
669
+	/**
670
+	 * Push a new error handler on top of the error handler options stack. With this
671
+	 * you can easily override the actual error handler for some code and restore
672
+	 * it later with popErrorHandling.
673
+	 *
674
+	 * @param mixed $mode (same as setErrorHandling)
675
+	 * @param mixed $options (same as setErrorHandling)
676
+	 *
677
+	 * @return bool Always true
678
+	 *
679
+	 * @see PEAR::setErrorHandling
680
+	 */
681
+	function pushErrorHandling($mode, $options = null)
682
+	{
683
+		$stack = &$GLOBALS['_PEAR_error_handler_stack'];
684
+		if (isset($this) && is_a($this, 'PEAR')) {
685
+			$def_mode    = &$this->_default_error_mode;
686
+			$def_options = &$this->_default_error_options;
687
+		} else {
688
+			$def_mode    = &$GLOBALS['_PEAR_default_error_mode'];
689
+			$def_options = &$GLOBALS['_PEAR_default_error_options'];
690
+		}
691
+		$stack[] = array($def_mode, $def_options);
692
+
693
+		if (isset($this) && is_a($this, 'PEAR')) {
694
+			$this->setErrorHandling($mode, $options);
695
+		} else {
696
+			PEAR::setErrorHandling($mode, $options);
697
+		}
698
+		$stack[] = array($mode, $options);
699
+		return true;
700
+	}
701
+
702
+	// }}}
703
+	// {{{ popErrorHandling()
704
+
705
+	/**
706
+	 * Pop the last error handler used
707
+	 *
708
+	 * @return bool Always true
709
+	 *
710
+	 * @see PEAR::pushErrorHandling
711
+	 */
712
+	function popErrorHandling()
713
+	{
714
+		$stack = &$GLOBALS['_PEAR_error_handler_stack'];
715
+		array_pop($stack);
716
+		list($mode, $options) = $stack[sizeof($stack) - 1];
717
+		array_pop($stack);
718
+		if (isset($this) && is_a($this, 'PEAR')) {
719
+			$this->setErrorHandling($mode, $options);
720
+		} else {
721
+			PEAR::setErrorHandling($mode, $options);
722
+		}
723
+		return true;
724
+	}
725
+
726
+	// }}}
727
+	// {{{ loadExtension()
728
+
729
+	/**
730
+	 * OS independant PHP extension load. Remember to take care
731
+	 * on the correct extension name for case sensitive OSes.
732
+	 *
733
+	 * @param string $ext The extension name
734
+	 * @return bool Success or not on the dl() call
735
+	 */
736
+	function loadExtension($ext)
737
+	{
738
+		if (!extension_loaded($ext)) {
739
+			// if either returns true dl() will produce a FATAL error, stop that
740
+			if ((ini_get('enable_dl') != 1) || (ini_get('safe_mode') == 1)) {
741
+				return false;
742
+			}
743
+
744
+			if (OS_WINDOWS) {
745
+				$suffix = '.dll';
746
+			} elseif (PHP_OS == 'HP-UX') {
747
+				$suffix = '.sl';
748
+			} elseif (PHP_OS == 'AIX') {
749
+				$suffix = '.a';
750
+			} elseif (PHP_OS == 'OSX') {
751
+				$suffix = '.bundle';
752
+			} else {
753
+				$suffix = '.so';
754
+			}
755
+
756
+			return @dl('php_'.$ext.$suffix) || @dl($ext.$suffix);
757
+		}
758
+
759
+		return true;
760
+	}
761
+
762
+	// }}}
763 763
 }
764 764
 
765 765
 if (PEAR_ZE2) {
766
-    include_once 'PEAR5.php';
766
+	include_once 'PEAR5.php';
767 767
 }
768 768
 
769 769
 // {{{ _PEAR_call_destructors()
770 770
 
771 771
 function _PEAR_call_destructors()
772 772
 {
773
-    global $_PEAR_destructor_object_list;
774
-    if (is_array($_PEAR_destructor_object_list) &&
775
-        sizeof($_PEAR_destructor_object_list))
776
-    {
777
-        reset($_PEAR_destructor_object_list);
778
-        if (PEAR_ZE2) {
779
-            $destructLifoExists = PEAR5::getStaticProperty('PEAR', 'destructlifo');
780
-        } else {
781
-            $destructLifoExists = PEAR::getStaticProperty('PEAR', 'destructlifo');
782
-        }
783
-
784
-        if ($destructLifoExists) {
785
-            $_PEAR_destructor_object_list = array_reverse($_PEAR_destructor_object_list);
786
-        }
787
-
788
-        while (list($k, $objref) = each($_PEAR_destructor_object_list)) {
789
-            $classname = get_class($objref);
790
-            while ($classname) {
791
-                $destructor = "_$classname";
792
-                if (method_exists($objref, $destructor)) {
793
-                    $objref->$destructor();
794
-                    break;
795
-                } else {
796
-                    $classname = get_parent_class($classname);
797
-                }
798
-            }
799
-        }
800
-        // Empty the object list to ensure that destructors are
801
-        // not called more than once.
802
-        $_PEAR_destructor_object_list = array();
803
-    }
804
-
805
-    // Now call the shutdown functions
806
-    if (isset($GLOBALS['_PEAR_shutdown_funcs']) AND is_array($GLOBALS['_PEAR_shutdown_funcs']) AND !empty($GLOBALS['_PEAR_shutdown_funcs'])) {
807
-        foreach ($GLOBALS['_PEAR_shutdown_funcs'] as $value) {
808
-            call_user_func_array($value[0], $value[1]);
809
-        }
810
-    }
773
+	global $_PEAR_destructor_object_list;
774
+	if (is_array($_PEAR_destructor_object_list) &&
775
+		sizeof($_PEAR_destructor_object_list))
776
+	{
777
+		reset($_PEAR_destructor_object_list);
778
+		if (PEAR_ZE2) {
779
+			$destructLifoExists = PEAR5::getStaticProperty('PEAR', 'destructlifo');
780
+		} else {
781
+			$destructLifoExists = PEAR::getStaticProperty('PEAR', 'destructlifo');
782
+		}
783
+
784
+		if ($destructLifoExists) {
785
+			$_PEAR_destructor_object_list = array_reverse($_PEAR_destructor_object_list);
786
+		}
787
+
788
+		while (list($k, $objref) = each($_PEAR_destructor_object_list)) {
789
+			$classname = get_class($objref);
790
+			while ($classname) {
791
+				$destructor = "_$classname";
792
+				if (method_exists($objref, $destructor)) {
793
+					$objref->$destructor();
794
+					break;
795
+				} else {
796
+					$classname = get_parent_class($classname);
797
+				}
798
+			}
799
+		}
800
+		// Empty the object list to ensure that destructors are
801
+		// not called more than once.
802
+		$_PEAR_destructor_object_list = array();
803
+	}
804
+
805
+	// Now call the shutdown functions
806
+	if (isset($GLOBALS['_PEAR_shutdown_funcs']) AND is_array($GLOBALS['_PEAR_shutdown_funcs']) AND !empty($GLOBALS['_PEAR_shutdown_funcs'])) {
807
+		foreach ($GLOBALS['_PEAR_shutdown_funcs'] as $value) {
808
+			call_user_func_array($value[0], $value[1]);
809
+		}
810
+	}
811 811
 }
812 812
 
813 813
 // }}}
@@ -830,302 +830,302 @@  discard block
 block discarded – undo
830 830
  */
831 831
 class PEAR_Error
832 832
 {
833
-    // {{{ properties
834
-
835
-    var $error_message_prefix = '';
836
-    var $mode                 = PEAR_ERROR_RETURN;
837
-    var $level                = E_USER_NOTICE;
838
-    var $code                 = -1;
839
-    var $message              = '';
840
-    var $userinfo             = '';
841
-    var $backtrace            = null;
842
-
843
-    // }}}
844
-    // {{{ constructor
845
-
846
-    /**
847
-     * PEAR_Error constructor
848
-     *
849
-     * @param string $message  message
850
-     *
851
-     * @param int $code     (optional) error code
852
-     *
853
-     * @param int $mode     (optional) error mode, one of: PEAR_ERROR_RETURN,
854
-     * PEAR_ERROR_PRINT, PEAR_ERROR_DIE, PEAR_ERROR_TRIGGER,
855
-     * PEAR_ERROR_CALLBACK or PEAR_ERROR_EXCEPTION
856
-     *
857
-     * @param mixed $options   (optional) error level, _OR_ in the case of
858
-     * PEAR_ERROR_CALLBACK, the callback function or object/method
859
-     * tuple.
860
-     *
861
-     * @param string $userinfo (optional) additional user/debug info
862
-     *
863
-     * @access public
864
-     *
865
-     */
866
-    function PEAR_Error($message = 'unknown error', $code = null,
867
-                        $mode = null, $options = null, $userinfo = null)
868
-    {
869
-        if ($mode === null) {
870
-            $mode = PEAR_ERROR_RETURN;
871
-        }
872
-        $this->message   = $message;
873
-        $this->code      = $code;
874
-        $this->mode      = $mode;
875
-        $this->userinfo  = $userinfo;
876
-
877
-        if (PEAR_ZE2) {
878
-            $skiptrace = PEAR5::getStaticProperty('PEAR_Error', 'skiptrace');
879
-        } else {
880
-            $skiptrace = PEAR::getStaticProperty('PEAR_Error', 'skiptrace');
881
-        }
882
-
883
-        if (!$skiptrace) {
884
-            $this->backtrace = debug_backtrace();
885
-            if (isset($this->backtrace[0]) && isset($this->backtrace[0]['object'])) {
886
-                unset($this->backtrace[0]['object']);
887
-            }
888
-        }
889
-
890
-        if ($mode & PEAR_ERROR_CALLBACK) {
891
-            $this->level = E_USER_NOTICE;
892
-            $this->callback = $options;
893
-        } else {
894
-            if ($options === null) {
895
-                $options = E_USER_NOTICE;
896
-            }
897
-
898
-            $this->level = $options;
899
-            $this->callback = null;
900
-        }
901
-
902
-        if ($this->mode & PEAR_ERROR_PRINT) {
903
-            if (is_null($options) || is_int($options)) {
904
-                $format = "%s";
905
-            } else {
906
-                $format = $options;
907
-            }
908
-
909
-            printf($format, $this->getMessage());
910
-        }
911
-
912
-        if ($this->mode & PEAR_ERROR_TRIGGER) {
913
-            trigger_error($this->getMessage(), $this->level);
914
-        }
915
-
916
-        if ($this->mode & PEAR_ERROR_DIE) {
917
-            $msg = $this->getMessage();
918
-            if (is_null($options) || is_int($options)) {
919
-                $format = "%s";
920
-                if (substr($msg, -1) != "\n") {
921
-                    $msg .= "\n";
922
-                }
923
-            } else {
924
-                $format = $options;
925
-            }
926
-            die(sprintf($format, $msg));
927
-        }
928
-
929
-        if ($this->mode & PEAR_ERROR_CALLBACK) {
930
-            if (is_callable($this->callback)) {
931
-                call_user_func($this->callback, $this);
932
-            }
933
-        }
934
-
935
-        if ($this->mode & PEAR_ERROR_EXCEPTION) {
936
-            trigger_error("PEAR_ERROR_EXCEPTION is obsolete, use class PEAR_Exception for exceptions", E_USER_WARNING);
937
-            eval('$e = new Exception($this->message, $this->code);throw($e);');
938
-        }
939
-    }
940
-
941
-    // }}}
942
-    // {{{ getMode()
943
-
944
-    /**
945
-     * Get the error mode from an error object.
946
-     *
947
-     * @return int error mode
948
-     * @access public
949
-     */
950
-    function getMode() {
951
-        return $this->mode;
952
-    }
953
-
954
-    // }}}
955
-    // {{{ getCallback()
956
-
957
-    /**
958
-     * Get the callback function/method from an error object.
959
-     *
960
-     * @return mixed callback function or object/method array
961
-     * @access public
962
-     */
963
-    function getCallback() {
964
-        return $this->callback;
965
-    }
966
-
967
-    // }}}
968
-    // {{{ getMessage()
969
-
970
-
971
-    /**
972
-     * Get the error message from an error object.
973
-     *
974
-     * @return  string  full error message
975
-     * @access public
976
-     */
977
-    function getMessage()
978
-    {
979
-        return ($this->error_message_prefix . $this->message);
980
-    }
981
-
982
-
983
-    // }}}
984
-    // {{{ getCode()
985
-
986
-    /**
987
-     * Get error code from an error object
988
-     *
989
-     * @return int error code
990
-     * @access public
991
-     */
992
-     function getCode()
993
-     {
994
-        return $this->code;
995
-     }
996
-
997
-    // }}}
998
-    // {{{ getType()
999
-
1000
-    /**
1001
-     * Get the name of this error/exception.
1002
-     *
1003
-     * @return string error/exception name (type)
1004
-     * @access public
1005
-     */
1006
-    function getType()
1007
-    {
1008
-        return get_class($this);
1009
-    }
1010
-
1011
-    // }}}
1012
-    // {{{ getUserInfo()
1013
-
1014
-    /**
1015
-     * Get additional user-supplied information.
1016
-     *
1017
-     * @return string user-supplied information
1018
-     * @access public
1019
-     */
1020
-    function getUserInfo()
1021
-    {
1022
-        return $this->userinfo;
1023
-    }
1024
-
1025
-    // }}}
1026
-    // {{{ getDebugInfo()
1027
-
1028
-    /**
1029
-     * Get additional debug information supplied by the application.
1030
-     *
1031
-     * @return string debug information
1032
-     * @access public
1033
-     */
1034
-    function getDebugInfo()
1035
-    {
1036
-        return $this->getUserInfo();
1037
-    }
1038
-
1039
-    // }}}
1040
-    // {{{ getBacktrace()
1041
-
1042
-    /**
1043
-     * Get the call backtrace from where the error was generated.
1044
-     * Supported with PHP 4.3.0 or newer.
1045
-     *
1046
-     * @param int $frame (optional) what frame to fetch
1047
-     * @return array Backtrace, or NULL if not available.
1048
-     * @access public
1049
-     */
1050
-    function getBacktrace($frame = null)
1051
-    {
1052
-        if (defined('PEAR_IGNORE_BACKTRACE')) {
1053
-            return null;
1054
-        }
1055
-        if ($frame === null) {
1056
-            return $this->backtrace;
1057
-        }
1058
-        return $this->backtrace[$frame];
1059
-    }
1060
-
1061
-    // }}}
1062
-    // {{{ addUserInfo()
1063
-
1064
-    function addUserInfo($info)
1065
-    {
1066
-        if (empty($this->userinfo)) {
1067
-            $this->userinfo = $info;
1068
-        } else {
1069
-            $this->userinfo .= " ** $info";
1070
-        }
1071
-    }
1072
-
1073
-    // }}}
1074
-    // {{{ toString()
1075
-    function __toString()
1076
-    {
1077
-        return $this->getMessage();
1078
-    }
1079
-    // }}}
1080
-    // {{{ toString()
1081
-
1082
-    /**
1083
-     * Make a string representation of this object.
1084
-     *
1085
-     * @return string a string with an object summary
1086
-     * @access public
1087
-     */
1088
-    function toString() {
1089
-        $modes = array();
1090
-        $levels = array(E_USER_NOTICE  => 'notice',
1091
-                        E_USER_WARNING => 'warning',
1092
-                        E_USER_ERROR   => 'error');
1093
-        if ($this->mode & PEAR_ERROR_CALLBACK) {
1094
-            if (is_array($this->callback)) {
1095
-                $callback = (is_object($this->callback[0]) ?
1096
-                    strtolower(get_class($this->callback[0])) :
1097
-                    $this->callback[0]) . '::' .
1098
-                    $this->callback[1];
1099
-            } else {
1100
-                $callback = $this->callback;
1101
-            }
1102
-            return sprintf('[%s: message="%s" code=%d mode=callback '.
1103
-                           'callback=%s prefix="%s" info="%s"]',
1104
-                           strtolower(get_class($this)), $this->message, $this->code,
1105
-                           $callback, $this->error_message_prefix,
1106
-                           $this->userinfo);
1107
-        }
1108
-        if ($this->mode & PEAR_ERROR_PRINT) {
1109
-            $modes[] = 'print';
1110
-        }
1111
-        if ($this->mode & PEAR_ERROR_TRIGGER) {
1112
-            $modes[] = 'trigger';
1113
-        }
1114
-        if ($this->mode & PEAR_ERROR_DIE) {
1115
-            $modes[] = 'die';
1116
-        }
1117
-        if ($this->mode & PEAR_ERROR_RETURN) {
1118
-            $modes[] = 'return';
1119
-        }
1120
-        return sprintf('[%s: message="%s" code=%d mode=%s level=%s '.
1121
-                       'prefix="%s" info="%s"]',
1122
-                       strtolower(get_class($this)), $this->message, $this->code,
1123
-                       implode("|", $modes), $levels[$this->level],
1124
-                       $this->error_message_prefix,
1125
-                       $this->userinfo);
1126
-    }
1127
-
1128
-    // }}}
833
+	// {{{ properties
834
+
835
+	var $error_message_prefix = '';
836
+	var $mode                 = PEAR_ERROR_RETURN;
837
+	var $level                = E_USER_NOTICE;
838
+	var $code                 = -1;
839
+	var $message              = '';
840
+	var $userinfo             = '';
841
+	var $backtrace            = null;
842
+
843
+	// }}}
844
+	// {{{ constructor
845
+
846
+	/**
847
+	 * PEAR_Error constructor
848
+	 *
849
+	 * @param string $message  message
850
+	 *
851
+	 * @param int $code     (optional) error code
852
+	 *
853
+	 * @param int $mode     (optional) error mode, one of: PEAR_ERROR_RETURN,
854
+	 * PEAR_ERROR_PRINT, PEAR_ERROR_DIE, PEAR_ERROR_TRIGGER,
855
+	 * PEAR_ERROR_CALLBACK or PEAR_ERROR_EXCEPTION
856
+	 *
857
+	 * @param mixed $options   (optional) error level, _OR_ in the case of
858
+	 * PEAR_ERROR_CALLBACK, the callback function or object/method
859
+	 * tuple.
860
+	 *
861
+	 * @param string $userinfo (optional) additional user/debug info
862
+	 *
863
+	 * @access public
864
+	 *
865
+	 */
866
+	function PEAR_Error($message = 'unknown error', $code = null,
867
+						$mode = null, $options = null, $userinfo = null)
868
+	{
869
+		if ($mode === null) {
870
+			$mode = PEAR_ERROR_RETURN;
871
+		}
872
+		$this->message   = $message;
873
+		$this->code      = $code;
874
+		$this->mode      = $mode;
875
+		$this->userinfo  = $userinfo;
876
+
877
+		if (PEAR_ZE2) {
878
+			$skiptrace = PEAR5::getStaticProperty('PEAR_Error', 'skiptrace');
879
+		} else {
880
+			$skiptrace = PEAR::getStaticProperty('PEAR_Error', 'skiptrace');
881
+		}
882
+
883
+		if (!$skiptrace) {
884
+			$this->backtrace = debug_backtrace();
885
+			if (isset($this->backtrace[0]) && isset($this->backtrace[0]['object'])) {
886
+				unset($this->backtrace[0]['object']);
887
+			}
888
+		}
889
+
890
+		if ($mode & PEAR_ERROR_CALLBACK) {
891
+			$this->level = E_USER_NOTICE;
892
+			$this->callback = $options;
893
+		} else {
894
+			if ($options === null) {
895
+				$options = E_USER_NOTICE;
896
+			}
897
+
898
+			$this->level = $options;
899
+			$this->callback = null;
900
+		}
901
+
902
+		if ($this->mode & PEAR_ERROR_PRINT) {
903
+			if (is_null($options) || is_int($options)) {
904
+				$format = "%s";
905
+			} else {
906
+				$format = $options;
907
+			}
908
+
909
+			printf($format, $this->getMessage());
910
+		}
911
+
912
+		if ($this->mode & PEAR_ERROR_TRIGGER) {
913
+			trigger_error($this->getMessage(), $this->level);
914
+		}
915
+
916
+		if ($this->mode & PEAR_ERROR_DIE) {
917
+			$msg = $this->getMessage();
918
+			if (is_null($options) || is_int($options)) {
919
+				$format = "%s";
920
+				if (substr($msg, -1) != "\n") {
921
+					$msg .= "\n";
922
+				}
923
+			} else {
924
+				$format = $options;
925
+			}
926
+			die(sprintf($format, $msg));
927
+		}
928
+
929
+		if ($this->mode & PEAR_ERROR_CALLBACK) {
930
+			if (is_callable($this->callback)) {
931
+				call_user_func($this->callback, $this);
932
+			}
933
+		}
934
+
935
+		if ($this->mode & PEAR_ERROR_EXCEPTION) {
936
+			trigger_error("PEAR_ERROR_EXCEPTION is obsolete, use class PEAR_Exception for exceptions", E_USER_WARNING);
937
+			eval('$e = new Exception($this->message, $this->code);throw($e);');
938
+		}
939
+	}
940
+
941
+	// }}}
942
+	// {{{ getMode()
943
+
944
+	/**
945
+	 * Get the error mode from an error object.
946
+	 *
947
+	 * @return int error mode
948
+	 * @access public
949
+	 */
950
+	function getMode() {
951
+		return $this->mode;
952
+	}
953
+
954
+	// }}}
955
+	// {{{ getCallback()
956
+
957
+	/**
958
+	 * Get the callback function/method from an error object.
959
+	 *
960
+	 * @return mixed callback function or object/method array
961
+	 * @access public
962
+	 */
963
+	function getCallback() {
964
+		return $this->callback;
965
+	}
966
+
967
+	// }}}
968
+	// {{{ getMessage()
969
+
970
+
971
+	/**
972
+	 * Get the error message from an error object.
973
+	 *
974
+	 * @return  string  full error message
975
+	 * @access public
976
+	 */
977
+	function getMessage()
978
+	{
979
+		return ($this->error_message_prefix . $this->message);
980
+	}
981
+
982
+
983
+	// }}}
984
+	// {{{ getCode()
985
+
986
+	/**
987
+	 * Get error code from an error object
988
+	 *
989
+	 * @return int error code
990
+	 * @access public
991
+	 */
992
+	 function getCode()
993
+	 {
994
+		return $this->code;
995
+	 }
996
+
997
+	// }}}
998
+	// {{{ getType()
999
+
1000
+	/**
1001
+	 * Get the name of this error/exception.
1002
+	 *
1003
+	 * @return string error/exception name (type)
1004
+	 * @access public
1005
+	 */
1006
+	function getType()
1007
+	{
1008
+		return get_class($this);
1009
+	}
1010
+
1011
+	// }}}
1012
+	// {{{ getUserInfo()
1013
+
1014
+	/**
1015
+	 * Get additional user-supplied information.
1016
+	 *
1017
+	 * @return string user-supplied information
1018
+	 * @access public
1019
+	 */
1020
+	function getUserInfo()
1021
+	{
1022
+		return $this->userinfo;
1023
+	}
1024
+
1025
+	// }}}
1026
+	// {{{ getDebugInfo()
1027
+
1028
+	/**
1029
+	 * Get additional debug information supplied by the application.
1030
+	 *
1031
+	 * @return string debug information
1032
+	 * @access public
1033
+	 */
1034
+	function getDebugInfo()
1035
+	{
1036
+		return $this->getUserInfo();
1037
+	}
1038
+
1039
+	// }}}
1040
+	// {{{ getBacktrace()
1041
+
1042
+	/**
1043
+	 * Get the call backtrace from where the error was generated.
1044
+	 * Supported with PHP 4.3.0 or newer.
1045
+	 *
1046
+	 * @param int $frame (optional) what frame to fetch
1047
+	 * @return array Backtrace, or NULL if not available.
1048
+	 * @access public
1049
+	 */
1050
+	function getBacktrace($frame = null)
1051
+	{
1052
+		if (defined('PEAR_IGNORE_BACKTRACE')) {
1053
+			return null;
1054
+		}
1055
+		if ($frame === null) {
1056
+			return $this->backtrace;
1057
+		}
1058
+		return $this->backtrace[$frame];
1059
+	}
1060
+
1061
+	// }}}
1062
+	// {{{ addUserInfo()
1063
+
1064
+	function addUserInfo($info)
1065
+	{
1066
+		if (empty($this->userinfo)) {
1067
+			$this->userinfo = $info;
1068
+		} else {
1069
+			$this->userinfo .= " ** $info";
1070
+		}
1071
+	}
1072
+
1073
+	// }}}
1074
+	// {{{ toString()
1075
+	function __toString()
1076
+	{
1077
+		return $this->getMessage();
1078
+	}
1079
+	// }}}
1080
+	// {{{ toString()
1081
+
1082
+	/**
1083
+	 * Make a string representation of this object.
1084
+	 *
1085
+	 * @return string a string with an object summary
1086
+	 * @access public
1087
+	 */
1088
+	function toString() {
1089
+		$modes = array();
1090
+		$levels = array(E_USER_NOTICE  => 'notice',
1091
+						E_USER_WARNING => 'warning',
1092
+						E_USER_ERROR   => 'error');
1093
+		if ($this->mode & PEAR_ERROR_CALLBACK) {
1094
+			if (is_array($this->callback)) {
1095
+				$callback = (is_object($this->callback[0]) ?
1096
+					strtolower(get_class($this->callback[0])) :
1097
+					$this->callback[0]) . '::' .
1098
+					$this->callback[1];
1099
+			} else {
1100
+				$callback = $this->callback;
1101
+			}
1102
+			return sprintf('[%s: message="%s" code=%d mode=callback '.
1103
+						   'callback=%s prefix="%s" info="%s"]',
1104
+						   strtolower(get_class($this)), $this->message, $this->code,
1105
+						   $callback, $this->error_message_prefix,
1106
+						   $this->userinfo);
1107
+		}
1108
+		if ($this->mode & PEAR_ERROR_PRINT) {
1109
+			$modes[] = 'print';
1110
+		}
1111
+		if ($this->mode & PEAR_ERROR_TRIGGER) {
1112
+			$modes[] = 'trigger';
1113
+		}
1114
+		if ($this->mode & PEAR_ERROR_DIE) {
1115
+			$modes[] = 'die';
1116
+		}
1117
+		if ($this->mode & PEAR_ERROR_RETURN) {
1118
+			$modes[] = 'return';
1119
+		}
1120
+		return sprintf('[%s: message="%s" code=%d mode=%s level=%s '.
1121
+					   'prefix="%s" info="%s"]',
1122
+					   strtolower(get_class($this)), $this->message, $this->code,
1123
+					   implode("|", $modes), $levels[$this->level],
1124
+					   $this->error_message_prefix,
1125
+					   $this->userinfo);
1126
+	}
1127
+
1128
+	// }}}
1129 1129
 }
1130 1130
 
1131 1131
 /*
Please login to merge, or discard this patch.
Spacing   +13 added lines, -14 removed lines patch added patch discarded remove patch
@@ -22,11 +22,11 @@  discard block
 block discarded – undo
22 22
 /**#@+
23 23
  * ERROR constants
24 24
  */
25
-define('PEAR_ERROR_RETURN',     1);
26
-define('PEAR_ERROR_PRINT',      2);
27
-define('PEAR_ERROR_TRIGGER',    4);
28
-define('PEAR_ERROR_DIE',        8);
29
-define('PEAR_ERROR_CALLBACK',  16);
25
+define('PEAR_ERROR_RETURN', 1);
26
+define('PEAR_ERROR_PRINT', 2);
27
+define('PEAR_ERROR_TRIGGER', 4);
28
+define('PEAR_ERROR_DIE', 8);
29
+define('PEAR_ERROR_CALLBACK', 16);
30 30
 /**
31 31
  * WARNING: obsolete
32 32
  * @deprecated
@@ -38,12 +38,12 @@  discard block
 block discarded – undo
38 38
 
39 39
 if (substr(PHP_OS, 0, 3) == 'WIN') {
40 40
     define('OS_WINDOWS', true);
41
-    define('OS_UNIX',    false);
42
-    define('PEAR_OS',    'Windows');
41
+    define('OS_UNIX', false);
42
+    define('PEAR_OS', 'Windows');
43 43
 } else {
44 44
     define('OS_WINDOWS', false);
45
-    define('OS_UNIX',    true);
46
-    define('PEAR_OS',    'Unix'); // blatant assumption
45
+    define('OS_UNIX', true);
46
+    define('PEAR_OS', 'Unix'); // blatant assumption
47 47
 }
48 48
 
49 49
 $GLOBALS['_PEAR_default_error_mode']     = PEAR_ERROR_RETURN;
@@ -447,9 +447,9 @@  discard block
 block discarded – undo
447 447
             // $error_code is a non-empty array here;
448 448
             // we walk through it trying to unset all
449 449
             // values
450
-            foreach($error_code as $key => $error) {
450
+            foreach ($error_code as $key => $error) {
451 451
                 if ($this->_checkDelExpect($error)) {
452
-                    $deleted =  true;
452
+                    $deleted = true;
453 453
                 } else {
454 454
                     $deleted = false;
455 455
                 }
@@ -976,7 +976,7 @@  discard block
 block discarded – undo
976 976
      */
977 977
     function getMessage()
978 978
     {
979
-        return ($this->error_message_prefix . $this->message);
979
+        return ($this->error_message_prefix.$this->message);
980 980
     }
981 981
 
982 982
 
@@ -1093,8 +1093,7 @@  discard block
 block discarded – undo
1093 1093
         if ($this->mode & PEAR_ERROR_CALLBACK) {
1094 1094
             if (is_array($this->callback)) {
1095 1095
                 $callback = (is_object($this->callback[0]) ?
1096
-                    strtolower(get_class($this->callback[0])) :
1097
-                    $this->callback[0]) . '::' .
1096
+                    strtolower(get_class($this->callback[0])) : $this->callback[0]).'::'.
1098 1097
                     $this->callback[1];
1099 1098
             } else {
1100 1099
                 $callback = $this->callback;
Please login to merge, or discard this patch.
libs/PEAR.1.9/HTTP/Request2/Adapter.php 2 patches
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
     * A list of methods that MUST NOT have a request body, per RFC 2616
65 65
     * @var  array
66 66
     */
67
-    protected static $bodyDisallowed = array('TRACE');
67
+	protected static $bodyDisallowed = array('TRACE');
68 68
 
69 69
    /**
70 70
     * Methods having defined semantics for request body
@@ -76,26 +76,26 @@  discard block
 block discarded – undo
76 76
     * @link http://pear.php.net/bugs/bug.php?id=12900
77 77
     * @link http://pear.php.net/bugs/bug.php?id=14740
78 78
     */
79
-    protected static $bodyRequired = array('POST', 'PUT');
79
+	protected static $bodyRequired = array('POST', 'PUT');
80 80
 
81 81
    /**
82 82
     * Request being sent
83 83
     * @var  HTTP_Request2
84 84
     */
85
-    protected $request;
85
+	protected $request;
86 86
 
87 87
    /**
88 88
     * Request body
89 89
     * @var  string|resource|HTTP_Request2_MultipartBody
90 90
     * @see  HTTP_Request2::getBody()
91 91
     */
92
-    protected $requestBody;
92
+	protected $requestBody;
93 93
 
94 94
    /**
95 95
     * Length of the request body
96 96
     * @var  integer
97 97
     */
98
-    protected $contentLength;
98
+	protected $contentLength;
99 99
 
100 100
    /**
101 101
     * Sends request to the remote server and returns its response
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
     * @return   HTTP_Request2_Response
105 105
     * @throws   HTTP_Request2_Exception
106 106
     */
107
-    abstract public function sendRequest(HTTP_Request2 $request);
107
+	abstract public function sendRequest(HTTP_Request2 $request);
108 108
 
109 109
    /**
110 110
     * Calculates length of the request body, adds proper headers
@@ -113,42 +113,42 @@  discard block
 block discarded – undo
113 113
     *                   add proper 'Content-Length' and 'Content-Type' headers
114 114
     *                   to this array (or remove them if not needed)
115 115
     */
116
-    protected function calculateRequestLength(&$headers)
117
-    {
118
-        $this->requestBody = $this->request->getBody();
116
+	protected function calculateRequestLength(&$headers)
117
+	{
118
+		$this->requestBody = $this->request->getBody();
119 119
 
120
-        if (is_string($this->requestBody)) {
121
-            $this->contentLength = strlen($this->requestBody);
122
-        } elseif (is_resource($this->requestBody)) {
123
-            $stat = fstat($this->requestBody);
124
-            $this->contentLength = $stat['size'];
125
-            rewind($this->requestBody);
126
-        } else {
127
-            $this->contentLength = $this->requestBody->getLength();
128
-            $headers['content-type'] = 'multipart/form-data; boundary=' .
129
-                                       $this->requestBody->getBoundary();
130
-            $this->requestBody->rewind();
131
-        }
120
+		if (is_string($this->requestBody)) {
121
+			$this->contentLength = strlen($this->requestBody);
122
+		} elseif (is_resource($this->requestBody)) {
123
+			$stat = fstat($this->requestBody);
124
+			$this->contentLength = $stat['size'];
125
+			rewind($this->requestBody);
126
+		} else {
127
+			$this->contentLength = $this->requestBody->getLength();
128
+			$headers['content-type'] = 'multipart/form-data; boundary=' .
129
+									   $this->requestBody->getBoundary();
130
+			$this->requestBody->rewind();
131
+		}
132 132
 
133
-        if (in_array($this->request->getMethod(), self::$bodyDisallowed) ||
134
-            0 == $this->contentLength
135
-        ) {
136
-            // No body: send a Content-Length header nonetheless (request #12900),
137
-            // but do that only for methods that require a body (bug #14740)
138
-            if (in_array($this->request->getMethod(), self::$bodyRequired)) {
139
-                $headers['content-length'] = 0;
140
-            } else {
141
-                unset($headers['content-length']);
142
-                // if the method doesn't require a body and doesn't have a
143
-                // body, don't send a Content-Type header. (request #16799)
144
-                unset($headers['content-type']);
145
-            }
146
-        } else {
147
-            if (empty($headers['content-type'])) {
148
-                $headers['content-type'] = 'application/x-www-form-urlencoded';
149
-            }
150
-            $headers['content-length'] = $this->contentLength;
151
-        }
152
-    }
133
+		if (in_array($this->request->getMethod(), self::$bodyDisallowed) ||
134
+			0 == $this->contentLength
135
+		) {
136
+			// No body: send a Content-Length header nonetheless (request #12900),
137
+			// but do that only for methods that require a body (bug #14740)
138
+			if (in_array($this->request->getMethod(), self::$bodyRequired)) {
139
+				$headers['content-length'] = 0;
140
+			} else {
141
+				unset($headers['content-length']);
142
+				// if the method doesn't require a body and doesn't have a
143
+				// body, don't send a Content-Type header. (request #16799)
144
+				unset($headers['content-type']);
145
+			}
146
+		} else {
147
+			if (empty($headers['content-type'])) {
148
+				$headers['content-type'] = 'application/x-www-form-urlencoded';
149
+			}
150
+			$headers['content-length'] = $this->contentLength;
151
+		}
152
+	}
153 153
 }
154 154
 ?>
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -125,7 +125,7 @@
 block discarded – undo
125 125
             rewind($this->requestBody);
126 126
         } else {
127 127
             $this->contentLength = $this->requestBody->getLength();
128
-            $headers['content-type'] = 'multipart/form-data; boundary=' .
128
+            $headers['content-type'] = 'multipart/form-data; boundary='.
129 129
                                        $this->requestBody->getBoundary();
130 130
             $this->requestBody->rewind();
131 131
         }
Please login to merge, or discard this patch.
libs/PEAR.1.9.5/PEAR5.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -5,29 +5,29 @@
 block discarded – undo
5 5
  */
6 6
 class PEAR5
7 7
 {
8
-    /**
9
-    * If you have a class that's mostly/entirely static, and you need static
10
-    * properties, you can use this method to simulate them. Eg. in your method(s)
11
-    * do this: $myVar = &PEAR5::getStaticProperty('myclass', 'myVar');
12
-    * You MUST use a reference, or they will not persist!
13
-    *
14
-    * @access public
15
-    * @param  string $class  The calling classname, to prevent clashes
16
-    * @param  string $var    The variable to retrieve.
17
-    * @return mixed   A reference to the variable. If not set it will be
18
-    *                 auto initialised to NULL.
19
-    */
20
-    static function &getStaticProperty($class, $var)
21
-    {
22
-        static $properties;
23
-        if (!isset($properties[$class])) {
24
-            $properties[$class] = array();
25
-        }
8
+	/**
9
+	 * If you have a class that's mostly/entirely static, and you need static
10
+	 * properties, you can use this method to simulate them. Eg. in your method(s)
11
+	 * do this: $myVar = &PEAR5::getStaticProperty('myclass', 'myVar');
12
+	 * You MUST use a reference, or they will not persist!
13
+	 *
14
+	 * @access public
15
+	 * @param  string $class  The calling classname, to prevent clashes
16
+	 * @param  string $var    The variable to retrieve.
17
+	 * @return mixed   A reference to the variable. If not set it will be
18
+	 *                 auto initialised to NULL.
19
+	 */
20
+	static function &getStaticProperty($class, $var)
21
+	{
22
+		static $properties;
23
+		if (!isset($properties[$class])) {
24
+			$properties[$class] = array();
25
+		}
26 26
 
27
-        if (!array_key_exists($var, $properties[$class])) {
28
-            $properties[$class][$var] = null;
29
-        }
27
+		if (!array_key_exists($var, $properties[$class])) {
28
+			$properties[$class][$var] = null;
29
+		}
30 30
 
31
-        return $properties[$class][$var];
32
-    }
31
+		return $properties[$class][$var];
32
+	}
33 33
 }
34 34
\ No newline at end of file
Please login to merge, or discard this patch.
libs/PEAR.1.9.5/PEAR.php 2 patches
Indentation   +945 added lines, -945 removed lines patch added patch discarded remove patch
@@ -34,16 +34,16 @@  discard block
 block discarded – undo
34 34
 define('PEAR_ERROR_EXCEPTION', 32);
35 35
 /**#@-*/
36 36
 define('PEAR_ZE2', (function_exists('version_compare') &&
37
-                    version_compare(zend_version(), "2-dev", "ge")));
37
+					version_compare(zend_version(), "2-dev", "ge")));
38 38
 
39 39
 if (substr(PHP_OS, 0, 3) == 'WIN') {
40
-    define('OS_WINDOWS', true);
41
-    define('OS_UNIX',    false);
42
-    define('PEAR_OS',    'Windows');
40
+	define('OS_WINDOWS', true);
41
+	define('OS_UNIX',    false);
42
+	define('PEAR_OS',    'Windows');
43 43
 } else {
44
-    define('OS_WINDOWS', false);
45
-    define('OS_UNIX',    true);
46
-    define('PEAR_OS',    'Unix'); // blatant assumption
44
+	define('OS_WINDOWS', false);
45
+	define('OS_UNIX',    true);
46
+	define('PEAR_OS',    'Unix'); // blatant assumption
47 47
 }
48 48
 
49 49
 $GLOBALS['_PEAR_default_error_mode']     = PEAR_ERROR_RETURN;
@@ -86,694 +86,694 @@  discard block
 block discarded – undo
86 86
  */
87 87
 class PEAR
88 88
 {
89
-    /**
90
-     * Whether to enable internal debug messages.
91
-     *
92
-     * @var     bool
93
-     * @access  private
94
-     */
95
-    var $_debug = false;
96
-
97
-    /**
98
-     * Default error mode for this object.
99
-     *
100
-     * @var     int
101
-     * @access  private
102
-     */
103
-    var $_default_error_mode = null;
104
-
105
-    /**
106
-     * Default error options used for this object when error mode
107
-     * is PEAR_ERROR_TRIGGER.
108
-     *
109
-     * @var     int
110
-     * @access  private
111
-     */
112
-    var $_default_error_options = null;
113
-
114
-    /**
115
-     * Default error handler (callback) for this object, if error mode is
116
-     * PEAR_ERROR_CALLBACK.
117
-     *
118
-     * @var     string
119
-     * @access  private
120
-     */
121
-    var $_default_error_handler = '';
122
-
123
-    /**
124
-     * Which class to use for error objects.
125
-     *
126
-     * @var     string
127
-     * @access  private
128
-     */
129
-    var $_error_class = 'PEAR_Error';
130
-
131
-    /**
132
-     * An array of expected errors.
133
-     *
134
-     * @var     array
135
-     * @access  private
136
-     */
137
-    var $_expected_errors = array();
138
-
139
-    /**
140
-     * Constructor.  Registers this object in
141
-     * $_PEAR_destructor_object_list for destructor emulation if a
142
-     * destructor object exists.
143
-     *
144
-     * @param string $error_class  (optional) which class to use for
145
-     *        error objects, defaults to PEAR_Error.
146
-     * @access public
147
-     * @return void
148
-     */
149
-    function PEAR($error_class = null)
150
-    {
151
-        $classname = strtolower(get_class($this));
152
-        if ($this->_debug) {
153
-            print "PEAR constructor called, class=$classname\n";
154
-        }
155
-
156
-        if ($error_class !== null) {
157
-            $this->_error_class = $error_class;
158
-        }
159
-
160
-        while ($classname && strcasecmp($classname, "pear")) {
161
-            $destructor = "_$classname";
162
-            if (method_exists($this, $destructor)) {
163
-                global $_PEAR_destructor_object_list;
164
-                $_PEAR_destructor_object_list[] = &$this;
165
-                if (!isset($GLOBALS['_PEAR_SHUTDOWN_REGISTERED'])) {
166
-                    register_shutdown_function("_PEAR_call_destructors");
167
-                    $GLOBALS['_PEAR_SHUTDOWN_REGISTERED'] = true;
168
-                }
169
-                break;
170
-            } else {
171
-                $classname = get_parent_class($classname);
172
-            }
173
-        }
174
-    }
175
-
176
-    /**
177
-     * Destructor (the emulated type of...).  Does nothing right now,
178
-     * but is included for forward compatibility, so subclass
179
-     * destructors should always call it.
180
-     *
181
-     * See the note in the class desciption about output from
182
-     * destructors.
183
-     *
184
-     * @access public
185
-     * @return void
186
-     */
187
-    function _PEAR() {
188
-        if ($this->_debug) {
189
-            printf("PEAR destructor called, class=%s\n", strtolower(get_class($this)));
190
-        }
191
-    }
192
-
193
-    /**
194
-    * If you have a class that's mostly/entirely static, and you need static
195
-    * properties, you can use this method to simulate them. Eg. in your method(s)
196
-    * do this: $myVar = &PEAR::getStaticProperty('myclass', 'myVar');
197
-    * You MUST use a reference, or they will not persist!
198
-    *
199
-    * @access public
200
-    * @param  string $class  The calling classname, to prevent clashes
201
-    * @param  string $var    The variable to retrieve.
202
-    * @return mixed   A reference to the variable. If not set it will be
203
-    *                 auto initialised to NULL.
204
-    */
205
-    function &getStaticProperty($class, $var)
206
-    {
207
-        static $properties;
208
-        if (!isset($properties[$class])) {
209
-            $properties[$class] = array();
210
-        }
211
-
212
-        if (!array_key_exists($var, $properties[$class])) {
213
-            $properties[$class][$var] = null;
214
-        }
215
-
216
-        return $properties[$class][$var];
217
-    }
218
-
219
-    /**
220
-    * Use this function to register a shutdown method for static
221
-    * classes.
222
-    *
223
-    * @access public
224
-    * @param  mixed $func  The function name (or array of class/method) to call
225
-    * @param  mixed $args  The arguments to pass to the function
226
-    * @return void
227
-    */
228
-    function registerShutdownFunc($func, $args = array())
229
-    {
230
-        // if we are called statically, there is a potential
231
-        // that no shutdown func is registered.  Bug #6445
232
-        if (!isset($GLOBALS['_PEAR_SHUTDOWN_REGISTERED'])) {
233
-            register_shutdown_function("_PEAR_call_destructors");
234
-            $GLOBALS['_PEAR_SHUTDOWN_REGISTERED'] = true;
235
-        }
236
-        $GLOBALS['_PEAR_shutdown_funcs'][] = array($func, $args);
237
-    }
238
-
239
-    /**
240
-     * Tell whether a value is a PEAR error.
241
-     *
242
-     * @param   mixed $data   the value to test
243
-     * @param   int   $code   if $data is an error object, return true
244
-     *                        only if $code is a string and
245
-     *                        $obj->getMessage() == $code or
246
-     *                        $code is an integer and $obj->getCode() == $code
247
-     * @access  public
248
-     * @return  bool    true if parameter is an error
249
-     */
250
-    function isError($data, $code = null)
251
-    {
252
-        if (!is_a($data, 'PEAR_Error')) {
253
-            return false;
254
-        }
255
-
256
-        if (is_null($code)) {
257
-            return true;
258
-        } elseif (is_string($code)) {
259
-            return $data->getMessage() == $code;
260
-        }
261
-
262
-        return $data->getCode() == $code;
263
-    }
264
-
265
-    /**
266
-     * Sets how errors generated by this object should be handled.
267
-     * Can be invoked both in objects and statically.  If called
268
-     * statically, setErrorHandling sets the default behaviour for all
269
-     * PEAR objects.  If called in an object, setErrorHandling sets
270
-     * the default behaviour for that object.
271
-     *
272
-     * @param int $mode
273
-     *        One of PEAR_ERROR_RETURN, PEAR_ERROR_PRINT,
274
-     *        PEAR_ERROR_TRIGGER, PEAR_ERROR_DIE,
275
-     *        PEAR_ERROR_CALLBACK or PEAR_ERROR_EXCEPTION.
276
-     *
277
-     * @param mixed $options
278
-     *        When $mode is PEAR_ERROR_TRIGGER, this is the error level (one
279
-     *        of E_USER_NOTICE, E_USER_WARNING or E_USER_ERROR).
280
-     *
281
-     *        When $mode is PEAR_ERROR_CALLBACK, this parameter is expected
282
-     *        to be the callback function or method.  A callback
283
-     *        function is a string with the name of the function, a
284
-     *        callback method is an array of two elements: the element
285
-     *        at index 0 is the object, and the element at index 1 is
286
-     *        the name of the method to call in the object.
287
-     *
288
-     *        When $mode is PEAR_ERROR_PRINT or PEAR_ERROR_DIE, this is
289
-     *        a printf format string used when printing the error
290
-     *        message.
291
-     *
292
-     * @access public
293
-     * @return void
294
-     * @see PEAR_ERROR_RETURN
295
-     * @see PEAR_ERROR_PRINT
296
-     * @see PEAR_ERROR_TRIGGER
297
-     * @see PEAR_ERROR_DIE
298
-     * @see PEAR_ERROR_CALLBACK
299
-     * @see PEAR_ERROR_EXCEPTION
300
-     *
301
-     * @since PHP 4.0.5
302
-     */
303
-    function setErrorHandling($mode = null, $options = null)
304
-    {
305
-        if (isset($this) && is_a($this, 'PEAR')) {
306
-            $setmode     = &$this->_default_error_mode;
307
-            $setoptions  = &$this->_default_error_options;
308
-        } else {
309
-            $setmode     = &$GLOBALS['_PEAR_default_error_mode'];
310
-            $setoptions  = &$GLOBALS['_PEAR_default_error_options'];
311
-        }
312
-
313
-        switch ($mode) {
314
-            case PEAR_ERROR_EXCEPTION:
315
-            case PEAR_ERROR_RETURN:
316
-            case PEAR_ERROR_PRINT:
317
-            case PEAR_ERROR_TRIGGER:
318
-            case PEAR_ERROR_DIE:
319
-            case null:
320
-                $setmode = $mode;
321
-                $setoptions = $options;
322
-                break;
323
-
324
-            case PEAR_ERROR_CALLBACK:
325
-                $setmode = $mode;
326
-                // class/object method callback
327
-                if (is_callable($options)) {
328
-                    $setoptions = $options;
329
-                } else {
330
-                    trigger_error("invalid error callback", E_USER_WARNING);
331
-                }
332
-                break;
333
-
334
-            default:
335
-                trigger_error("invalid error mode", E_USER_WARNING);
336
-                break;
337
-        }
338
-    }
339
-
340
-    /**
341
-     * This method is used to tell which errors you expect to get.
342
-     * Expected errors are always returned with error mode
343
-     * PEAR_ERROR_RETURN.  Expected error codes are stored in a stack,
344
-     * and this method pushes a new element onto it.  The list of
345
-     * expected errors are in effect until they are popped off the
346
-     * stack with the popExpect() method.
347
-     *
348
-     * Note that this method can not be called statically
349
-     *
350
-     * @param mixed $code a single error code or an array of error codes to expect
351
-     *
352
-     * @return int     the new depth of the "expected errors" stack
353
-     * @access public
354
-     */
355
-    function expectError($code = '*')
356
-    {
357
-        if (is_array($code)) {
358
-            array_push($this->_expected_errors, $code);
359
-        } else {
360
-            array_push($this->_expected_errors, array($code));
361
-        }
362
-        return count($this->_expected_errors);
363
-    }
364
-
365
-    /**
366
-     * This method pops one element off the expected error codes
367
-     * stack.
368
-     *
369
-     * @return array   the list of error codes that were popped
370
-     */
371
-    function popExpect()
372
-    {
373
-        return array_pop($this->_expected_errors);
374
-    }
375
-
376
-    /**
377
-     * This method checks unsets an error code if available
378
-     *
379
-     * @param mixed error code
380
-     * @return bool true if the error code was unset, false otherwise
381
-     * @access private
382
-     * @since PHP 4.3.0
383
-     */
384
-    function _checkDelExpect($error_code)
385
-    {
386
-        $deleted = false;
387
-        foreach ($this->_expected_errors as $key => $error_array) {
388
-            if (in_array($error_code, $error_array)) {
389
-                unset($this->_expected_errors[$key][array_search($error_code, $error_array)]);
390
-                $deleted = true;
391
-            }
392
-
393
-            // clean up empty arrays
394
-            if (0 == count($this->_expected_errors[$key])) {
395
-                unset($this->_expected_errors[$key]);
396
-            }
397
-        }
398
-
399
-        return $deleted;
400
-    }
401
-
402
-    /**
403
-     * This method deletes all occurences of the specified element from
404
-     * the expected error codes stack.
405
-     *
406
-     * @param  mixed $error_code error code that should be deleted
407
-     * @return mixed list of error codes that were deleted or error
408
-     * @access public
409
-     * @since PHP 4.3.0
410
-     */
411
-    function delExpect($error_code)
412
-    {
413
-        $deleted = false;
414
-        if ((is_array($error_code) && (0 != count($error_code)))) {
415
-            // $error_code is a non-empty array here; we walk through it trying
416
-            // to unset all values
417
-            foreach ($error_code as $key => $error) {
418
-                $deleted =  $this->_checkDelExpect($error) ? true : false;
419
-            }
420
-
421
-            return $deleted ? true : PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME
422
-        } elseif (!empty($error_code)) {
423
-            // $error_code comes alone, trying to unset it
424
-            if ($this->_checkDelExpect($error_code)) {
425
-                return true;
426
-            }
427
-
428
-            return PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME
429
-        }
430
-
431
-        // $error_code is empty
432
-        return PEAR::raiseError("The expected error you submitted is empty"); // IMPROVE ME
433
-    }
434
-
435
-    /**
436
-     * This method is a wrapper that returns an instance of the
437
-     * configured error class with this object's default error
438
-     * handling applied.  If the $mode and $options parameters are not
439
-     * specified, the object's defaults are used.
440
-     *
441
-     * @param mixed $message a text error message or a PEAR error object
442
-     *
443
-     * @param int $code      a numeric error code (it is up to your class
444
-     *                  to define these if you want to use codes)
445
-     *
446
-     * @param int $mode      One of PEAR_ERROR_RETURN, PEAR_ERROR_PRINT,
447
-     *                  PEAR_ERROR_TRIGGER, PEAR_ERROR_DIE,
448
-     *                  PEAR_ERROR_CALLBACK, PEAR_ERROR_EXCEPTION.
449
-     *
450
-     * @param mixed $options If $mode is PEAR_ERROR_TRIGGER, this parameter
451
-     *                  specifies the PHP-internal error level (one of
452
-     *                  E_USER_NOTICE, E_USER_WARNING or E_USER_ERROR).
453
-     *                  If $mode is PEAR_ERROR_CALLBACK, this
454
-     *                  parameter specifies the callback function or
455
-     *                  method.  In other error modes this parameter
456
-     *                  is ignored.
457
-     *
458
-     * @param string $userinfo If you need to pass along for example debug
459
-     *                  information, this parameter is meant for that.
460
-     *
461
-     * @param string $error_class The returned error object will be
462
-     *                  instantiated from this class, if specified.
463
-     *
464
-     * @param bool $skipmsg If true, raiseError will only pass error codes,
465
-     *                  the error message parameter will be dropped.
466
-     *
467
-     * @access public
468
-     * @return object   a PEAR error object
469
-     * @see PEAR::setErrorHandling
470
-     * @since PHP 4.0.5
471
-     */
472
-    function &raiseError($message = null,
473
-                         $code = null,
474
-                         $mode = null,
475
-                         $options = null,
476
-                         $userinfo = null,
477
-                         $error_class = null,
478
-                         $skipmsg = false)
479
-    {
480
-        // The error is yet a PEAR error object
481
-        if (is_object($message)) {
482
-            $code        = $message->getCode();
483
-            $userinfo    = $message->getUserInfo();
484
-            $error_class = $message->getType();
485
-            $message->error_message_prefix = '';
486
-            $message     = $message->getMessage();
487
-        }
488
-
489
-        if (
490
-            isset($this) &&
491
-            isset($this->_expected_errors) &&
492
-            count($this->_expected_errors) > 0 &&
493
-            count($exp = end($this->_expected_errors))
494
-        ) {
495
-            if ($exp[0] == "*" ||
496
-                (is_int(reset($exp)) && in_array($code, $exp)) ||
497
-                (is_string(reset($exp)) && in_array($message, $exp))
498
-            ) {
499
-                $mode = PEAR_ERROR_RETURN;
500
-            }
501
-        }
502
-
503
-        // No mode given, try global ones
504
-        if ($mode === null) {
505
-            // Class error handler
506
-            if (isset($this) && isset($this->_default_error_mode)) {
507
-                $mode    = $this->_default_error_mode;
508
-                $options = $this->_default_error_options;
509
-            // Global error handler
510
-            } elseif (isset($GLOBALS['_PEAR_default_error_mode'])) {
511
-                $mode    = $GLOBALS['_PEAR_default_error_mode'];
512
-                $options = $GLOBALS['_PEAR_default_error_options'];
513
-            }
514
-        }
515
-
516
-        if ($error_class !== null) {
517
-            $ec = $error_class;
518
-        } elseif (isset($this) && isset($this->_error_class)) {
519
-            $ec = $this->_error_class;
520
-        } else {
521
-            $ec = 'PEAR_Error';
522
-        }
523
-
524
-        if (intval(PHP_VERSION) < 5) {
525
-            // little non-eval hack to fix bug #12147
526
-            include 'PEAR/FixPHP5PEARWarnings.php';
527
-            return $a;
528
-        }
529
-
530
-        if ($skipmsg) {
531
-            $a = new $ec($code, $mode, $options, $userinfo);
532
-        } else {
533
-            $a = new $ec($message, $code, $mode, $options, $userinfo);
534
-        }
535
-
536
-        return $a;
537
-    }
538
-
539
-    /**
540
-     * Simpler form of raiseError with fewer options.  In most cases
541
-     * message, code and userinfo are enough.
542
-     *
543
-     * @param mixed $message a text error message or a PEAR error object
544
-     *
545
-     * @param int $code      a numeric error code (it is up to your class
546
-     *                  to define these if you want to use codes)
547
-     *
548
-     * @param string $userinfo If you need to pass along for example debug
549
-     *                  information, this parameter is meant for that.
550
-     *
551
-     * @access public
552
-     * @return object   a PEAR error object
553
-     * @see PEAR::raiseError
554
-     */
555
-    function &throwError($message = null, $code = null, $userinfo = null)
556
-    {
557
-        if (isset($this) && is_a($this, 'PEAR')) {
558
-            $a = &$this->raiseError($message, $code, null, null, $userinfo);
559
-            return $a;
560
-        }
561
-
562
-        $a = &PEAR::raiseError($message, $code, null, null, $userinfo);
563
-        return $a;
564
-    }
565
-
566
-    function staticPushErrorHandling($mode, $options = null)
567
-    {
568
-        $stack       = &$GLOBALS['_PEAR_error_handler_stack'];
569
-        $def_mode    = &$GLOBALS['_PEAR_default_error_mode'];
570
-        $def_options = &$GLOBALS['_PEAR_default_error_options'];
571
-        $stack[] = array($def_mode, $def_options);
572
-        switch ($mode) {
573
-            case PEAR_ERROR_EXCEPTION:
574
-            case PEAR_ERROR_RETURN:
575
-            case PEAR_ERROR_PRINT:
576
-            case PEAR_ERROR_TRIGGER:
577
-            case PEAR_ERROR_DIE:
578
-            case null:
579
-                $def_mode = $mode;
580
-                $def_options = $options;
581
-                break;
582
-
583
-            case PEAR_ERROR_CALLBACK:
584
-                $def_mode = $mode;
585
-                // class/object method callback
586
-                if (is_callable($options)) {
587
-                    $def_options = $options;
588
-                } else {
589
-                    trigger_error("invalid error callback", E_USER_WARNING);
590
-                }
591
-                break;
592
-
593
-            default:
594
-                trigger_error("invalid error mode", E_USER_WARNING);
595
-                break;
596
-        }
597
-        $stack[] = array($mode, $options);
598
-        return true;
599
-    }
600
-
601
-    function staticPopErrorHandling()
602
-    {
603
-        $stack = &$GLOBALS['_PEAR_error_handler_stack'];
604
-        $setmode     = &$GLOBALS['_PEAR_default_error_mode'];
605
-        $setoptions  = &$GLOBALS['_PEAR_default_error_options'];
606
-        array_pop($stack);
607
-        list($mode, $options) = $stack[sizeof($stack) - 1];
608
-        array_pop($stack);
609
-        switch ($mode) {
610
-            case PEAR_ERROR_EXCEPTION:
611
-            case PEAR_ERROR_RETURN:
612
-            case PEAR_ERROR_PRINT:
613
-            case PEAR_ERROR_TRIGGER:
614
-            case PEAR_ERROR_DIE:
615
-            case null:
616
-                $setmode = $mode;
617
-                $setoptions = $options;
618
-                break;
619
-
620
-            case PEAR_ERROR_CALLBACK:
621
-                $setmode = $mode;
622
-                // class/object method callback
623
-                if (is_callable($options)) {
624
-                    $setoptions = $options;
625
-                } else {
626
-                    trigger_error("invalid error callback", E_USER_WARNING);
627
-                }
628
-                break;
629
-
630
-            default:
631
-                trigger_error("invalid error mode", E_USER_WARNING);
632
-                break;
633
-        }
634
-        return true;
635
-    }
636
-
637
-    /**
638
-     * Push a new error handler on top of the error handler options stack. With this
639
-     * you can easily override the actual error handler for some code and restore
640
-     * it later with popErrorHandling.
641
-     *
642
-     * @param mixed $mode (same as setErrorHandling)
643
-     * @param mixed $options (same as setErrorHandling)
644
-     *
645
-     * @return bool Always true
646
-     *
647
-     * @see PEAR::setErrorHandling
648
-     */
649
-    function pushErrorHandling($mode, $options = null)
650
-    {
651
-        $stack = &$GLOBALS['_PEAR_error_handler_stack'];
652
-        if (isset($this) && is_a($this, 'PEAR')) {
653
-            $def_mode    = &$this->_default_error_mode;
654
-            $def_options = &$this->_default_error_options;
655
-        } else {
656
-            $def_mode    = &$GLOBALS['_PEAR_default_error_mode'];
657
-            $def_options = &$GLOBALS['_PEAR_default_error_options'];
658
-        }
659
-        $stack[] = array($def_mode, $def_options);
660
-
661
-        if (isset($this) && is_a($this, 'PEAR')) {
662
-            $this->setErrorHandling($mode, $options);
663
-        } else {
664
-            PEAR::setErrorHandling($mode, $options);
665
-        }
666
-        $stack[] = array($mode, $options);
667
-        return true;
668
-    }
669
-
670
-    /**
671
-    * Pop the last error handler used
672
-    *
673
-    * @return bool Always true
674
-    *
675
-    * @see PEAR::pushErrorHandling
676
-    */
677
-    function popErrorHandling()
678
-    {
679
-        $stack = &$GLOBALS['_PEAR_error_handler_stack'];
680
-        array_pop($stack);
681
-        list($mode, $options) = $stack[sizeof($stack) - 1];
682
-        array_pop($stack);
683
-        if (isset($this) && is_a($this, 'PEAR')) {
684
-            $this->setErrorHandling($mode, $options);
685
-        } else {
686
-            PEAR::setErrorHandling($mode, $options);
687
-        }
688
-        return true;
689
-    }
690
-
691
-    /**
692
-    * OS independent PHP extension load. Remember to take care
693
-    * on the correct extension name for case sensitive OSes.
694
-    *
695
-    * @param string $ext The extension name
696
-    * @return bool Success or not on the dl() call
697
-    */
698
-    function loadExtension($ext)
699
-    {
700
-        if (extension_loaded($ext)) {
701
-            return true;
702
-        }
703
-
704
-        // if either returns true dl() will produce a FATAL error, stop that
705
-        if (
706
-            function_exists('dl') === false ||
707
-            ini_get('enable_dl') != 1 ||
708
-            ini_get('safe_mode') == 1
709
-        ) {
710
-            return false;
711
-        }
712
-
713
-        if (OS_WINDOWS) {
714
-            $suffix = '.dll';
715
-        } elseif (PHP_OS == 'HP-UX') {
716
-            $suffix = '.sl';
717
-        } elseif (PHP_OS == 'AIX') {
718
-            $suffix = '.a';
719
-        } elseif (PHP_OS == 'OSX') {
720
-            $suffix = '.bundle';
721
-        } else {
722
-            $suffix = '.so';
723
-        }
724
-
725
-        return @dl('php_'.$ext.$suffix) || @dl($ext.$suffix);
726
-    }
89
+	/**
90
+	 * Whether to enable internal debug messages.
91
+	 *
92
+	 * @var     bool
93
+	 * @access  private
94
+	 */
95
+	var $_debug = false;
96
+
97
+	/**
98
+	 * Default error mode for this object.
99
+	 *
100
+	 * @var     int
101
+	 * @access  private
102
+	 */
103
+	var $_default_error_mode = null;
104
+
105
+	/**
106
+	 * Default error options used for this object when error mode
107
+	 * is PEAR_ERROR_TRIGGER.
108
+	 *
109
+	 * @var     int
110
+	 * @access  private
111
+	 */
112
+	var $_default_error_options = null;
113
+
114
+	/**
115
+	 * Default error handler (callback) for this object, if error mode is
116
+	 * PEAR_ERROR_CALLBACK.
117
+	 *
118
+	 * @var     string
119
+	 * @access  private
120
+	 */
121
+	var $_default_error_handler = '';
122
+
123
+	/**
124
+	 * Which class to use for error objects.
125
+	 *
126
+	 * @var     string
127
+	 * @access  private
128
+	 */
129
+	var $_error_class = 'PEAR_Error';
130
+
131
+	/**
132
+	 * An array of expected errors.
133
+	 *
134
+	 * @var     array
135
+	 * @access  private
136
+	 */
137
+	var $_expected_errors = array();
138
+
139
+	/**
140
+	 * Constructor.  Registers this object in
141
+	 * $_PEAR_destructor_object_list for destructor emulation if a
142
+	 * destructor object exists.
143
+	 *
144
+	 * @param string $error_class  (optional) which class to use for
145
+	 *        error objects, defaults to PEAR_Error.
146
+	 * @access public
147
+	 * @return void
148
+	 */
149
+	function PEAR($error_class = null)
150
+	{
151
+		$classname = strtolower(get_class($this));
152
+		if ($this->_debug) {
153
+			print "PEAR constructor called, class=$classname\n";
154
+		}
155
+
156
+		if ($error_class !== null) {
157
+			$this->_error_class = $error_class;
158
+		}
159
+
160
+		while ($classname && strcasecmp($classname, "pear")) {
161
+			$destructor = "_$classname";
162
+			if (method_exists($this, $destructor)) {
163
+				global $_PEAR_destructor_object_list;
164
+				$_PEAR_destructor_object_list[] = &$this;
165
+				if (!isset($GLOBALS['_PEAR_SHUTDOWN_REGISTERED'])) {
166
+					register_shutdown_function("_PEAR_call_destructors");
167
+					$GLOBALS['_PEAR_SHUTDOWN_REGISTERED'] = true;
168
+				}
169
+				break;
170
+			} else {
171
+				$classname = get_parent_class($classname);
172
+			}
173
+		}
174
+	}
175
+
176
+	/**
177
+	 * Destructor (the emulated type of...).  Does nothing right now,
178
+	 * but is included for forward compatibility, so subclass
179
+	 * destructors should always call it.
180
+	 *
181
+	 * See the note in the class desciption about output from
182
+	 * destructors.
183
+	 *
184
+	 * @access public
185
+	 * @return void
186
+	 */
187
+	function _PEAR() {
188
+		if ($this->_debug) {
189
+			printf("PEAR destructor called, class=%s\n", strtolower(get_class($this)));
190
+		}
191
+	}
192
+
193
+	/**
194
+	 * If you have a class that's mostly/entirely static, and you need static
195
+	 * properties, you can use this method to simulate them. Eg. in your method(s)
196
+	 * do this: $myVar = &PEAR::getStaticProperty('myclass', 'myVar');
197
+	 * You MUST use a reference, or they will not persist!
198
+	 *
199
+	 * @access public
200
+	 * @param  string $class  The calling classname, to prevent clashes
201
+	 * @param  string $var    The variable to retrieve.
202
+	 * @return mixed   A reference to the variable. If not set it will be
203
+	 *                 auto initialised to NULL.
204
+	 */
205
+	function &getStaticProperty($class, $var)
206
+	{
207
+		static $properties;
208
+		if (!isset($properties[$class])) {
209
+			$properties[$class] = array();
210
+		}
211
+
212
+		if (!array_key_exists($var, $properties[$class])) {
213
+			$properties[$class][$var] = null;
214
+		}
215
+
216
+		return $properties[$class][$var];
217
+	}
218
+
219
+	/**
220
+	 * Use this function to register a shutdown method for static
221
+	 * classes.
222
+	 *
223
+	 * @access public
224
+	 * @param  mixed $func  The function name (or array of class/method) to call
225
+	 * @param  mixed $args  The arguments to pass to the function
226
+	 * @return void
227
+	 */
228
+	function registerShutdownFunc($func, $args = array())
229
+	{
230
+		// if we are called statically, there is a potential
231
+		// that no shutdown func is registered.  Bug #6445
232
+		if (!isset($GLOBALS['_PEAR_SHUTDOWN_REGISTERED'])) {
233
+			register_shutdown_function("_PEAR_call_destructors");
234
+			$GLOBALS['_PEAR_SHUTDOWN_REGISTERED'] = true;
235
+		}
236
+		$GLOBALS['_PEAR_shutdown_funcs'][] = array($func, $args);
237
+	}
238
+
239
+	/**
240
+	 * Tell whether a value is a PEAR error.
241
+	 *
242
+	 * @param   mixed $data   the value to test
243
+	 * @param   int   $code   if $data is an error object, return true
244
+	 *                        only if $code is a string and
245
+	 *                        $obj->getMessage() == $code or
246
+	 *                        $code is an integer and $obj->getCode() == $code
247
+	 * @access  public
248
+	 * @return  bool    true if parameter is an error
249
+	 */
250
+	function isError($data, $code = null)
251
+	{
252
+		if (!is_a($data, 'PEAR_Error')) {
253
+			return false;
254
+		}
255
+
256
+		if (is_null($code)) {
257
+			return true;
258
+		} elseif (is_string($code)) {
259
+			return $data->getMessage() == $code;
260
+		}
261
+
262
+		return $data->getCode() == $code;
263
+	}
264
+
265
+	/**
266
+	 * Sets how errors generated by this object should be handled.
267
+	 * Can be invoked both in objects and statically.  If called
268
+	 * statically, setErrorHandling sets the default behaviour for all
269
+	 * PEAR objects.  If called in an object, setErrorHandling sets
270
+	 * the default behaviour for that object.
271
+	 *
272
+	 * @param int $mode
273
+	 *        One of PEAR_ERROR_RETURN, PEAR_ERROR_PRINT,
274
+	 *        PEAR_ERROR_TRIGGER, PEAR_ERROR_DIE,
275
+	 *        PEAR_ERROR_CALLBACK or PEAR_ERROR_EXCEPTION.
276
+	 *
277
+	 * @param mixed $options
278
+	 *        When $mode is PEAR_ERROR_TRIGGER, this is the error level (one
279
+	 *        of E_USER_NOTICE, E_USER_WARNING or E_USER_ERROR).
280
+	 *
281
+	 *        When $mode is PEAR_ERROR_CALLBACK, this parameter is expected
282
+	 *        to be the callback function or method.  A callback
283
+	 *        function is a string with the name of the function, a
284
+	 *        callback method is an array of two elements: the element
285
+	 *        at index 0 is the object, and the element at index 1 is
286
+	 *        the name of the method to call in the object.
287
+	 *
288
+	 *        When $mode is PEAR_ERROR_PRINT or PEAR_ERROR_DIE, this is
289
+	 *        a printf format string used when printing the error
290
+	 *        message.
291
+	 *
292
+	 * @access public
293
+	 * @return void
294
+	 * @see PEAR_ERROR_RETURN
295
+	 * @see PEAR_ERROR_PRINT
296
+	 * @see PEAR_ERROR_TRIGGER
297
+	 * @see PEAR_ERROR_DIE
298
+	 * @see PEAR_ERROR_CALLBACK
299
+	 * @see PEAR_ERROR_EXCEPTION
300
+	 *
301
+	 * @since PHP 4.0.5
302
+	 */
303
+	function setErrorHandling($mode = null, $options = null)
304
+	{
305
+		if (isset($this) && is_a($this, 'PEAR')) {
306
+			$setmode     = &$this->_default_error_mode;
307
+			$setoptions  = &$this->_default_error_options;
308
+		} else {
309
+			$setmode     = &$GLOBALS['_PEAR_default_error_mode'];
310
+			$setoptions  = &$GLOBALS['_PEAR_default_error_options'];
311
+		}
312
+
313
+		switch ($mode) {
314
+			case PEAR_ERROR_EXCEPTION:
315
+			case PEAR_ERROR_RETURN:
316
+			case PEAR_ERROR_PRINT:
317
+			case PEAR_ERROR_TRIGGER:
318
+			case PEAR_ERROR_DIE:
319
+			case null:
320
+				$setmode = $mode;
321
+				$setoptions = $options;
322
+				break;
323
+
324
+			case PEAR_ERROR_CALLBACK:
325
+				$setmode = $mode;
326
+				// class/object method callback
327
+				if (is_callable($options)) {
328
+					$setoptions = $options;
329
+				} else {
330
+					trigger_error("invalid error callback", E_USER_WARNING);
331
+				}
332
+				break;
333
+
334
+			default:
335
+				trigger_error("invalid error mode", E_USER_WARNING);
336
+				break;
337
+		}
338
+	}
339
+
340
+	/**
341
+	 * This method is used to tell which errors you expect to get.
342
+	 * Expected errors are always returned with error mode
343
+	 * PEAR_ERROR_RETURN.  Expected error codes are stored in a stack,
344
+	 * and this method pushes a new element onto it.  The list of
345
+	 * expected errors are in effect until they are popped off the
346
+	 * stack with the popExpect() method.
347
+	 *
348
+	 * Note that this method can not be called statically
349
+	 *
350
+	 * @param mixed $code a single error code or an array of error codes to expect
351
+	 *
352
+	 * @return int     the new depth of the "expected errors" stack
353
+	 * @access public
354
+	 */
355
+	function expectError($code = '*')
356
+	{
357
+		if (is_array($code)) {
358
+			array_push($this->_expected_errors, $code);
359
+		} else {
360
+			array_push($this->_expected_errors, array($code));
361
+		}
362
+		return count($this->_expected_errors);
363
+	}
364
+
365
+	/**
366
+	 * This method pops one element off the expected error codes
367
+	 * stack.
368
+	 *
369
+	 * @return array   the list of error codes that were popped
370
+	 */
371
+	function popExpect()
372
+	{
373
+		return array_pop($this->_expected_errors);
374
+	}
375
+
376
+	/**
377
+	 * This method checks unsets an error code if available
378
+	 *
379
+	 * @param mixed error code
380
+	 * @return bool true if the error code was unset, false otherwise
381
+	 * @access private
382
+	 * @since PHP 4.3.0
383
+	 */
384
+	function _checkDelExpect($error_code)
385
+	{
386
+		$deleted = false;
387
+		foreach ($this->_expected_errors as $key => $error_array) {
388
+			if (in_array($error_code, $error_array)) {
389
+				unset($this->_expected_errors[$key][array_search($error_code, $error_array)]);
390
+				$deleted = true;
391
+			}
392
+
393
+			// clean up empty arrays
394
+			if (0 == count($this->_expected_errors[$key])) {
395
+				unset($this->_expected_errors[$key]);
396
+			}
397
+		}
398
+
399
+		return $deleted;
400
+	}
401
+
402
+	/**
403
+	 * This method deletes all occurences of the specified element from
404
+	 * the expected error codes stack.
405
+	 *
406
+	 * @param  mixed $error_code error code that should be deleted
407
+	 * @return mixed list of error codes that were deleted or error
408
+	 * @access public
409
+	 * @since PHP 4.3.0
410
+	 */
411
+	function delExpect($error_code)
412
+	{
413
+		$deleted = false;
414
+		if ((is_array($error_code) && (0 != count($error_code)))) {
415
+			// $error_code is a non-empty array here; we walk through it trying
416
+			// to unset all values
417
+			foreach ($error_code as $key => $error) {
418
+				$deleted =  $this->_checkDelExpect($error) ? true : false;
419
+			}
420
+
421
+			return $deleted ? true : PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME
422
+		} elseif (!empty($error_code)) {
423
+			// $error_code comes alone, trying to unset it
424
+			if ($this->_checkDelExpect($error_code)) {
425
+				return true;
426
+			}
427
+
428
+			return PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME
429
+		}
430
+
431
+		// $error_code is empty
432
+		return PEAR::raiseError("The expected error you submitted is empty"); // IMPROVE ME
433
+	}
434
+
435
+	/**
436
+	 * This method is a wrapper that returns an instance of the
437
+	 * configured error class with this object's default error
438
+	 * handling applied.  If the $mode and $options parameters are not
439
+	 * specified, the object's defaults are used.
440
+	 *
441
+	 * @param mixed $message a text error message or a PEAR error object
442
+	 *
443
+	 * @param int $code      a numeric error code (it is up to your class
444
+	 *                  to define these if you want to use codes)
445
+	 *
446
+	 * @param int $mode      One of PEAR_ERROR_RETURN, PEAR_ERROR_PRINT,
447
+	 *                  PEAR_ERROR_TRIGGER, PEAR_ERROR_DIE,
448
+	 *                  PEAR_ERROR_CALLBACK, PEAR_ERROR_EXCEPTION.
449
+	 *
450
+	 * @param mixed $options If $mode is PEAR_ERROR_TRIGGER, this parameter
451
+	 *                  specifies the PHP-internal error level (one of
452
+	 *                  E_USER_NOTICE, E_USER_WARNING or E_USER_ERROR).
453
+	 *                  If $mode is PEAR_ERROR_CALLBACK, this
454
+	 *                  parameter specifies the callback function or
455
+	 *                  method.  In other error modes this parameter
456
+	 *                  is ignored.
457
+	 *
458
+	 * @param string $userinfo If you need to pass along for example debug
459
+	 *                  information, this parameter is meant for that.
460
+	 *
461
+	 * @param string $error_class The returned error object will be
462
+	 *                  instantiated from this class, if specified.
463
+	 *
464
+	 * @param bool $skipmsg If true, raiseError will only pass error codes,
465
+	 *                  the error message parameter will be dropped.
466
+	 *
467
+	 * @access public
468
+	 * @return object   a PEAR error object
469
+	 * @see PEAR::setErrorHandling
470
+	 * @since PHP 4.0.5
471
+	 */
472
+	function &raiseError($message = null,
473
+						 $code = null,
474
+						 $mode = null,
475
+						 $options = null,
476
+						 $userinfo = null,
477
+						 $error_class = null,
478
+						 $skipmsg = false)
479
+	{
480
+		// The error is yet a PEAR error object
481
+		if (is_object($message)) {
482
+			$code        = $message->getCode();
483
+			$userinfo    = $message->getUserInfo();
484
+			$error_class = $message->getType();
485
+			$message->error_message_prefix = '';
486
+			$message     = $message->getMessage();
487
+		}
488
+
489
+		if (
490
+			isset($this) &&
491
+			isset($this->_expected_errors) &&
492
+			count($this->_expected_errors) > 0 &&
493
+			count($exp = end($this->_expected_errors))
494
+		) {
495
+			if ($exp[0] == "*" ||
496
+				(is_int(reset($exp)) && in_array($code, $exp)) ||
497
+				(is_string(reset($exp)) && in_array($message, $exp))
498
+			) {
499
+				$mode = PEAR_ERROR_RETURN;
500
+			}
501
+		}
502
+
503
+		// No mode given, try global ones
504
+		if ($mode === null) {
505
+			// Class error handler
506
+			if (isset($this) && isset($this->_default_error_mode)) {
507
+				$mode    = $this->_default_error_mode;
508
+				$options = $this->_default_error_options;
509
+			// Global error handler
510
+			} elseif (isset($GLOBALS['_PEAR_default_error_mode'])) {
511
+				$mode    = $GLOBALS['_PEAR_default_error_mode'];
512
+				$options = $GLOBALS['_PEAR_default_error_options'];
513
+			}
514
+		}
515
+
516
+		if ($error_class !== null) {
517
+			$ec = $error_class;
518
+		} elseif (isset($this) && isset($this->_error_class)) {
519
+			$ec = $this->_error_class;
520
+		} else {
521
+			$ec = 'PEAR_Error';
522
+		}
523
+
524
+		if (intval(PHP_VERSION) < 5) {
525
+			// little non-eval hack to fix bug #12147
526
+			include 'PEAR/FixPHP5PEARWarnings.php';
527
+			return $a;
528
+		}
529
+
530
+		if ($skipmsg) {
531
+			$a = new $ec($code, $mode, $options, $userinfo);
532
+		} else {
533
+			$a = new $ec($message, $code, $mode, $options, $userinfo);
534
+		}
535
+
536
+		return $a;
537
+	}
538
+
539
+	/**
540
+	 * Simpler form of raiseError with fewer options.  In most cases
541
+	 * message, code and userinfo are enough.
542
+	 *
543
+	 * @param mixed $message a text error message or a PEAR error object
544
+	 *
545
+	 * @param int $code      a numeric error code (it is up to your class
546
+	 *                  to define these if you want to use codes)
547
+	 *
548
+	 * @param string $userinfo If you need to pass along for example debug
549
+	 *                  information, this parameter is meant for that.
550
+	 *
551
+	 * @access public
552
+	 * @return object   a PEAR error object
553
+	 * @see PEAR::raiseError
554
+	 */
555
+	function &throwError($message = null, $code = null, $userinfo = null)
556
+	{
557
+		if (isset($this) && is_a($this, 'PEAR')) {
558
+			$a = &$this->raiseError($message, $code, null, null, $userinfo);
559
+			return $a;
560
+		}
561
+
562
+		$a = &PEAR::raiseError($message, $code, null, null, $userinfo);
563
+		return $a;
564
+	}
565
+
566
+	function staticPushErrorHandling($mode, $options = null)
567
+	{
568
+		$stack       = &$GLOBALS['_PEAR_error_handler_stack'];
569
+		$def_mode    = &$GLOBALS['_PEAR_default_error_mode'];
570
+		$def_options = &$GLOBALS['_PEAR_default_error_options'];
571
+		$stack[] = array($def_mode, $def_options);
572
+		switch ($mode) {
573
+			case PEAR_ERROR_EXCEPTION:
574
+			case PEAR_ERROR_RETURN:
575
+			case PEAR_ERROR_PRINT:
576
+			case PEAR_ERROR_TRIGGER:
577
+			case PEAR_ERROR_DIE:
578
+			case null:
579
+				$def_mode = $mode;
580
+				$def_options = $options;
581
+				break;
582
+
583
+			case PEAR_ERROR_CALLBACK:
584
+				$def_mode = $mode;
585
+				// class/object method callback
586
+				if (is_callable($options)) {
587
+					$def_options = $options;
588
+				} else {
589
+					trigger_error("invalid error callback", E_USER_WARNING);
590
+				}
591
+				break;
592
+
593
+			default:
594
+				trigger_error("invalid error mode", E_USER_WARNING);
595
+				break;
596
+		}
597
+		$stack[] = array($mode, $options);
598
+		return true;
599
+	}
600
+
601
+	function staticPopErrorHandling()
602
+	{
603
+		$stack = &$GLOBALS['_PEAR_error_handler_stack'];
604
+		$setmode     = &$GLOBALS['_PEAR_default_error_mode'];
605
+		$setoptions  = &$GLOBALS['_PEAR_default_error_options'];
606
+		array_pop($stack);
607
+		list($mode, $options) = $stack[sizeof($stack) - 1];
608
+		array_pop($stack);
609
+		switch ($mode) {
610
+			case PEAR_ERROR_EXCEPTION:
611
+			case PEAR_ERROR_RETURN:
612
+			case PEAR_ERROR_PRINT:
613
+			case PEAR_ERROR_TRIGGER:
614
+			case PEAR_ERROR_DIE:
615
+			case null:
616
+				$setmode = $mode;
617
+				$setoptions = $options;
618
+				break;
619
+
620
+			case PEAR_ERROR_CALLBACK:
621
+				$setmode = $mode;
622
+				// class/object method callback
623
+				if (is_callable($options)) {
624
+					$setoptions = $options;
625
+				} else {
626
+					trigger_error("invalid error callback", E_USER_WARNING);
627
+				}
628
+				break;
629
+
630
+			default:
631
+				trigger_error("invalid error mode", E_USER_WARNING);
632
+				break;
633
+		}
634
+		return true;
635
+	}
636
+
637
+	/**
638
+	 * Push a new error handler on top of the error handler options stack. With this
639
+	 * you can easily override the actual error handler for some code and restore
640
+	 * it later with popErrorHandling.
641
+	 *
642
+	 * @param mixed $mode (same as setErrorHandling)
643
+	 * @param mixed $options (same as setErrorHandling)
644
+	 *
645
+	 * @return bool Always true
646
+	 *
647
+	 * @see PEAR::setErrorHandling
648
+	 */
649
+	function pushErrorHandling($mode, $options = null)
650
+	{
651
+		$stack = &$GLOBALS['_PEAR_error_handler_stack'];
652
+		if (isset($this) && is_a($this, 'PEAR')) {
653
+			$def_mode    = &$this->_default_error_mode;
654
+			$def_options = &$this->_default_error_options;
655
+		} else {
656
+			$def_mode    = &$GLOBALS['_PEAR_default_error_mode'];
657
+			$def_options = &$GLOBALS['_PEAR_default_error_options'];
658
+		}
659
+		$stack[] = array($def_mode, $def_options);
660
+
661
+		if (isset($this) && is_a($this, 'PEAR')) {
662
+			$this->setErrorHandling($mode, $options);
663
+		} else {
664
+			PEAR::setErrorHandling($mode, $options);
665
+		}
666
+		$stack[] = array($mode, $options);
667
+		return true;
668
+	}
669
+
670
+	/**
671
+	 * Pop the last error handler used
672
+	 *
673
+	 * @return bool Always true
674
+	 *
675
+	 * @see PEAR::pushErrorHandling
676
+	 */
677
+	function popErrorHandling()
678
+	{
679
+		$stack = &$GLOBALS['_PEAR_error_handler_stack'];
680
+		array_pop($stack);
681
+		list($mode, $options) = $stack[sizeof($stack) - 1];
682
+		array_pop($stack);
683
+		if (isset($this) && is_a($this, 'PEAR')) {
684
+			$this->setErrorHandling($mode, $options);
685
+		} else {
686
+			PEAR::setErrorHandling($mode, $options);
687
+		}
688
+		return true;
689
+	}
690
+
691
+	/**
692
+	 * OS independent PHP extension load. Remember to take care
693
+	 * on the correct extension name for case sensitive OSes.
694
+	 *
695
+	 * @param string $ext The extension name
696
+	 * @return bool Success or not on the dl() call
697
+	 */
698
+	function loadExtension($ext)
699
+	{
700
+		if (extension_loaded($ext)) {
701
+			return true;
702
+		}
703
+
704
+		// if either returns true dl() will produce a FATAL error, stop that
705
+		if (
706
+			function_exists('dl') === false ||
707
+			ini_get('enable_dl') != 1 ||
708
+			ini_get('safe_mode') == 1
709
+		) {
710
+			return false;
711
+		}
712
+
713
+		if (OS_WINDOWS) {
714
+			$suffix = '.dll';
715
+		} elseif (PHP_OS == 'HP-UX') {
716
+			$suffix = '.sl';
717
+		} elseif (PHP_OS == 'AIX') {
718
+			$suffix = '.a';
719
+		} elseif (PHP_OS == 'OSX') {
720
+			$suffix = '.bundle';
721
+		} else {
722
+			$suffix = '.so';
723
+		}
724
+
725
+		return @dl('php_'.$ext.$suffix) || @dl($ext.$suffix);
726
+	}
727 727
 }
728 728
 
729 729
 if (PEAR_ZE2) {
730
-    include_once 'PEAR5.php';
730
+	include_once 'PEAR5.php';
731 731
 }
732 732
 
733 733
 function _PEAR_call_destructors()
734 734
 {
735
-    global $_PEAR_destructor_object_list;
736
-    if (is_array($_PEAR_destructor_object_list) &&
737
-        sizeof($_PEAR_destructor_object_list))
738
-    {
739
-        reset($_PEAR_destructor_object_list);
740
-        if (PEAR_ZE2) {
741
-            $destructLifoExists = PEAR5::getStaticProperty('PEAR', 'destructlifo');
742
-        } else {
743
-            $destructLifoExists = PEAR::getStaticProperty('PEAR', 'destructlifo');
744
-        }
745
-
746
-        if ($destructLifoExists) {
747
-            $_PEAR_destructor_object_list = array_reverse($_PEAR_destructor_object_list);
748
-        }
749
-
750
-        while (list($k, $objref) = each($_PEAR_destructor_object_list)) {
751
-            $classname = get_class($objref);
752
-            while ($classname) {
753
-                $destructor = "_$classname";
754
-                if (method_exists($objref, $destructor)) {
755
-                    $objref->$destructor();
756
-                    break;
757
-                } else {
758
-                    $classname = get_parent_class($classname);
759
-                }
760
-            }
761
-        }
762
-        // Empty the object list to ensure that destructors are
763
-        // not called more than once.
764
-        $_PEAR_destructor_object_list = array();
765
-    }
766
-
767
-    // Now call the shutdown functions
768
-    if (
769
-        isset($GLOBALS['_PEAR_shutdown_funcs']) &&
770
-        is_array($GLOBALS['_PEAR_shutdown_funcs']) &&
771
-        !empty($GLOBALS['_PEAR_shutdown_funcs'])
772
-    ) {
773
-        foreach ($GLOBALS['_PEAR_shutdown_funcs'] as $value) {
774
-            call_user_func_array($value[0], $value[1]);
775
-        }
776
-    }
735
+	global $_PEAR_destructor_object_list;
736
+	if (is_array($_PEAR_destructor_object_list) &&
737
+		sizeof($_PEAR_destructor_object_list))
738
+	{
739
+		reset($_PEAR_destructor_object_list);
740
+		if (PEAR_ZE2) {
741
+			$destructLifoExists = PEAR5::getStaticProperty('PEAR', 'destructlifo');
742
+		} else {
743
+			$destructLifoExists = PEAR::getStaticProperty('PEAR', 'destructlifo');
744
+		}
745
+
746
+		if ($destructLifoExists) {
747
+			$_PEAR_destructor_object_list = array_reverse($_PEAR_destructor_object_list);
748
+		}
749
+
750
+		while (list($k, $objref) = each($_PEAR_destructor_object_list)) {
751
+			$classname = get_class($objref);
752
+			while ($classname) {
753
+				$destructor = "_$classname";
754
+				if (method_exists($objref, $destructor)) {
755
+					$objref->$destructor();
756
+					break;
757
+				} else {
758
+					$classname = get_parent_class($classname);
759
+				}
760
+			}
761
+		}
762
+		// Empty the object list to ensure that destructors are
763
+		// not called more than once.
764
+		$_PEAR_destructor_object_list = array();
765
+	}
766
+
767
+	// Now call the shutdown functions
768
+	if (
769
+		isset($GLOBALS['_PEAR_shutdown_funcs']) &&
770
+		is_array($GLOBALS['_PEAR_shutdown_funcs']) &&
771
+		!empty($GLOBALS['_PEAR_shutdown_funcs'])
772
+	) {
773
+		foreach ($GLOBALS['_PEAR_shutdown_funcs'] as $value) {
774
+			call_user_func_array($value[0], $value[1]);
775
+		}
776
+	}
777 777
 }
778 778
 
779 779
 /**
@@ -795,263 +795,263 @@  discard block
 block discarded – undo
795 795
  */
796 796
 class PEAR_Error
797 797
 {
798
-    var $error_message_prefix = '';
799
-    var $mode                 = PEAR_ERROR_RETURN;
800
-    var $level                = E_USER_NOTICE;
801
-    var $code                 = -1;
802
-    var $message              = '';
803
-    var $userinfo             = '';
804
-    var $backtrace            = null;
805
-
806
-    /**
807
-     * PEAR_Error constructor
808
-     *
809
-     * @param string $message  message
810
-     *
811
-     * @param int $code     (optional) error code
812
-     *
813
-     * @param int $mode     (optional) error mode, one of: PEAR_ERROR_RETURN,
814
-     * PEAR_ERROR_PRINT, PEAR_ERROR_DIE, PEAR_ERROR_TRIGGER,
815
-     * PEAR_ERROR_CALLBACK or PEAR_ERROR_EXCEPTION
816
-     *
817
-     * @param mixed $options   (optional) error level, _OR_ in the case of
818
-     * PEAR_ERROR_CALLBACK, the callback function or object/method
819
-     * tuple.
820
-     *
821
-     * @param string $userinfo (optional) additional user/debug info
822
-     *
823
-     * @access public
824
-     *
825
-     */
826
-    function PEAR_Error($message = 'unknown error', $code = null,
827
-                        $mode = null, $options = null, $userinfo = null)
828
-    {
829
-        if ($mode === null) {
830
-            $mode = PEAR_ERROR_RETURN;
831
-        }
832
-        $this->message   = $message;
833
-        $this->code      = $code;
834
-        $this->mode      = $mode;
835
-        $this->userinfo  = $userinfo;
836
-
837
-        if (PEAR_ZE2) {
838
-            $skiptrace = PEAR5::getStaticProperty('PEAR_Error', 'skiptrace');
839
-        } else {
840
-            $skiptrace = PEAR::getStaticProperty('PEAR_Error', 'skiptrace');
841
-        }
842
-
843
-        if (!$skiptrace) {
844
-            $this->backtrace = debug_backtrace();
845
-            if (isset($this->backtrace[0]) && isset($this->backtrace[0]['object'])) {
846
-                unset($this->backtrace[0]['object']);
847
-            }
848
-        }
849
-
850
-        if ($mode & PEAR_ERROR_CALLBACK) {
851
-            $this->level = E_USER_NOTICE;
852
-            $this->callback = $options;
853
-        } else {
854
-            if ($options === null) {
855
-                $options = E_USER_NOTICE;
856
-            }
857
-
858
-            $this->level = $options;
859
-            $this->callback = null;
860
-        }
861
-
862
-        if ($this->mode & PEAR_ERROR_PRINT) {
863
-            if (is_null($options) || is_int($options)) {
864
-                $format = "%s";
865
-            } else {
866
-                $format = $options;
867
-            }
868
-
869
-            printf($format, $this->getMessage());
870
-        }
871
-
872
-        if ($this->mode & PEAR_ERROR_TRIGGER) {
873
-            trigger_error($this->getMessage(), $this->level);
874
-        }
875
-
876
-        if ($this->mode & PEAR_ERROR_DIE) {
877
-            $msg = $this->getMessage();
878
-            if (is_null($options) || is_int($options)) {
879
-                $format = "%s";
880
-                if (substr($msg, -1) != "\n") {
881
-                    $msg .= "\n";
882
-                }
883
-            } else {
884
-                $format = $options;
885
-            }
886
-            die(sprintf($format, $msg));
887
-        }
888
-
889
-        if ($this->mode & PEAR_ERROR_CALLBACK && is_callable($this->callback)) {
890
-            call_user_func($this->callback, $this);
891
-        }
892
-
893
-        if ($this->mode & PEAR_ERROR_EXCEPTION) {
894
-            trigger_error("PEAR_ERROR_EXCEPTION is obsolete, use class PEAR_Exception for exceptions", E_USER_WARNING);
895
-            eval('$e = new Exception($this->message, $this->code);throw($e);');
896
-        }
897
-    }
898
-
899
-    /**
900
-     * Get the error mode from an error object.
901
-     *
902
-     * @return int error mode
903
-     * @access public
904
-     */
905
-    function getMode()
906
-    {
907
-        return $this->mode;
908
-    }
909
-
910
-    /**
911
-     * Get the callback function/method from an error object.
912
-     *
913
-     * @return mixed callback function or object/method array
914
-     * @access public
915
-     */
916
-    function getCallback()
917
-    {
918
-        return $this->callback;
919
-    }
920
-
921
-    /**
922
-     * Get the error message from an error object.
923
-     *
924
-     * @return  string  full error message
925
-     * @access public
926
-     */
927
-    function getMessage()
928
-    {
929
-        return ($this->error_message_prefix . $this->message);
930
-    }
931
-
932
-    /**
933
-     * Get error code from an error object
934
-     *
935
-     * @return int error code
936
-     * @access public
937
-     */
938
-     function getCode()
939
-     {
940
-        return $this->code;
941
-     }
942
-
943
-    /**
944
-     * Get the name of this error/exception.
945
-     *
946
-     * @return string error/exception name (type)
947
-     * @access public
948
-     */
949
-    function getType()
950
-    {
951
-        return get_class($this);
952
-    }
953
-
954
-    /**
955
-     * Get additional user-supplied information.
956
-     *
957
-     * @return string user-supplied information
958
-     * @access public
959
-     */
960
-    function getUserInfo()
961
-    {
962
-        return $this->userinfo;
963
-    }
964
-
965
-    /**
966
-     * Get additional debug information supplied by the application.
967
-     *
968
-     * @return string debug information
969
-     * @access public
970
-     */
971
-    function getDebugInfo()
972
-    {
973
-        return $this->getUserInfo();
974
-    }
975
-
976
-    /**
977
-     * Get the call backtrace from where the error was generated.
978
-     * Supported with PHP 4.3.0 or newer.
979
-     *
980
-     * @param int $frame (optional) what frame to fetch
981
-     * @return array Backtrace, or NULL if not available.
982
-     * @access public
983
-     */
984
-    function getBacktrace($frame = null)
985
-    {
986
-        if (defined('PEAR_IGNORE_BACKTRACE')) {
987
-            return null;
988
-        }
989
-        if ($frame === null) {
990
-            return $this->backtrace;
991
-        }
992
-        return $this->backtrace[$frame];
993
-    }
994
-
995
-    function addUserInfo($info)
996
-    {
997
-        if (empty($this->userinfo)) {
998
-            $this->userinfo = $info;
999
-        } else {
1000
-            $this->userinfo .= " ** $info";
1001
-        }
1002
-    }
1003
-
1004
-    function __toString()
1005
-    {
1006
-        return $this->getMessage();
1007
-    }
1008
-
1009
-    /**
1010
-     * Make a string representation of this object.
1011
-     *
1012
-     * @return string a string with an object summary
1013
-     * @access public
1014
-     */
1015
-    function toString()
1016
-    {
1017
-        $modes = array();
1018
-        $levels = array(E_USER_NOTICE  => 'notice',
1019
-                        E_USER_WARNING => 'warning',
1020
-                        E_USER_ERROR   => 'error');
1021
-        if ($this->mode & PEAR_ERROR_CALLBACK) {
1022
-            if (is_array($this->callback)) {
1023
-                $callback = (is_object($this->callback[0]) ?
1024
-                    strtolower(get_class($this->callback[0])) :
1025
-                    $this->callback[0]) . '::' .
1026
-                    $this->callback[1];
1027
-            } else {
1028
-                $callback = $this->callback;
1029
-            }
1030
-            return sprintf('[%s: message="%s" code=%d mode=callback '.
1031
-                           'callback=%s prefix="%s" info="%s"]',
1032
-                           strtolower(get_class($this)), $this->message, $this->code,
1033
-                           $callback, $this->error_message_prefix,
1034
-                           $this->userinfo);
1035
-        }
1036
-        if ($this->mode & PEAR_ERROR_PRINT) {
1037
-            $modes[] = 'print';
1038
-        }
1039
-        if ($this->mode & PEAR_ERROR_TRIGGER) {
1040
-            $modes[] = 'trigger';
1041
-        }
1042
-        if ($this->mode & PEAR_ERROR_DIE) {
1043
-            $modes[] = 'die';
1044
-        }
1045
-        if ($this->mode & PEAR_ERROR_RETURN) {
1046
-            $modes[] = 'return';
1047
-        }
1048
-        return sprintf('[%s: message="%s" code=%d mode=%s level=%s '.
1049
-                       'prefix="%s" info="%s"]',
1050
-                       strtolower(get_class($this)), $this->message, $this->code,
1051
-                       implode("|", $modes), $levels[$this->level],
1052
-                       $this->error_message_prefix,
1053
-                       $this->userinfo);
1054
-    }
798
+	var $error_message_prefix = '';
799
+	var $mode                 = PEAR_ERROR_RETURN;
800
+	var $level                = E_USER_NOTICE;
801
+	var $code                 = -1;
802
+	var $message              = '';
803
+	var $userinfo             = '';
804
+	var $backtrace            = null;
805
+
806
+	/**
807
+	 * PEAR_Error constructor
808
+	 *
809
+	 * @param string $message  message
810
+	 *
811
+	 * @param int $code     (optional) error code
812
+	 *
813
+	 * @param int $mode     (optional) error mode, one of: PEAR_ERROR_RETURN,
814
+	 * PEAR_ERROR_PRINT, PEAR_ERROR_DIE, PEAR_ERROR_TRIGGER,
815
+	 * PEAR_ERROR_CALLBACK or PEAR_ERROR_EXCEPTION
816
+	 *
817
+	 * @param mixed $options   (optional) error level, _OR_ in the case of
818
+	 * PEAR_ERROR_CALLBACK, the callback function or object/method
819
+	 * tuple.
820
+	 *
821
+	 * @param string $userinfo (optional) additional user/debug info
822
+	 *
823
+	 * @access public
824
+	 *
825
+	 */
826
+	function PEAR_Error($message = 'unknown error', $code = null,
827
+						$mode = null, $options = null, $userinfo = null)
828
+	{
829
+		if ($mode === null) {
830
+			$mode = PEAR_ERROR_RETURN;
831
+		}
832
+		$this->message   = $message;
833
+		$this->code      = $code;
834
+		$this->mode      = $mode;
835
+		$this->userinfo  = $userinfo;
836
+
837
+		if (PEAR_ZE2) {
838
+			$skiptrace = PEAR5::getStaticProperty('PEAR_Error', 'skiptrace');
839
+		} else {
840
+			$skiptrace = PEAR::getStaticProperty('PEAR_Error', 'skiptrace');
841
+		}
842
+
843
+		if (!$skiptrace) {
844
+			$this->backtrace = debug_backtrace();
845
+			if (isset($this->backtrace[0]) && isset($this->backtrace[0]['object'])) {
846
+				unset($this->backtrace[0]['object']);
847
+			}
848
+		}
849
+
850
+		if ($mode & PEAR_ERROR_CALLBACK) {
851
+			$this->level = E_USER_NOTICE;
852
+			$this->callback = $options;
853
+		} else {
854
+			if ($options === null) {
855
+				$options = E_USER_NOTICE;
856
+			}
857
+
858
+			$this->level = $options;
859
+			$this->callback = null;
860
+		}
861
+
862
+		if ($this->mode & PEAR_ERROR_PRINT) {
863
+			if (is_null($options) || is_int($options)) {
864
+				$format = "%s";
865
+			} else {
866
+				$format = $options;
867
+			}
868
+
869
+			printf($format, $this->getMessage());
870
+		}
871
+
872
+		if ($this->mode & PEAR_ERROR_TRIGGER) {
873
+			trigger_error($this->getMessage(), $this->level);
874
+		}
875
+
876
+		if ($this->mode & PEAR_ERROR_DIE) {
877
+			$msg = $this->getMessage();
878
+			if (is_null($options) || is_int($options)) {
879
+				$format = "%s";
880
+				if (substr($msg, -1) != "\n") {
881
+					$msg .= "\n";
882
+				}
883
+			} else {
884
+				$format = $options;
885
+			}
886
+			die(sprintf($format, $msg));
887
+		}
888
+
889
+		if ($this->mode & PEAR_ERROR_CALLBACK && is_callable($this->callback)) {
890
+			call_user_func($this->callback, $this);
891
+		}
892
+
893
+		if ($this->mode & PEAR_ERROR_EXCEPTION) {
894
+			trigger_error("PEAR_ERROR_EXCEPTION is obsolete, use class PEAR_Exception for exceptions", E_USER_WARNING);
895
+			eval('$e = new Exception($this->message, $this->code);throw($e);');
896
+		}
897
+	}
898
+
899
+	/**
900
+	 * Get the error mode from an error object.
901
+	 *
902
+	 * @return int error mode
903
+	 * @access public
904
+	 */
905
+	function getMode()
906
+	{
907
+		return $this->mode;
908
+	}
909
+
910
+	/**
911
+	 * Get the callback function/method from an error object.
912
+	 *
913
+	 * @return mixed callback function or object/method array
914
+	 * @access public
915
+	 */
916
+	function getCallback()
917
+	{
918
+		return $this->callback;
919
+	}
920
+
921
+	/**
922
+	 * Get the error message from an error object.
923
+	 *
924
+	 * @return  string  full error message
925
+	 * @access public
926
+	 */
927
+	function getMessage()
928
+	{
929
+		return ($this->error_message_prefix . $this->message);
930
+	}
931
+
932
+	/**
933
+	 * Get error code from an error object
934
+	 *
935
+	 * @return int error code
936
+	 * @access public
937
+	 */
938
+	 function getCode()
939
+	 {
940
+		return $this->code;
941
+	 }
942
+
943
+	/**
944
+	 * Get the name of this error/exception.
945
+	 *
946
+	 * @return string error/exception name (type)
947
+	 * @access public
948
+	 */
949
+	function getType()
950
+	{
951
+		return get_class($this);
952
+	}
953
+
954
+	/**
955
+	 * Get additional user-supplied information.
956
+	 *
957
+	 * @return string user-supplied information
958
+	 * @access public
959
+	 */
960
+	function getUserInfo()
961
+	{
962
+		return $this->userinfo;
963
+	}
964
+
965
+	/**
966
+	 * Get additional debug information supplied by the application.
967
+	 *
968
+	 * @return string debug information
969
+	 * @access public
970
+	 */
971
+	function getDebugInfo()
972
+	{
973
+		return $this->getUserInfo();
974
+	}
975
+
976
+	/**
977
+	 * Get the call backtrace from where the error was generated.
978
+	 * Supported with PHP 4.3.0 or newer.
979
+	 *
980
+	 * @param int $frame (optional) what frame to fetch
981
+	 * @return array Backtrace, or NULL if not available.
982
+	 * @access public
983
+	 */
984
+	function getBacktrace($frame = null)
985
+	{
986
+		if (defined('PEAR_IGNORE_BACKTRACE')) {
987
+			return null;
988
+		}
989
+		if ($frame === null) {
990
+			return $this->backtrace;
991
+		}
992
+		return $this->backtrace[$frame];
993
+	}
994
+
995
+	function addUserInfo($info)
996
+	{
997
+		if (empty($this->userinfo)) {
998
+			$this->userinfo = $info;
999
+		} else {
1000
+			$this->userinfo .= " ** $info";
1001
+		}
1002
+	}
1003
+
1004
+	function __toString()
1005
+	{
1006
+		return $this->getMessage();
1007
+	}
1008
+
1009
+	/**
1010
+	 * Make a string representation of this object.
1011
+	 *
1012
+	 * @return string a string with an object summary
1013
+	 * @access public
1014
+	 */
1015
+	function toString()
1016
+	{
1017
+		$modes = array();
1018
+		$levels = array(E_USER_NOTICE  => 'notice',
1019
+						E_USER_WARNING => 'warning',
1020
+						E_USER_ERROR   => 'error');
1021
+		if ($this->mode & PEAR_ERROR_CALLBACK) {
1022
+			if (is_array($this->callback)) {
1023
+				$callback = (is_object($this->callback[0]) ?
1024
+					strtolower(get_class($this->callback[0])) :
1025
+					$this->callback[0]) . '::' .
1026
+					$this->callback[1];
1027
+			} else {
1028
+				$callback = $this->callback;
1029
+			}
1030
+			return sprintf('[%s: message="%s" code=%d mode=callback '.
1031
+						   'callback=%s prefix="%s" info="%s"]',
1032
+						   strtolower(get_class($this)), $this->message, $this->code,
1033
+						   $callback, $this->error_message_prefix,
1034
+						   $this->userinfo);
1035
+		}
1036
+		if ($this->mode & PEAR_ERROR_PRINT) {
1037
+			$modes[] = 'print';
1038
+		}
1039
+		if ($this->mode & PEAR_ERROR_TRIGGER) {
1040
+			$modes[] = 'trigger';
1041
+		}
1042
+		if ($this->mode & PEAR_ERROR_DIE) {
1043
+			$modes[] = 'die';
1044
+		}
1045
+		if ($this->mode & PEAR_ERROR_RETURN) {
1046
+			$modes[] = 'return';
1047
+		}
1048
+		return sprintf('[%s: message="%s" code=%d mode=%s level=%s '.
1049
+					   'prefix="%s" info="%s"]',
1050
+					   strtolower(get_class($this)), $this->message, $this->code,
1051
+					   implode("|", $modes), $levels[$this->level],
1052
+					   $this->error_message_prefix,
1053
+					   $this->userinfo);
1054
+	}
1055 1055
 }
1056 1056
 
1057 1057
 /*
Please login to merge, or discard this patch.
Spacing   +12 added lines, -13 removed lines patch added patch discarded remove patch
@@ -22,11 +22,11 @@  discard block
 block discarded – undo
22 22
 /**#@+
23 23
  * ERROR constants
24 24
  */
25
-define('PEAR_ERROR_RETURN',     1);
26
-define('PEAR_ERROR_PRINT',      2);
27
-define('PEAR_ERROR_TRIGGER',    4);
28
-define('PEAR_ERROR_DIE',        8);
29
-define('PEAR_ERROR_CALLBACK',  16);
25
+define('PEAR_ERROR_RETURN', 1);
26
+define('PEAR_ERROR_PRINT', 2);
27
+define('PEAR_ERROR_TRIGGER', 4);
28
+define('PEAR_ERROR_DIE', 8);
29
+define('PEAR_ERROR_CALLBACK', 16);
30 30
 /**
31 31
  * WARNING: obsolete
32 32
  * @deprecated
@@ -38,12 +38,12 @@  discard block
 block discarded – undo
38 38
 
39 39
 if (substr(PHP_OS, 0, 3) == 'WIN') {
40 40
     define('OS_WINDOWS', true);
41
-    define('OS_UNIX',    false);
42
-    define('PEAR_OS',    'Windows');
41
+    define('OS_UNIX', false);
42
+    define('PEAR_OS', 'Windows');
43 43
 } else {
44 44
     define('OS_WINDOWS', false);
45
-    define('OS_UNIX',    true);
46
-    define('PEAR_OS',    'Unix'); // blatant assumption
45
+    define('OS_UNIX', true);
46
+    define('PEAR_OS', 'Unix'); // blatant assumption
47 47
 }
48 48
 
49 49
 $GLOBALS['_PEAR_default_error_mode']     = PEAR_ERROR_RETURN;
@@ -415,7 +415,7 @@  discard block
 block discarded – undo
415 415
             // $error_code is a non-empty array here; we walk through it trying
416 416
             // to unset all values
417 417
             foreach ($error_code as $key => $error) {
418
-                $deleted =  $this->_checkDelExpect($error) ? true : false;
418
+                $deleted = $this->_checkDelExpect($error) ? true : false;
419 419
             }
420 420
 
421 421
             return $deleted ? true : PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME
@@ -926,7 +926,7 @@  discard block
 block discarded – undo
926 926
      */
927 927
     function getMessage()
928 928
     {
929
-        return ($this->error_message_prefix . $this->message);
929
+        return ($this->error_message_prefix.$this->message);
930 930
     }
931 931
 
932 932
     /**
@@ -1021,8 +1021,7 @@  discard block
 block discarded – undo
1021 1021
         if ($this->mode & PEAR_ERROR_CALLBACK) {
1022 1022
             if (is_array($this->callback)) {
1023 1023
                 $callback = (is_object($this->callback[0]) ?
1024
-                    strtolower(get_class($this->callback[0])) :
1025
-                    $this->callback[0]) . '::' .
1024
+                    strtolower(get_class($this->callback[0])) : $this->callback[0]).'::'.
1026 1025
                     $this->callback[1];
1027 1026
             } else {
1028 1027
                 $callback = $this->callback;
Please login to merge, or discard this patch.
classes/security/phphtmlparser/src/html2text.inc 4 patches
Indentation   +182 added lines, -182 removed lines patch added patch discarded remove patch
@@ -18,197 +18,197 @@
 block discarded – undo
18 18
  */
19 19
 class Html2Text {
20 20
 
21
-    // Private fields
21
+	// Private fields
22 22
   
23
-    var $iCurrentLine = "";
24
-    var $iCurrentWord = "";
25
-    var $iCurrentWordArray;
26
-    var $iCurrentWordIndex;
27
-    var $iInScript;
28
-    var $iListLevel = 0;
29
-    var $iHtmlText;
30
-    var $iMaxColumns;
31
-    var $iHtmlParser;
23
+	var $iCurrentLine = "";
24
+	var $iCurrentWord = "";
25
+	var $iCurrentWordArray;
26
+	var $iCurrentWordIndex;
27
+	var $iInScript;
28
+	var $iListLevel = 0;
29
+	var $iHtmlText;
30
+	var $iMaxColumns;
31
+	var $iHtmlParser;
32 32
 
33
-    // Constants
33
+	// Constants
34 34
 
35
-    var $TOKEN_BR       = 0;
36
-    var $TOKEN_P        = 1;
37
-    var $TOKEN_LI       = 2;
38
-    var $TOKEN_AFTERLI  = 3;
39
-    var $TOKEN_UL       = 4;
40
-    var $TOKEN_ENDUL    = 5;
35
+	var $TOKEN_BR       = 0;
36
+	var $TOKEN_P        = 1;
37
+	var $TOKEN_LI       = 2;
38
+	var $TOKEN_AFTERLI  = 3;
39
+	var $TOKEN_UL       = 4;
40
+	var $TOKEN_ENDUL    = 5;
41 41
    
42
-    function Html2Text ($aHtmlText, $aMaxColumns) {
43
-        $this->iHtmlText = $aHtmlText;
44
-        $this->iMaxColumns = $aMaxColumns;
45
-    }
42
+	function Html2Text ($aHtmlText, $aMaxColumns) {
43
+		$this->iHtmlText = $aHtmlText;
44
+		$this->iMaxColumns = $aMaxColumns;
45
+	}
46 46
 
47
-    function convert() {
48
-        $this->iHtmlParser = new HtmlParser($this->iHtmlText);
49
-        $wholeText = "";
50
-        while (($line = $this->getLine()) !== false) {
51
-            $wholeText .= ($line . "\r\n");
52
-        }
53
-        return $wholeText;
54
-    }
47
+	function convert() {
48
+		$this->iHtmlParser = new HtmlParser($this->iHtmlText);
49
+		$wholeText = "";
50
+		while (($line = $this->getLine()) !== false) {
51
+			$wholeText .= ($line . "\r\n");
52
+		}
53
+		return $wholeText;
54
+	}
55 55
 
56
-    function getLine() {
57
-        while (true) {
58
-            if (!$this->addWordToLine($this->iCurrentWord)) {
59
-                $retvalue = $this->iCurrentLine;
60
-                $this->iCurrentLine = "";
61
-                return $retvalue;
62
-            }                
63
-            $word = $this->getWord();
64
-            if ($word === false) {
65
-                if ($this->iCurrentLine == "") {
66
-                    break;
67
-                }
68
-                $retvalue = $this->iCurrentLine;
69
-                $this->iCurrentLine = "";
70
-                $this->iInText = false;
71
-                $this->iCurrentWord = "";
72
-                return $retvalue;                
73
-            }
74
-        }
75
-        return false;
76
-    }
56
+	function getLine() {
57
+		while (true) {
58
+			if (!$this->addWordToLine($this->iCurrentWord)) {
59
+				$retvalue = $this->iCurrentLine;
60
+				$this->iCurrentLine = "";
61
+				return $retvalue;
62
+			}                
63
+			$word = $this->getWord();
64
+			if ($word === false) {
65
+				if ($this->iCurrentLine == "") {
66
+					break;
67
+				}
68
+				$retvalue = $this->iCurrentLine;
69
+				$this->iCurrentLine = "";
70
+				$this->iInText = false;
71
+				$this->iCurrentWord = "";
72
+				return $retvalue;                
73
+			}
74
+		}
75
+		return false;
76
+	}
77 77
 
78
-    function addWordToLine ($word) {
79
-        if ($this->iInScript) {
80
-            return true;
81
-        }
82
-        $prevLine = $this->iCurrentLine;
83
-        if ($word === $this->TOKEN_BR) {
84
-            $this->iCurrentWord = "";
85
-            return false;
86
-        }
87
-        if ($word === $this->TOKEN_P) {
88
-            $this->iCurrentWord = $this->TOKEN_BR;
89
-            return false;
90
-        }
91
-        if ($word === $this->TOKEN_UL) {
92
-            $this->iCurrentWord = $this->TOKEN_BR;
93
-            return false;
94
-        }
95
-        if ($word === $this->TOKEN_ENDUL) {
96
-            $this->iCurrentWord = $this->TOKEN_BR;
97
-            return false;
98
-        }
99
-        if ($word === $this->TOKEN_LI) {
100
-            $this->iCurrentWord = $this->TOKEN_AFTERLI;
101
-            return false;
102
-        }
103
-        $toAdd = $word;
104
-        if ($word === $this->TOKEN_AFTERLI) {
105
-            $toAdd = "";
106
-        }
107
-        if ($prevLine != "") {
108
-            $prevLine .= " ";
109
-        }
110
-        else {
111
-            $prevLine = $this->getIndentation($word === $this->TOKEN_AFTERLI);
112
-        }
113
-        $candidateLine = $prevLine . $toAdd;
114
-        if (strlen ($candidateLine) > $this->iMaxColumns && $prevLine != "") {
115
-            return false;
116
-        }
117
-        $this->iCurrentLine = $candidateLine;
118
-        return true;
119
-    }
78
+	function addWordToLine ($word) {
79
+		if ($this->iInScript) {
80
+			return true;
81
+		}
82
+		$prevLine = $this->iCurrentLine;
83
+		if ($word === $this->TOKEN_BR) {
84
+			$this->iCurrentWord = "";
85
+			return false;
86
+		}
87
+		if ($word === $this->TOKEN_P) {
88
+			$this->iCurrentWord = $this->TOKEN_BR;
89
+			return false;
90
+		}
91
+		if ($word === $this->TOKEN_UL) {
92
+			$this->iCurrentWord = $this->TOKEN_BR;
93
+			return false;
94
+		}
95
+		if ($word === $this->TOKEN_ENDUL) {
96
+			$this->iCurrentWord = $this->TOKEN_BR;
97
+			return false;
98
+		}
99
+		if ($word === $this->TOKEN_LI) {
100
+			$this->iCurrentWord = $this->TOKEN_AFTERLI;
101
+			return false;
102
+		}
103
+		$toAdd = $word;
104
+		if ($word === $this->TOKEN_AFTERLI) {
105
+			$toAdd = "";
106
+		}
107
+		if ($prevLine != "") {
108
+			$prevLine .= " ";
109
+		}
110
+		else {
111
+			$prevLine = $this->getIndentation($word === $this->TOKEN_AFTERLI);
112
+		}
113
+		$candidateLine = $prevLine . $toAdd;
114
+		if (strlen ($candidateLine) > $this->iMaxColumns && $prevLine != "") {
115
+			return false;
116
+		}
117
+		$this->iCurrentLine = $candidateLine;
118
+		return true;
119
+	}
120 120
 
121
-    function getWord() {
122
-        while (true) {
123
-            if ($this->iHtmlParser->iNodeType == NODE_TYPE_TEXT) {
124
-                if (!$this->iInText) {
125
-                    $words = $this->splitWords($this->iHtmlParser->iNodeValue);
126
-                    $this->iCurrentWordArray = $words;
127
-                    $this->iCurrentWordIndex = 0;
128
-                    $this->iInText = true;
129
-                }
130
-                if ($this->iCurrentWordIndex < count($this->iCurrentWordArray)) {
131
-                    $this->iCurrentWord = $this->iCurrentWordArray[$this->iCurrentWordIndex++];
132
-                    return $this->iCurrentWord;
133
-                }
134
-                else {
135
-                    $this->iInText = false;
136
-                }
137
-            }
138
-            else if ($this->iHtmlParser->iNodeType == NODE_TYPE_ELEMENT) {
139
-                if (strcasecmp ($this->iHtmlParser->iNodeName, "br") == 0) {
140
-                    $this->iHtmlParser->parse();
141
-                    $this->iCurrentWord = $this->TOKEN_BR;
142
-                    return $this->iCurrentWord;
143
-                }
144
-                else if (strcasecmp ($this->iHtmlParser->iNodeName, "p") == 0) {
145
-                    $this->iHtmlParser->parse();
146
-                    $this->iCurrentWord = $this->TOKEN_P;
147
-                    return $this->iCurrentWord;
148
-                }
149
-                else if (strcasecmp ($this->iHtmlParser->iNodeName, "script") == 0) {
150
-                    $this->iHtmlParser->parse();
151
-                    $this->iCurrentWord = "";
152
-                    $this->iInScript = true;
153
-                    return $this->iCurrentWord;
154
-                }
155
-                else if (strcasecmp ($this->iHtmlParser->iNodeName, "ul") == 0 || strcasecmp ($this->iHtmlParser->iNodeName, "ol") == 0) {
156
-                    $this->iHtmlParser->parse();
157
-                    $this->iCurrentWord = $this->TOKEN_UL;
158
-                    $this->iListLevel++;
159
-                    return $this->iCurrentWord;
160
-                }
161
-                else if (strcasecmp ($this->iHtmlParser->iNodeName, "li") == 0) {
162
-                    $this->iHtmlParser->parse();
163
-                    $this->iCurrentWord = $this->TOKEN_LI;
164
-                    return $this->iCurrentWord;
165
-                }
166
-            }
167
-            else if ($this->iHtmlParser->iNodeType == NODE_TYPE_ENDELEMENT) {
168
-                if (strcasecmp ($this->iHtmlParser->iNodeName, "script") == 0) {
169
-                    $this->iHtmlParser->parse();
170
-                    $this->iCurrentWord = "";
171
-                    $this->iInScript = false;
172
-                    return $this->iCurrentWord;
173
-                }
174
-                else if (strcasecmp ($this->iHtmlParser->iNodeName, "ul") == 0 || strcasecmp ($this->iHtmlParser->iNodeName, "ol") == 0) {
175
-                    $this->iHtmlParser->parse();
176
-                    $this->iCurrentWord = $this->TOKEN_ENDUL;
177
-                    if ($this->iListLevel > 0) {
178
-                        $this->iListLevel--;
179
-                    }
180
-                    return $this->iCurrentWord;
181
-                }
182
-            }
183
-            if (!$this->iHtmlParser->parse()) {
184
-                break;
185
-            }
186
-        }
187
-        return false;
188
-    }
121
+	function getWord() {
122
+		while (true) {
123
+			if ($this->iHtmlParser->iNodeType == NODE_TYPE_TEXT) {
124
+				if (!$this->iInText) {
125
+					$words = $this->splitWords($this->iHtmlParser->iNodeValue);
126
+					$this->iCurrentWordArray = $words;
127
+					$this->iCurrentWordIndex = 0;
128
+					$this->iInText = true;
129
+				}
130
+				if ($this->iCurrentWordIndex < count($this->iCurrentWordArray)) {
131
+					$this->iCurrentWord = $this->iCurrentWordArray[$this->iCurrentWordIndex++];
132
+					return $this->iCurrentWord;
133
+				}
134
+				else {
135
+					$this->iInText = false;
136
+				}
137
+			}
138
+			else if ($this->iHtmlParser->iNodeType == NODE_TYPE_ELEMENT) {
139
+				if (strcasecmp ($this->iHtmlParser->iNodeName, "br") == 0) {
140
+					$this->iHtmlParser->parse();
141
+					$this->iCurrentWord = $this->TOKEN_BR;
142
+					return $this->iCurrentWord;
143
+				}
144
+				else if (strcasecmp ($this->iHtmlParser->iNodeName, "p") == 0) {
145
+					$this->iHtmlParser->parse();
146
+					$this->iCurrentWord = $this->TOKEN_P;
147
+					return $this->iCurrentWord;
148
+				}
149
+				else if (strcasecmp ($this->iHtmlParser->iNodeName, "script") == 0) {
150
+					$this->iHtmlParser->parse();
151
+					$this->iCurrentWord = "";
152
+					$this->iInScript = true;
153
+					return $this->iCurrentWord;
154
+				}
155
+				else if (strcasecmp ($this->iHtmlParser->iNodeName, "ul") == 0 || strcasecmp ($this->iHtmlParser->iNodeName, "ol") == 0) {
156
+					$this->iHtmlParser->parse();
157
+					$this->iCurrentWord = $this->TOKEN_UL;
158
+					$this->iListLevel++;
159
+					return $this->iCurrentWord;
160
+				}
161
+				else if (strcasecmp ($this->iHtmlParser->iNodeName, "li") == 0) {
162
+					$this->iHtmlParser->parse();
163
+					$this->iCurrentWord = $this->TOKEN_LI;
164
+					return $this->iCurrentWord;
165
+				}
166
+			}
167
+			else if ($this->iHtmlParser->iNodeType == NODE_TYPE_ENDELEMENT) {
168
+				if (strcasecmp ($this->iHtmlParser->iNodeName, "script") == 0) {
169
+					$this->iHtmlParser->parse();
170
+					$this->iCurrentWord = "";
171
+					$this->iInScript = false;
172
+					return $this->iCurrentWord;
173
+				}
174
+				else if (strcasecmp ($this->iHtmlParser->iNodeName, "ul") == 0 || strcasecmp ($this->iHtmlParser->iNodeName, "ol") == 0) {
175
+					$this->iHtmlParser->parse();
176
+					$this->iCurrentWord = $this->TOKEN_ENDUL;
177
+					if ($this->iListLevel > 0) {
178
+						$this->iListLevel--;
179
+					}
180
+					return $this->iCurrentWord;
181
+				}
182
+			}
183
+			if (!$this->iHtmlParser->parse()) {
184
+				break;
185
+			}
186
+		}
187
+		return false;
188
+	}
189 189
 
190
-    function splitWords ($text) {
191
-        $words = split ("[ \t\r\n]+", $text);
192
-        for ($idx = 0; $idx < count($words); $idx++) {
193
-            $words[$idx] = $this->htmlDecode($words[$idx]);
194
-        }
195
-        return $words;
196
-    }
190
+	function splitWords ($text) {
191
+		$words = split ("[ \t\r\n]+", $text);
192
+		for ($idx = 0; $idx < count($words); $idx++) {
193
+			$words[$idx] = $this->htmlDecode($words[$idx]);
194
+		}
195
+		return $words;
196
+	}
197 197
 
198
-    function htmlDecode ($text) {
199
-        // TBD
200
-        return $text;
201
-    } 
198
+	function htmlDecode ($text) {
199
+		// TBD
200
+		return $text;
201
+	} 
202 202
 
203
-    function getIndentation ($hasLI) {
204
-        $indent = "";
205
-        $idx = 0;
206
-        for ($idx = 0; $idx < ($this->iListLevel - 1); $idx++) {
207
-            $indent .= "  ";
208
-        }
209
-        if ($this->iListLevel > 0) {
210
-            $indent = $hasLI ? ($indent . "- ") : ($indent . "  ");
211
-        }
212
-        return $indent;
213
-    }
203
+	function getIndentation ($hasLI) {
204
+		$indent = "";
205
+		$idx = 0;
206
+		for ($idx = 0; $idx < ($this->iListLevel - 1); $idx++) {
207
+			$indent .= "  ";
208
+		}
209
+		if ($this->iListLevel > 0) {
210
+			$indent = $hasLI ? ($indent . "- ") : ($indent . "  ");
211
+		}
212
+		return $indent;
213
+	}
214 214
 }
Please login to merge, or discard this patch.
Braces   +9 added lines, -18 removed lines patch added patch discarded remove patch
@@ -106,8 +106,7 @@  discard block
 block discarded – undo
106 106
         }
107 107
         if ($prevLine != "") {
108 108
             $prevLine .= " ";
109
-        }
110
-        else {
109
+        } else {
111 110
             $prevLine = $this->getIndentation($word === $this->TOKEN_AFTERLI);
112 111
         }
113 112
         $candidateLine = $prevLine . $toAdd;
@@ -130,48 +129,40 @@  discard block
 block discarded – undo
130 129
                 if ($this->iCurrentWordIndex < count($this->iCurrentWordArray)) {
131 130
                     $this->iCurrentWord = $this->iCurrentWordArray[$this->iCurrentWordIndex++];
132 131
                     return $this->iCurrentWord;
133
-                }
134
-                else {
132
+                } else {
135 133
                     $this->iInText = false;
136 134
                 }
137
-            }
138
-            else if ($this->iHtmlParser->iNodeType == NODE_TYPE_ELEMENT) {
135
+            } else if ($this->iHtmlParser->iNodeType == NODE_TYPE_ELEMENT) {
139 136
                 if (strcasecmp ($this->iHtmlParser->iNodeName, "br") == 0) {
140 137
                     $this->iHtmlParser->parse();
141 138
                     $this->iCurrentWord = $this->TOKEN_BR;
142 139
                     return $this->iCurrentWord;
143
-                }
144
-                else if (strcasecmp ($this->iHtmlParser->iNodeName, "p") == 0) {
140
+                } else if (strcasecmp ($this->iHtmlParser->iNodeName, "p") == 0) {
145 141
                     $this->iHtmlParser->parse();
146 142
                     $this->iCurrentWord = $this->TOKEN_P;
147 143
                     return $this->iCurrentWord;
148
-                }
149
-                else if (strcasecmp ($this->iHtmlParser->iNodeName, "script") == 0) {
144
+                } else if (strcasecmp ($this->iHtmlParser->iNodeName, "script") == 0) {
150 145
                     $this->iHtmlParser->parse();
151 146
                     $this->iCurrentWord = "";
152 147
                     $this->iInScript = true;
153 148
                     return $this->iCurrentWord;
154
-                }
155
-                else if (strcasecmp ($this->iHtmlParser->iNodeName, "ul") == 0 || strcasecmp ($this->iHtmlParser->iNodeName, "ol") == 0) {
149
+                } else if (strcasecmp ($this->iHtmlParser->iNodeName, "ul") == 0 || strcasecmp ($this->iHtmlParser->iNodeName, "ol") == 0) {
156 150
                     $this->iHtmlParser->parse();
157 151
                     $this->iCurrentWord = $this->TOKEN_UL;
158 152
                     $this->iListLevel++;
159 153
                     return $this->iCurrentWord;
160
-                }
161
-                else if (strcasecmp ($this->iHtmlParser->iNodeName, "li") == 0) {
154
+                } else if (strcasecmp ($this->iHtmlParser->iNodeName, "li") == 0) {
162 155
                     $this->iHtmlParser->parse();
163 156
                     $this->iCurrentWord = $this->TOKEN_LI;
164 157
                     return $this->iCurrentWord;
165 158
                 }
166
-            }
167
-            else if ($this->iHtmlParser->iNodeType == NODE_TYPE_ENDELEMENT) {
159
+            } else if ($this->iHtmlParser->iNodeType == NODE_TYPE_ENDELEMENT) {
168 160
                 if (strcasecmp ($this->iHtmlParser->iNodeName, "script") == 0) {
169 161
                     $this->iHtmlParser->parse();
170 162
                     $this->iCurrentWord = "";
171 163
                     $this->iInScript = false;
172 164
                     return $this->iCurrentWord;
173
-                }
174
-                else if (strcasecmp ($this->iHtmlParser->iNodeName, "ul") == 0 || strcasecmp ($this->iHtmlParser->iNodeName, "ol") == 0) {
165
+                } else if (strcasecmp ($this->iHtmlParser->iNodeName, "ul") == 0 || strcasecmp ($this->iHtmlParser->iNodeName, "ol") == 0) {
175 166
                     $this->iHtmlParser->parse();
176 167
                     $this->iCurrentWord = $this->TOKEN_ENDUL;
177 168
                     if ($this->iListLevel > 0) {
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
     var $TOKEN_UL       = 4;
40 40
     var $TOKEN_ENDUL    = 5;
41 41
    
42
-    function Html2Text ($aHtmlText, $aMaxColumns) {
42
+    function Html2Text($aHtmlText, $aMaxColumns) {
43 43
         $this->iHtmlText = $aHtmlText;
44 44
         $this->iMaxColumns = $aMaxColumns;
45 45
     }
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
         $this->iHtmlParser = new HtmlParser($this->iHtmlText);
49 49
         $wholeText = "";
50 50
         while (($line = $this->getLine()) !== false) {
51
-            $wholeText .= ($line . "\r\n");
51
+            $wholeText .= ($line."\r\n");
52 52
         }
53 53
         return $wholeText;
54 54
     }
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
         return false;
76 76
     }
77 77
 
78
-    function addWordToLine ($word) {
78
+    function addWordToLine($word) {
79 79
         if ($this->iInScript) {
80 80
             return true;
81 81
         }
@@ -110,8 +110,8 @@  discard block
 block discarded – undo
110 110
         else {
111 111
             $prevLine = $this->getIndentation($word === $this->TOKEN_AFTERLI);
112 112
         }
113
-        $candidateLine = $prevLine . $toAdd;
114
-        if (strlen ($candidateLine) > $this->iMaxColumns && $prevLine != "") {
113
+        $candidateLine = $prevLine.$toAdd;
114
+        if (strlen($candidateLine) > $this->iMaxColumns && $prevLine != "") {
115 115
             return false;
116 116
         }
117 117
         $this->iCurrentLine = $candidateLine;
@@ -136,42 +136,42 @@  discard block
 block discarded – undo
136 136
                 }
137 137
             }
138 138
             else if ($this->iHtmlParser->iNodeType == NODE_TYPE_ELEMENT) {
139
-                if (strcasecmp ($this->iHtmlParser->iNodeName, "br") == 0) {
139
+                if (strcasecmp($this->iHtmlParser->iNodeName, "br") == 0) {
140 140
                     $this->iHtmlParser->parse();
141 141
                     $this->iCurrentWord = $this->TOKEN_BR;
142 142
                     return $this->iCurrentWord;
143 143
                 }
144
-                else if (strcasecmp ($this->iHtmlParser->iNodeName, "p") == 0) {
144
+                else if (strcasecmp($this->iHtmlParser->iNodeName, "p") == 0) {
145 145
                     $this->iHtmlParser->parse();
146 146
                     $this->iCurrentWord = $this->TOKEN_P;
147 147
                     return $this->iCurrentWord;
148 148
                 }
149
-                else if (strcasecmp ($this->iHtmlParser->iNodeName, "script") == 0) {
149
+                else if (strcasecmp($this->iHtmlParser->iNodeName, "script") == 0) {
150 150
                     $this->iHtmlParser->parse();
151 151
                     $this->iCurrentWord = "";
152 152
                     $this->iInScript = true;
153 153
                     return $this->iCurrentWord;
154 154
                 }
155
-                else if (strcasecmp ($this->iHtmlParser->iNodeName, "ul") == 0 || strcasecmp ($this->iHtmlParser->iNodeName, "ol") == 0) {
155
+                else if (strcasecmp($this->iHtmlParser->iNodeName, "ul") == 0 || strcasecmp($this->iHtmlParser->iNodeName, "ol") == 0) {
156 156
                     $this->iHtmlParser->parse();
157 157
                     $this->iCurrentWord = $this->TOKEN_UL;
158 158
                     $this->iListLevel++;
159 159
                     return $this->iCurrentWord;
160 160
                 }
161
-                else if (strcasecmp ($this->iHtmlParser->iNodeName, "li") == 0) {
161
+                else if (strcasecmp($this->iHtmlParser->iNodeName, "li") == 0) {
162 162
                     $this->iHtmlParser->parse();
163 163
                     $this->iCurrentWord = $this->TOKEN_LI;
164 164
                     return $this->iCurrentWord;
165 165
                 }
166 166
             }
167 167
             else if ($this->iHtmlParser->iNodeType == NODE_TYPE_ENDELEMENT) {
168
-                if (strcasecmp ($this->iHtmlParser->iNodeName, "script") == 0) {
168
+                if (strcasecmp($this->iHtmlParser->iNodeName, "script") == 0) {
169 169
                     $this->iHtmlParser->parse();
170 170
                     $this->iCurrentWord = "";
171 171
                     $this->iInScript = false;
172 172
                     return $this->iCurrentWord;
173 173
                 }
174
-                else if (strcasecmp ($this->iHtmlParser->iNodeName, "ul") == 0 || strcasecmp ($this->iHtmlParser->iNodeName, "ol") == 0) {
174
+                else if (strcasecmp($this->iHtmlParser->iNodeName, "ul") == 0 || strcasecmp($this->iHtmlParser->iNodeName, "ol") == 0) {
175 175
                     $this->iHtmlParser->parse();
176 176
                     $this->iCurrentWord = $this->TOKEN_ENDUL;
177 177
                     if ($this->iListLevel > 0) {
@@ -187,27 +187,27 @@  discard block
 block discarded – undo
187 187
         return false;
188 188
     }
189 189
 
190
-    function splitWords ($text) {
191
-        $words = split ("[ \t\r\n]+", $text);
190
+    function splitWords($text) {
191
+        $words = split("[ \t\r\n]+", $text);
192 192
         for ($idx = 0; $idx < count($words); $idx++) {
193 193
             $words[$idx] = $this->htmlDecode($words[$idx]);
194 194
         }
195 195
         return $words;
196 196
     }
197 197
 
198
-    function htmlDecode ($text) {
198
+    function htmlDecode($text) {
199 199
         // TBD
200 200
         return $text;
201 201
     } 
202 202
 
203
-    function getIndentation ($hasLI) {
203
+    function getIndentation($hasLI) {
204 204
         $indent = "";
205 205
         $idx = 0;
206 206
         for ($idx = 0; $idx < ($this->iListLevel - 1); $idx++) {
207 207
             $indent .= "  ";
208 208
         }
209 209
         if ($this->iListLevel > 0) {
210
-            $indent = $hasLI ? ($indent . "- ") : ($indent . "  ");
210
+            $indent = $hasLI ? ($indent."- ") : ($indent."  ");
211 211
         }
212 212
         return $indent;
213 213
     }
Please login to merge, or discard this patch.
Doc Comments   +9 added lines patch added patch discarded remove patch
@@ -75,6 +75,9 @@  discard block
 block discarded – undo
75 75
         return false;
76 76
     }
77 77
 
78
+    /**
79
+     * @param string $word
80
+     */
78 81
     function addWordToLine ($word) {
79 82
         if ($this->iInScript) {
80 83
             return true;
@@ -187,6 +190,9 @@  discard block
 block discarded – undo
187 190
         return false;
188 191
     }
189 192
 
193
+    /**
194
+     * @param string $text
195
+     */
190 196
     function splitWords ($text) {
191 197
         $words = split ("[ \t\r\n]+", $text);
192 198
         for ($idx = 0; $idx < count($words); $idx++) {
@@ -200,6 +206,9 @@  discard block
 block discarded – undo
200 206
         return $text;
201 207
     } 
202 208
 
209
+    /**
210
+     * @param boolean $hasLI
211
+     */
203 212
     function getIndentation ($hasLI) {
204 213
         $indent = "";
205 214
         $idx = 0;
Please login to merge, or discard this patch.