@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | * A queue of responses to be returned by sendRequest() |
75 | 75 | * @var array |
76 | 76 | */ |
77 | - protected $responses = array(); |
|
77 | + protected $responses = array(); |
|
78 | 78 | |
79 | 79 | /** |
80 | 80 | * Returns the next response from the queue built by addResponse() |
@@ -86,23 +86,23 @@ discard block |
||
86 | 86 | * @return HTTP_Request2_Response |
87 | 87 | * @throws Exception |
88 | 88 | */ |
89 | - public function sendRequest(HTTP_Request2 $request) |
|
90 | - { |
|
91 | - if (count($this->responses) > 0) { |
|
92 | - $response = array_shift($this->responses); |
|
93 | - if ($response instanceof HTTP_Request2_Response) { |
|
94 | - return $response; |
|
95 | - } else { |
|
96 | - // rethrow the exception |
|
97 | - $class = get_class($response); |
|
98 | - $message = $response->getMessage(); |
|
99 | - $code = $response->getCode(); |
|
100 | - throw new $class($message, $code); |
|
101 | - } |
|
102 | - } else { |
|
103 | - return self::createResponseFromString("HTTP/1.1 400 Bad Request\r\n\r\n"); |
|
104 | - } |
|
105 | - } |
|
89 | + public function sendRequest(HTTP_Request2 $request) |
|
90 | + { |
|
91 | + if (count($this->responses) > 0) { |
|
92 | + $response = array_shift($this->responses); |
|
93 | + if ($response instanceof HTTP_Request2_Response) { |
|
94 | + return $response; |
|
95 | + } else { |
|
96 | + // rethrow the exception |
|
97 | + $class = get_class($response); |
|
98 | + $message = $response->getMessage(); |
|
99 | + $code = $response->getCode(); |
|
100 | + throw new $class($message, $code); |
|
101 | + } |
|
102 | + } else { |
|
103 | + return self::createResponseFromString("HTTP/1.1 400 Bad Request\r\n\r\n"); |
|
104 | + } |
|
105 | + } |
|
106 | 106 | |
107 | 107 | /** |
108 | 108 | * Adds response to the queue |
@@ -111,19 +111,19 @@ discard block |
||
111 | 111 | * an instance of HTTP_Request2_Response or Exception |
112 | 112 | * @throws HTTP_Request2_Exception |
113 | 113 | */ |
114 | - public function addResponse($response) |
|
115 | - { |
|
116 | - if (is_string($response)) { |
|
117 | - $response = self::createResponseFromString($response); |
|
118 | - } elseif (is_resource($response)) { |
|
119 | - $response = self::createResponseFromFile($response); |
|
120 | - } elseif (!$response instanceof HTTP_Request2_Response && |
|
121 | - !$response instanceof Exception |
|
122 | - ) { |
|
123 | - throw new HTTP_Request2_Exception('Parameter is not a valid response'); |
|
124 | - } |
|
125 | - $this->responses[] = $response; |
|
126 | - } |
|
114 | + public function addResponse($response) |
|
115 | + { |
|
116 | + if (is_string($response)) { |
|
117 | + $response = self::createResponseFromString($response); |
|
118 | + } elseif (is_resource($response)) { |
|
119 | + $response = self::createResponseFromFile($response); |
|
120 | + } elseif (!$response instanceof HTTP_Request2_Response && |
|
121 | + !$response instanceof Exception |
|
122 | + ) { |
|
123 | + throw new HTTP_Request2_Exception('Parameter is not a valid response'); |
|
124 | + } |
|
125 | + $this->responses[] = $response; |
|
126 | + } |
|
127 | 127 | |
128 | 128 | /** |
129 | 129 | * Creates a new HTTP_Request2_Response object from a string |
@@ -132,20 +132,20 @@ discard block |
||
132 | 132 | * @return HTTP_Request2_Response |
133 | 133 | * @throws HTTP_Request2_Exception |
134 | 134 | */ |
135 | - public static function createResponseFromString($str) |
|
136 | - { |
|
137 | - $parts = preg_split('!(\r?\n){2}!m', $str, 2); |
|
138 | - $headerLines = explode("\n", $parts[0]); |
|
139 | - $response = new HTTP_Request2_Response(array_shift($headerLines)); |
|
140 | - foreach ($headerLines as $headerLine) { |
|
141 | - $response->parseHeaderLine($headerLine); |
|
142 | - } |
|
143 | - $response->parseHeaderLine(''); |
|
144 | - if (isset($parts[1])) { |
|
145 | - $response->appendBody($parts[1]); |
|
146 | - } |
|
147 | - return $response; |
|
148 | - } |
|
135 | + public static function createResponseFromString($str) |
|
136 | + { |
|
137 | + $parts = preg_split('!(\r?\n){2}!m', $str, 2); |
|
138 | + $headerLines = explode("\n", $parts[0]); |
|
139 | + $response = new HTTP_Request2_Response(array_shift($headerLines)); |
|
140 | + foreach ($headerLines as $headerLine) { |
|
141 | + $response->parseHeaderLine($headerLine); |
|
142 | + } |
|
143 | + $response->parseHeaderLine(''); |
|
144 | + if (isset($parts[1])) { |
|
145 | + $response->appendBody($parts[1]); |
|
146 | + } |
|
147 | + return $response; |
|
148 | + } |
|
149 | 149 | |
150 | 150 | /** |
151 | 151 | * Creates a new HTTP_Request2_Response object from a file |
@@ -154,18 +154,18 @@ discard block |
||
154 | 154 | * @return HTTP_Request2_Response |
155 | 155 | * @throws HTTP_Request2_Exception |
156 | 156 | */ |
157 | - public static function createResponseFromFile($fp) |
|
158 | - { |
|
159 | - $response = new HTTP_Request2_Response(fgets($fp)); |
|
160 | - do { |
|
161 | - $headerLine = fgets($fp); |
|
162 | - $response->parseHeaderLine($headerLine); |
|
163 | - } while ('' != trim($headerLine)); |
|
157 | + public static function createResponseFromFile($fp) |
|
158 | + { |
|
159 | + $response = new HTTP_Request2_Response(fgets($fp)); |
|
160 | + do { |
|
161 | + $headerLine = fgets($fp); |
|
162 | + $response->parseHeaderLine($headerLine); |
|
163 | + } while ('' != trim($headerLine)); |
|
164 | 164 | |
165 | - while (!feof($fp)) { |
|
166 | - $response->appendBody(fread($fp, 8192)); |
|
167 | - } |
|
168 | - return $response; |
|
169 | - } |
|
165 | + while (!feof($fp)) { |
|
166 | + $response->appendBody(fread($fp, 8192)); |
|
167 | + } |
|
168 | + return $response; |
|
169 | + } |
|
170 | 170 | } |
171 | 171 | ?> |
172 | 172 | \ No newline at end of file |
@@ -7,14 +7,14 @@ |
||
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: '; |
@@ -6,14 +6,14 @@ |
||
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.'; |
@@ -36,58 +36,58 @@ |
||
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 | /** |
@@ -60,17 +60,17 @@ discard block |
||
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 |
||
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 |
||
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 | ?> |
@@ -62,19 +62,19 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
@@ -162,8 +162,8 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -34,16 +34,16 @@ discard block |
||
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 |
||
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 |
||
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 | /* |
@@ -22,11 +22,11 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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; |
@@ -64,7 +64,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 | ?> |
@@ -125,7 +125,7 @@ |
||
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 | } |
@@ -5,29 +5,29 @@ |
||
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 |
@@ -382,6 +382,9 @@ discard block |
||
382 | 382 | $this->setTemplateFile('layout_preview'); |
383 | 383 | } |
384 | 384 | |
385 | + /** |
|
386 | + * @return string |
|
387 | + */ |
|
385 | 388 | private function getRealLayoutFile($layoutSrl) |
386 | 389 | { |
387 | 390 | $oLayoutModel = getModel('layout'); |
@@ -398,6 +401,9 @@ discard block |
||
398 | 401 | |
399 | 402 | } |
400 | 403 | |
404 | + /** |
|
405 | + * @return string |
|
406 | + */ |
|
401 | 407 | private function getRealLayoutCSS($layoutSrl) |
402 | 408 | { |
403 | 409 | $oLayoutModel = getModel('layout'); |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | // Get the layout information |
26 | 26 | $oLayoutModel = getModel('layout'); |
27 | 27 | $layout_info = $oLayoutModel->getLayoutInfo(Context::get('selected_layout')); |
28 | - if(!$layout_info) exit(); |
|
28 | + if (!$layout_info) exit(); |
|
29 | 29 | Context::set('layout_info', $layout_info); |
30 | 30 | // Set the layout to be pop-up |
31 | 31 | $this->setLayoutFile('popup_layout'); |
@@ -53,13 +53,13 @@ discard block |
||
53 | 53 | // admin check |
54 | 54 | // this act is admin view but in normal view because do not load admin css/js files |
55 | 55 | $logged_info = Context::get('logged_info'); |
56 | - if($logged_info->is_admin != 'Y') |
|
56 | + if ($logged_info->is_admin != 'Y') |
|
57 | 57 | { |
58 | 58 | throw new Exception(Context::getLang('msg_invalid_request')); |
59 | 59 | } |
60 | 60 | |
61 | 61 | // if module is 'ARTiCLE' and from site design setting, make content directly |
62 | - if($module == 'ARTICLE' && !$mid) |
|
62 | + if ($module == 'ARTICLE' && !$mid) |
|
63 | 63 | { |
64 | 64 | $oDocumentModel = getModel('document'); |
65 | 65 | $oDocument = $oDocumentModel->getDocument(0, true); |
@@ -67,12 +67,12 @@ discard block |
||
67 | 67 | $t = Context::getLang('article_preview_title'); |
68 | 68 | |
69 | 69 | $c = ''; |
70 | - for($i = 0; $i < 4; $i++) |
|
70 | + for ($i = 0; $i < 4; $i++) |
|
71 | 71 | { |
72 | 72 | $c .= '<p>'; |
73 | - for($j = 0; $j < 20; $j++) |
|
73 | + for ($j = 0; $j < 20; $j++) |
|
74 | 74 | { |
75 | - $c .= Context::getLang('article_preview_content') . ' '; |
|
75 | + $c .= Context::getLang('article_preview_content').' '; |
|
76 | 76 | } |
77 | 77 | $c .= '</p>'; |
78 | 78 | } |
@@ -87,12 +87,12 @@ discard block |
||
87 | 87 | |
88 | 88 | if ($skinType == 'M') |
89 | 89 | { |
90 | - $templatePath = _XE_PATH_ . 'modules/page/m.skins/' . $skin; |
|
90 | + $templatePath = _XE_PATH_.'modules/page/m.skins/'.$skin; |
|
91 | 91 | $templateFile = 'mobile'; |
92 | 92 | } |
93 | 93 | else |
94 | 94 | { |
95 | - $templatePath = _XE_PATH_ . 'modules/page/skins/' . $skin; |
|
95 | + $templatePath = _XE_PATH_.'modules/page/skins/'.$skin; |
|
96 | 96 | $templateFile = 'content'; |
97 | 97 | } |
98 | 98 | |
@@ -108,15 +108,15 @@ discard block |
||
108 | 108 | Context::set('content', $content); |
109 | 109 | |
110 | 110 | // find layout |
111 | - if($layoutSrl) |
|
111 | + if ($layoutSrl) |
|
112 | 112 | { |
113 | - if($layoutSrl == -1) |
|
113 | + if ($layoutSrl == -1) |
|
114 | 114 | { |
115 | 115 | $site_srl = ($oModule) ? $oModule->module_info->site_srl : 0; |
116 | - $designInfoFile = sprintf(_XE_PATH_ . 'files/site_design/design_%s.php', $site_srl); |
|
116 | + $designInfoFile = sprintf(_XE_PATH_.'files/site_design/design_%s.php', $site_srl); |
|
117 | 117 | include($designInfoFile); |
118 | 118 | |
119 | - if($skinType == 'M') |
|
119 | + if ($skinType == 'M') |
|
120 | 120 | { |
121 | 121 | $layoutSrl = $designInfo->mlayout_srl; |
122 | 122 | } |
@@ -130,21 +130,21 @@ discard block |
||
130 | 130 | $layoutInfo = $oLayoutModel->getLayout($layoutSrl); |
131 | 131 | |
132 | 132 | // If there is no layout, pass it. |
133 | - if($layoutInfo) |
|
133 | + if ($layoutInfo) |
|
134 | 134 | { |
135 | 135 | // Adhoc... |
136 | 136 | |
137 | 137 | // Input extra_vars into $layout_info |
138 | - if($layoutInfo->extra_var_count) |
|
138 | + if ($layoutInfo->extra_var_count) |
|
139 | 139 | { |
140 | 140 | |
141 | - foreach($layoutInfo->extra_var as $var_id => $val) |
|
141 | + foreach ($layoutInfo->extra_var as $var_id => $val) |
|
142 | 142 | { |
143 | - if($val->type == 'image') |
|
143 | + if ($val->type == 'image') |
|
144 | 144 | { |
145 | - if(strncmp('./files/attach/images/', $val->value, 22) === 0) |
|
145 | + if (strncmp('./files/attach/images/', $val->value, 22) === 0) |
|
146 | 146 | { |
147 | - $val->value = Context::getRequestUri() . substr($val->value, 2); |
|
147 | + $val->value = Context::getRequestUri().substr($val->value, 2); |
|
148 | 148 | } |
149 | 149 | } |
150 | 150 | $layoutInfo->{$var_id} = $val->value; |
@@ -152,25 +152,25 @@ discard block |
||
152 | 152 | } |
153 | 153 | |
154 | 154 | // Set menus into context |
155 | - if($layoutInfo->menu_count) |
|
155 | + if ($layoutInfo->menu_count) |
|
156 | 156 | { |
157 | - foreach($layoutInfo->menu as $menu_id => $menu) |
|
157 | + foreach ($layoutInfo->menu as $menu_id => $menu) |
|
158 | 158 | { |
159 | 159 | // set default menu set(included home menu) |
160 | - if(!$menu->menu_srl || $menu->menu_srl == -1) |
|
160 | + if (!$menu->menu_srl || $menu->menu_srl == -1) |
|
161 | 161 | { |
162 | 162 | $oMenuAdminController = getAdminController('menu'); |
163 | 163 | $homeMenuCacheFile = $oMenuAdminController->getHomeMenuCacheFile(); |
164 | 164 | |
165 | - if(file_exists($homeMenuCacheFile)) |
|
165 | + if (file_exists($homeMenuCacheFile)) |
|
166 | 166 | { |
167 | 167 | include($homeMenuCacheFile); |
168 | 168 | } |
169 | 169 | |
170 | - if(!$menu->menu_srl) |
|
170 | + if (!$menu->menu_srl) |
|
171 | 171 | { |
172 | - $menu->xml_file = str_replace('.xml.php', $homeMenuSrl . '.xml.php', $menu->xml_file); |
|
173 | - $menu->php_file = str_replace('.php', $homeMenuSrl . '.php', $menu->php_file); |
|
172 | + $menu->xml_file = str_replace('.xml.php', $homeMenuSrl.'.xml.php', $menu->xml_file); |
|
173 | + $menu->php_file = str_replace('.php', $homeMenuSrl.'.php', $menu->php_file); |
|
174 | 174 | $layoutInfo->menu->{$menu_id}->menu_srl = $homeMenuSrl; |
175 | 175 | } |
176 | 176 | else |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | } |
182 | 182 | |
183 | 183 | $menu->php_file = FileHandler::getRealPath($menu->php_file); |
184 | - if(FileHandler::exists($menu->php_file)) |
|
184 | + if (FileHandler::exists($menu->php_file)) |
|
185 | 185 | { |
186 | 186 | include($menu->php_file); |
187 | 187 | } |
@@ -193,9 +193,9 @@ discard block |
||
193 | 193 | } |
194 | 194 | } |
195 | 195 | } |
196 | - catch(Exception $e) |
|
196 | + catch (Exception $e) |
|
197 | 197 | { |
198 | - $content = '<div class="message error"><p id="preview_error">' . $e->getMessage() . '</p></div>'; |
|
198 | + $content = '<div class="message error"><p id="preview_error">'.$e->getMessage().'</p></div>'; |
|
199 | 199 | Context::set('content', $content); |
200 | 200 | $layoutSrl = 0; |
201 | 201 | } |
@@ -204,12 +204,12 @@ discard block |
||
204 | 204 | $oTemplate = TemplateHandler::getInstance(); |
205 | 205 | Context::clearHtmlHeader(); |
206 | 206 | |
207 | - if($layoutInfo) |
|
207 | + if ($layoutInfo) |
|
208 | 208 | { |
209 | 209 | $layout_path = $layoutInfo->path; |
210 | 210 | $editLayoutTPL = $this->getRealLayoutFile($layoutSrl); |
211 | 211 | $editLayoutCSS = $this->getRealLayoutCSS($layoutSrl); |
212 | - if($editLayoutCSS != '') |
|
212 | + if ($editLayoutCSS != '') |
|
213 | 213 | { |
214 | 214 | Context::addCSSFile($editLayoutCSS); |
215 | 215 | } |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | } |
226 | 226 | |
227 | 227 | $layout_tpl = $oTemplate->compile($layout_path, $layout_file, $editLayoutTPL); |
228 | - Context::set('layout','none'); |
|
228 | + Context::set('layout', 'none'); |
|
229 | 229 | |
230 | 230 | // Convert widgets and others |
231 | 231 | $oContext = Context::getInstance(); |
@@ -246,18 +246,18 @@ discard block |
||
246 | 246 | private function procRealModule($module, $mid, $skin, $skinType) |
247 | 247 | { |
248 | 248 | // if form site design and preview module, find target module |
249 | - if($module && !$mid) |
|
249 | + if ($module && !$mid) |
|
250 | 250 | { |
251 | 251 | $args = new stdClass(); |
252 | 252 | $args->module = $module; |
253 | 253 | $output = executeQuery('layout.getOneModuleInstanceByModuleName', $args); |
254 | - if(!$output->toBool()) |
|
254 | + if (!$output->toBool()) |
|
255 | 255 | { |
256 | 256 | throw new Exception($output->getMessage()); |
257 | 257 | } |
258 | 258 | |
259 | 259 | // if there is no module instance, error... |
260 | - if(!$output->data) |
|
260 | + if (!$output->data) |
|
261 | 261 | { |
262 | 262 | throw new Exception(Context::getLang('msg_unabled_preview')); |
263 | 263 | } |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | } |
267 | 267 | |
268 | 268 | // if form site design and preview layout, find start module |
269 | - elseif(!$module && !$mid) |
|
269 | + elseif (!$module && !$mid) |
|
270 | 270 | { |
271 | 271 | $oModuleModel = getModel('module'); |
272 | 272 | $columnList = array('modules.mid', 'sites.index_module_srl'); |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | $oModuleHandler->module_info->is_skin_fix = 'Y'; |
287 | 287 | $oModuleHandler->module_info->is_mskin_fix = 'Y'; |
288 | 288 | |
289 | - if($skinType == 'M') |
|
289 | + if ($skinType == 'M') |
|
290 | 290 | { |
291 | 291 | Mobile::setMobile(TRUE); |
292 | 292 | $oModuleHandler->module_info->mskin = $skin; |
@@ -299,13 +299,13 @@ discard block |
||
299 | 299 | |
300 | 300 | // Proc module |
301 | 301 | $oModule = $oModuleHandler->procModule(); |
302 | - if(!$oModule->toBool()) |
|
302 | + if (!$oModule->toBool()) |
|
303 | 303 | { |
304 | 304 | throw new Exception(Context::getLang('not_support_layout_preview')); |
305 | 305 | } |
306 | 306 | |
307 | 307 | // get module html |
308 | - require_once(_XE_PATH_ . "classes/display/HTMLDisplayHandler.php"); |
|
308 | + require_once(_XE_PATH_."classes/display/HTMLDisplayHandler.php"); |
|
309 | 309 | $handler = new HTMLDisplayHandler(); |
310 | 310 | return $handler->toDoc($oModule); |
311 | 311 | } |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | */ |
317 | 317 | function dispLayoutPreview() |
318 | 318 | { |
319 | - if(!checkCSRF()) |
|
319 | + if (!checkCSRF()) |
|
320 | 320 | { |
321 | 321 | $this->stop('msg_invalid_request'); |
322 | 322 | return new BaseObject(-1, 'msg_invalid_request'); |
@@ -325,36 +325,36 @@ discard block |
||
325 | 325 | // admin check |
326 | 326 | // this act is admin view but in normal view because do not load admin css/js files |
327 | 327 | $logged_info = Context::get('logged_info'); |
328 | - if($logged_info->is_admin != 'Y') return $this->stop('msg_invalid_request'); |
|
328 | + if ($logged_info->is_admin != 'Y') return $this->stop('msg_invalid_request'); |
|
329 | 329 | |
330 | 330 | $layout_srl = Context::get('layout_srl'); |
331 | 331 | $code = Context::get('code'); |
332 | 332 | |
333 | 333 | $code_css = Context::get('code_css'); |
334 | - if(!$layout_srl || !$code) return new BaseObject(-1, 'msg_invalid_request'); |
|
334 | + if (!$layout_srl || !$code) return new BaseObject(-1, 'msg_invalid_request'); |
|
335 | 335 | // Get the layout information |
336 | 336 | $oLayoutModel = getModel('layout'); |
337 | 337 | $layout_info = $oLayoutModel->getLayout($layout_srl); |
338 | - if(!$layout_info) return new BaseObject(-1, 'msg_invalid_request'); |
|
338 | + if (!$layout_info) return new BaseObject(-1, 'msg_invalid_request'); |
|
339 | 339 | // Separately handle the layout if its type is faceoff |
340 | - if($layout_info && $layout_info->type == 'faceoff') $oLayoutModel->doActivateFaceOff($layout_info); |
|
340 | + if ($layout_info && $layout_info->type == 'faceoff') $oLayoutModel->doActivateFaceOff($layout_info); |
|
341 | 341 | // Apply CSS directly |
342 | 342 | Context::addHtmlHeader("<style type=\"text/css\" charset=\"UTF-8\">".$code_css."</style>"); |
343 | 343 | // Set names and values of extra_vars to $layout_info |
344 | - if($layout_info->extra_var_count) |
|
344 | + if ($layout_info->extra_var_count) |
|
345 | 345 | { |
346 | - foreach($layout_info->extra_var as $var_id => $val) |
|
346 | + foreach ($layout_info->extra_var as $var_id => $val) |
|
347 | 347 | { |
348 | 348 | $layout_info->{$var_id} = $val->value; |
349 | 349 | } |
350 | 350 | } |
351 | 351 | // menu in layout information becomes an argument for Context:: set |
352 | - if($layout_info->menu_count) |
|
352 | + if ($layout_info->menu_count) |
|
353 | 353 | { |
354 | - foreach($layout_info->menu as $menu_id => $menu) |
|
354 | + foreach ($layout_info->menu as $menu_id => $menu) |
|
355 | 355 | { |
356 | 356 | $menu->php_file = FileHandler::getRealPath($menu->php_file); |
357 | - if(FileHandler::exists($menu->php_file)) include($menu->php_file); |
|
357 | + if (FileHandler::exists($menu->php_file)) include($menu->php_file); |
|
358 | 358 | |
359 | 359 | Context::set($menu_id, $menu); |
360 | 360 | } |
@@ -363,7 +363,7 @@ discard block |
||
363 | 363 | Context::set('layout_info', $layout_info); |
364 | 364 | Context::set('content', Context::getLang('layout_preview_content')); |
365 | 365 | // Temporary save the codes |
366 | - $edited_layout_file = _XE_PATH_ . 'files/cache/layout/tmp.tpl'; |
|
366 | + $edited_layout_file = _XE_PATH_.'files/cache/layout/tmp.tpl'; |
|
367 | 367 | FileHandler::writeFile($edited_layout_file, $code); |
368 | 368 | |
369 | 369 | // Compile |
@@ -373,7 +373,7 @@ discard block |
||
373 | 373 | $layout_file = 'layout'; |
374 | 374 | |
375 | 375 | $layout_tpl = $oTemplate->compile($layout_path, $layout_file, $edited_layout_file); |
376 | - Context::set('layout','none'); |
|
376 | + Context::set('layout', 'none'); |
|
377 | 377 | // Convert widgets and others |
378 | 378 | $oContext = &Context::getInstance(); |
379 | 379 | Context::set('layout_tpl', $layout_tpl); |
@@ -387,7 +387,7 @@ discard block |
||
387 | 387 | $oLayoutModel = getModel('layout'); |
388 | 388 | $layoutFile = $oLayoutModel->getUserLayoutHtml($layoutSrl); |
389 | 389 | |
390 | - if(file_exists($layoutFile)) |
|
390 | + if (file_exists($layoutFile)) |
|
391 | 391 | { |
392 | 392 | return $layoutFile; |
393 | 393 | } |
@@ -403,7 +403,7 @@ discard block |
||
403 | 403 | $oLayoutModel = getModel('layout'); |
404 | 404 | $cssFile = $oLayoutModel->getUserLayoutCss($layoutSrl); |
405 | 405 | |
406 | - if(file_exists($cssFile)) |
|
406 | + if (file_exists($cssFile)) |
|
407 | 407 | { |
408 | 408 | return $cssFile; |
409 | 409 | } |
@@ -25,7 +25,9 @@ discard block |
||
25 | 25 | // Get the layout information |
26 | 26 | $oLayoutModel = getModel('layout'); |
27 | 27 | $layout_info = $oLayoutModel->getLayoutInfo(Context::get('selected_layout')); |
28 | - if(!$layout_info) exit(); |
|
28 | + if(!$layout_info) { |
|
29 | + exit(); |
|
30 | + } |
|
29 | 31 | Context::set('layout_info', $layout_info); |
30 | 32 | // Set the layout to be pop-up |
31 | 33 | $this->setLayoutFile('popup_layout'); |
@@ -89,8 +91,7 @@ discard block |
||
89 | 91 | { |
90 | 92 | $templatePath = _XE_PATH_ . 'modules/page/m.skins/' . $skin; |
91 | 93 | $templateFile = 'mobile'; |
92 | - } |
|
93 | - else |
|
94 | + } else |
|
94 | 95 | { |
95 | 96 | $templatePath = _XE_PATH_ . 'modules/page/skins/' . $skin; |
96 | 97 | $templateFile = 'content'; |
@@ -119,8 +120,7 @@ discard block |
||
119 | 120 | if($skinType == 'M') |
120 | 121 | { |
121 | 122 | $layoutSrl = $designInfo->mlayout_srl; |
122 | - } |
|
123 | - else |
|
123 | + } else |
|
124 | 124 | { |
125 | 125 | $layoutSrl = $designInfo->layout_srl; |
126 | 126 | } |
@@ -172,8 +172,7 @@ discard block |
||
172 | 172 | $menu->xml_file = str_replace('.xml.php', $homeMenuSrl . '.xml.php', $menu->xml_file); |
173 | 173 | $menu->php_file = str_replace('.php', $homeMenuSrl . '.php', $menu->php_file); |
174 | 174 | $layoutInfo->menu->{$menu_id}->menu_srl = $homeMenuSrl; |
175 | - } |
|
176 | - else |
|
175 | + } else |
|
177 | 176 | { |
178 | 177 | $menu->xml_file = str_replace($menu->menu_srl, $homeMenuSrl, $menu->xml_file); |
179 | 178 | $menu->php_file = str_replace($menu->menu_srl, $homeMenuSrl, $menu->php_file); |
@@ -192,8 +191,7 @@ discard block |
||
192 | 191 | Context::set('layout_info', $layoutInfo); |
193 | 192 | } |
194 | 193 | } |
195 | - } |
|
196 | - catch(Exception $e) |
|
194 | + } catch(Exception $e) |
|
197 | 195 | { |
198 | 196 | $content = '<div class="message error"><p id="preview_error">' . $e->getMessage() . '</p></div>'; |
199 | 197 | Context::set('content', $content); |
@@ -217,8 +215,7 @@ discard block |
||
217 | 215 | $oModuleModel = getModel('module'); |
218 | 216 | $part_config = $oModuleModel->getModulePartConfig('layout', $layoutSrl); |
219 | 217 | Context::addHtmlHeader($part_config->header_script); |
220 | - } |
|
221 | - else |
|
218 | + } else |
|
222 | 219 | { |
223 | 220 | $layout_path = './common/tpl'; |
224 | 221 | $layout_file = 'default_layout'; |
@@ -290,8 +287,7 @@ discard block |
||
290 | 287 | { |
291 | 288 | Mobile::setMobile(TRUE); |
292 | 289 | $oModuleHandler->module_info->mskin = $skin; |
293 | - } |
|
294 | - else |
|
290 | + } else |
|
295 | 291 | { |
296 | 292 | Mobile::setMobile(FALSE); |
297 | 293 | $oModuleHandler->module_info->skin = $skin; |
@@ -325,19 +321,27 @@ discard block |
||
325 | 321 | // admin check |
326 | 322 | // this act is admin view but in normal view because do not load admin css/js files |
327 | 323 | $logged_info = Context::get('logged_info'); |
328 | - if($logged_info->is_admin != 'Y') return $this->stop('msg_invalid_request'); |
|
324 | + if($logged_info->is_admin != 'Y') { |
|
325 | + return $this->stop('msg_invalid_request'); |
|
326 | + } |
|
329 | 327 | |
330 | 328 | $layout_srl = Context::get('layout_srl'); |
331 | 329 | $code = Context::get('code'); |
332 | 330 | |
333 | 331 | $code_css = Context::get('code_css'); |
334 | - if(!$layout_srl || !$code) return new BaseObject(-1, 'msg_invalid_request'); |
|
332 | + if(!$layout_srl || !$code) { |
|
333 | + return new BaseObject(-1, 'msg_invalid_request'); |
|
334 | + } |
|
335 | 335 | // Get the layout information |
336 | 336 | $oLayoutModel = getModel('layout'); |
337 | 337 | $layout_info = $oLayoutModel->getLayout($layout_srl); |
338 | - if(!$layout_info) return new BaseObject(-1, 'msg_invalid_request'); |
|
338 | + if(!$layout_info) { |
|
339 | + return new BaseObject(-1, 'msg_invalid_request'); |
|
340 | + } |
|
339 | 341 | // Separately handle the layout if its type is faceoff |
340 | - if($layout_info && $layout_info->type == 'faceoff') $oLayoutModel->doActivateFaceOff($layout_info); |
|
342 | + if($layout_info && $layout_info->type == 'faceoff') { |
|
343 | + $oLayoutModel->doActivateFaceOff($layout_info); |
|
344 | + } |
|
341 | 345 | // Apply CSS directly |
342 | 346 | Context::addHtmlHeader("<style type=\"text/css\" charset=\"UTF-8\">".$code_css."</style>"); |
343 | 347 | // Set names and values of extra_vars to $layout_info |
@@ -354,7 +358,9 @@ discard block |
||
354 | 358 | foreach($layout_info->menu as $menu_id => $menu) |
355 | 359 | { |
356 | 360 | $menu->php_file = FileHandler::getRealPath($menu->php_file); |
357 | - if(FileHandler::exists($menu->php_file)) include($menu->php_file); |
|
361 | + if(FileHandler::exists($menu->php_file)) { |
|
362 | + include($menu->php_file); |
|
363 | + } |
|
358 | 364 | |
359 | 365 | Context::set($menu_id, $menu); |
360 | 366 | } |
@@ -390,8 +396,7 @@ discard block |
||
390 | 396 | if(file_exists($layoutFile)) |
391 | 397 | { |
392 | 398 | return $layoutFile; |
393 | - } |
|
394 | - else |
|
399 | + } else |
|
395 | 400 | { |
396 | 401 | return ''; |
397 | 402 | } |
@@ -406,8 +411,7 @@ discard block |
||
406 | 411 | if(file_exists($cssFile)) |
407 | 412 | { |
408 | 413 | return $cssFile; |
409 | - } |
|
410 | - else |
|
414 | + } else |
|
411 | 415 | { |
412 | 416 | return ''; |
413 | 417 | } |