Rename protected methods for PSR2

This commit is contained in:
Michael Große 2019-03-17 13:35:04 +01:00
parent 60b9af73d5
commit 0efa8d12f0
No known key found for this signature in database
GPG Key ID: BDD834E001B99EDC
2 changed files with 54 additions and 54 deletions

View File

@ -315,7 +315,7 @@ class httpclient_http_test extends DokuWikiTest {
);
$this->assertEquals(
'%C3%B6%C3%A4%3F=%C3%B6%C3%A4%3F&foo=bang',
$this->callInaccessibleMethod($http, '_postEncode', [$data]),
$this->callInaccessibleMethod($http, 'postEncode', [$data]),
'simple'
);
@ -326,7 +326,7 @@ class httpclient_http_test extends DokuWikiTest {
);
$this->assertEquals(
'foo=bang&%C3%A4rr%5B0%5D=%C3%B6&%C3%A4rr%5B1%5D=b&%C3%A4rr%5B2%5D=c',
$this->callInaccessibleMethod($http, '_postEncode', [$data]),
$this->callInaccessibleMethod($http, 'postEncode', [$data]),
'onelevelnum'
);
@ -337,7 +337,7 @@ class httpclient_http_test extends DokuWikiTest {
);
$this->assertEquals(
'foo=bang&%C3%A4rr%5B%C3%B6%5D=%C3%A4&%C3%A4rr%5Bb%5D=c',
$this->callInaccessibleMethod($http, '_postEncode', [$data]),
$this->callInaccessibleMethod($http, 'postEncode', [$data]),
'onelevelassoc'
);
@ -349,7 +349,7 @@ class httpclient_http_test extends DokuWikiTest {
);
$this->assertEquals(
'foo=bang&%C3%A4rr%5B%C3%B6%5D=%C3%A4&%C3%A4rr%5B%C3%A4%5D%5B%C3%B6%5D=%C3%A4',
$this->callInaccessibleMethod($http, '_postEncode', [$data]),
$this->callInaccessibleMethod($http, 'postEncode', [$data]),
'twolevelassoc'
);
}

View File

@ -124,7 +124,7 @@ class HTTPClient {
}else{
$url .= '?';
}
$url .= $this->_postEncode($data);
$url .= $this->postEncode($data);
return $this->get($url,$sloppy304);
}
@ -162,7 +162,7 @@ class HTTPClient {
* @author Andreas Gohr <andi@splitbrain.org>
*/
public function sendRequest($url,$data='',$method='GET'){
$this->start = $this->_time();
$this->start = $this->time();
$this->error = '';
$this->status = 0;
$this->status = 0;
@ -223,11 +223,11 @@ class HTTPClient {
switch ($headers['Content-Type']) {
case 'multipart/form-data':
$headers['Content-Type'] = 'multipart/form-data; boundary=' . $this->boundary;
$data = $this->_postMultipartEncode($data);
$data = $this->postMultipartEncode($data);
break;
default:
$headers['Content-Type'] = 'application/x-www-form-urlencoded';
$data = $this->_postEncode($data);
$data = $this->postEncode($data);
}
}
}elseif($method == 'GET'){
@ -247,15 +247,15 @@ class HTTPClient {
}
// already connected?
$connectionId = $this->_uniqueConnectionId($server,$port);
$this->_debug('connection pool', self::$connections);
$connectionId = $this->uniqueConnectionId($server,$port);
$this->debug('connection pool', self::$connections);
$socket = null;
if (isset(self::$connections[$connectionId])) {
$this->_debug('reusing connection', $connectionId);
$this->debug('reusing connection', $connectionId);
$socket = self::$connections[$connectionId];
}
if (is_null($socket) || feof($socket)) {
$this->_debug('opening connection', $connectionId);
$this->debug('opening connection', $connectionId);
// open socket
$socket = @fsockopen($server,$port,$errno, $errstr, $this->timeout);
if (!$socket){
@ -266,7 +266,7 @@ class HTTPClient {
// try establish a CONNECT tunnel for SSL
try {
if($this->_ssltunnel($socket, $request_url)){
if($this->ssltunnel($socket, $request_url)){
// no keep alive for tunnels
$this->keep_alive = false;
// tunnel is authed already
@ -302,22 +302,22 @@ class HTTPClient {
// build request
$request = "$method $request_url HTTP/".$this->http.HTTP_NL;
$request .= $this->_buildHeaders($headers);
$request .= $this->_getCookies();
$request .= $this->buildHeaders($headers);
$request .= $this->getCookies();
$request .= HTTP_NL;
$request .= $data;
$this->_debug('request',$request);
$this->_sendData($socket, $request, 'request');
$this->debug('request',$request);
$this->sendData($socket, $request, 'request');
// read headers from socket
$r_headers = '';
do{
$r_line = $this->_readLine($socket, 'headers');
$r_line = $this->readLine($socket, 'headers');
$r_headers .= $r_line;
}while($r_line != "\r\n" && $r_line != "\n");
$this->_debug('response headers',$r_headers);
$this->debug('response headers',$r_headers);
// check if expected body size exceeds allowance
if($this->max_bodysize && preg_match('/\r?\nContent-Length:\s*(\d+)\r?\n/i',$r_headers,$match)){
@ -336,7 +336,7 @@ class HTTPClient {
$this->status = $m[2];
// handle headers and cookies
$this->resp_headers = $this->_parseHeaders($r_headers);
$this->resp_headers = $this->parseHeaders($r_headers);
if(isset($this->resp_headers['set-cookie'])){
foreach ((array) $this->resp_headers['set-cookie'] as $cookie){
list($cookie) = explode(';',$cookie,2);
@ -352,7 +352,7 @@ class HTTPClient {
}
}
$this->_debug('Object headers',$this->resp_headers);
$this->debug('Object headers',$this->resp_headers);
// check server status code to follow redirect
if($this->status == 301 || $this->status == 302 ){
@ -401,13 +401,13 @@ class HTTPClient {
$abort = false;
do {
$chunk_size = '';
while (preg_match('/^[a-zA-Z0-9]?$/',$byte=$this->_readData($socket,1,'chunk'))){
while (preg_match('/^[a-zA-Z0-9]?$/',$byte=$this->readData($socket,1,'chunk'))){
// read chunksize until \r
$chunk_size .= $byte;
if (strlen($chunk_size) > 128) // set an abritrary limit on the size of chunks
throw new HTTPClientException('Allowed response size exceeded');
}
$this->_readLine($socket, 'chunk'); // readtrailing \n
$this->readLine($socket, 'chunk'); // readtrailing \n
$chunk_size = hexdec($chunk_size);
if($this->max_bodysize && $chunk_size+strlen($r_body) > $this->max_bodysize){
@ -419,8 +419,8 @@ class HTTPClient {
}
if ($chunk_size > 0) {
$r_body .= $this->_readData($socket, $chunk_size, 'chunk');
$this->_readData($socket, 2, 'chunk'); // read trailing \r\n
$r_body .= $this->readData($socket, $chunk_size, 'chunk');
$this->readData($socket, 2, 'chunk'); // read trailing \r\n
}
} while ($chunk_size && !$abort);
}elseif(isset($this->resp_headers['content-length']) && !isset($this->resp_headers['transfer-encoding'])){
@ -441,15 +441,15 @@ class HTTPClient {
$length = $this->resp_headers['content-length'];
}
$r_body = $this->_readData($socket, $length, 'response (content-length limited)', true);
$r_body = $this->readData($socket, $length, 'response (content-length limited)', true);
}elseif( !isset($this->resp_headers['transfer-encoding']) && $this->max_bodysize && !$this->keep_alive){
$r_body = $this->_readData($socket, $this->max_bodysize+1, 'response (content-length limited)', true);
$r_body = $this->readData($socket, $this->max_bodysize+1, 'response (content-length limited)', true);
} elseif ((int)$this->status === 204) {
// request has no content
} else{
// read entire socket
while (!feof($socket)) {
$r_body .= $this->_readData($socket, 4096, 'response (unlimited)', true);
$r_body .= $this->readData($socket, 4096, 'response (unlimited)', true);
}
}
@ -493,7 +493,7 @@ class HTTPClient {
$this->resp_body = $r_body;
}
$this->_debug('response body',$this->resp_body);
$this->debug('response body',$this->resp_body);
$this->redirect_count = 0;
return true;
}
@ -508,7 +508,7 @@ class HTTPClient {
* @throws HTTPClientException when a tunnel is needed but could not be established
* @return bool true if a tunnel was established
*/
protected function _ssltunnel(&$socket, &$requesturl){
protected function ssltunnel(&$socket, &$requesturl){
if(!$this->proxy_host) return false;
$requestinfo = parse_url($requesturl);
if($requestinfo['scheme'] != 'https') return false;
@ -522,17 +522,17 @@ class HTTPClient {
}
$request .= HTTP_NL;
$this->_debug('SSL Tunnel CONNECT',$request);
$this->_sendData($socket, $request, 'SSL Tunnel CONNECT');
$this->debug('SSL Tunnel CONNECT',$request);
$this->sendData($socket, $request, 'SSL Tunnel CONNECT');
// read headers from socket
$r_headers = '';
do{
$r_line = $this->_readLine($socket, 'headers');
$r_line = $this->readLine($socket, 'headers');
$r_headers .= $r_line;
}while($r_line != "\r\n" && $r_line != "\n");
$this->_debug('SSL Tunnel Response',$r_headers);
$this->debug('SSL Tunnel Response',$r_headers);
if(preg_match('/^HTTP\/1\.[01] 200/i',$r_headers)){
// set correct peer name for verification (enabled since PHP 5.6)
stream_context_set_option($socket, 'ssl', 'peer_name', $requestinfo['host']);
@ -570,13 +570,13 @@ class HTTPClient {
*
* @author Tom N Harris <tnharris@whoopdedo.org>
*/
protected function _sendData($socket, $data, $message) {
protected function sendData($socket, $data, $message) {
// send request
$towrite = strlen($data);
$written = 0;
while($written < $towrite){
// check timeout
$time_used = $this->_time() - $this->start;
$time_used = $this->time() - $this->start;
if($time_used > $this->timeout)
throw new HTTPClientException(sprintf('Timeout while sending %s (%.3fs)',$message, $time_used), -100);
if(feof($socket))
@ -615,13 +615,13 @@ class HTTPClient {
*
* @author Tom N Harris <tnharris@whoopdedo.org>
*/
protected function _readData($socket, $nbytes, $message, $ignore_eof = false) {
protected function readData($socket, $nbytes, $message, $ignore_eof = false) {
$r_data = '';
// Does not return immediately so timeout and eof can be checked
if ($nbytes < 0) $nbytes = 0;
$to_read = $nbytes;
do {
$time_used = $this->_time() - $this->start;
$time_used = $this->time() - $this->start;
if ($time_used > $this->timeout)
throw new HTTPClientException(
sprintf('Timeout while reading %s after %d bytes (%.3fs)', $message,
@ -665,10 +665,10 @@ class HTTPClient {
*
* @author Tom N Harris <tnharris@whoopdedo.org>
*/
protected function _readLine($socket, $message) {
protected function readLine($socket, $message) {
$r_data = '';
do {
$time_used = $this->_time() - $this->start;
$time_used = $this->time() - $this->start;
if ($time_used > $this->timeout)
throw new HTTPClientException(
sprintf('Timeout while reading %s (%.3fs) >%s<', $message, $time_used, $r_data),
@ -701,12 +701,12 @@ class HTTPClient {
* @param string $info
* @param mixed $var
*/
protected function _debug($info,$var=null){
protected function debug($info,$var=null){
if(!$this->debug) return;
if(php_sapi_name() == 'cli'){
$this->_debug_text($info, $var);
$this->debugText($info, $var);
}else{
$this->_debug_html($info, $var);
$this->debugHtml($info, $var);
}
}
@ -716,8 +716,8 @@ class HTTPClient {
* @param string $info
* @param mixed $var
*/
protected function _debug_html($info, $var=null){
print '<b>'.$info.'</b> '.($this->_time() - $this->start).'s<br />';
protected function debugHtml($info, $var=null){
print '<b>'.$info.'</b> '.($this->time() - $this->start).'s<br />';
if(!is_null($var)){
ob_start();
print_r($var);
@ -733,8 +733,8 @@ class HTTPClient {
* @param string $info
* @param mixed $var
*/
protected function _debug_text($info, $var=null){
print '*'.$info.'* '.($this->_time() - $this->start)."s\n";
protected function debugText($info, $var=null){
print '*'.$info.'* '.($this->time() - $this->start)."s\n";
if(!is_null($var)) print_r($var);
print "\n-----------------------------------------------\n";
}
@ -744,7 +744,7 @@ class HTTPClient {
*
* @return float
*/
protected static function _time(){
protected static function time(){
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
@ -759,7 +759,7 @@ class HTTPClient {
* @param string $string
* @return array
*/
protected function _parseHeaders($string){
protected function parseHeaders($string){
$headers = array();
$lines = explode("\n",$string);
array_shift($lines); //skip first line (status)
@ -790,7 +790,7 @@ class HTTPClient {
* @param array $headers
* @return string
*/
protected function _buildHeaders($headers){
protected function buildHeaders($headers){
$string = '';
foreach($headers as $key => $value){
if($value === '') continue;
@ -806,7 +806,7 @@ class HTTPClient {
*
* @return string
*/
protected function _getCookies(){
protected function getCookies(){
$headers = '';
foreach ($this->cookies as $key => $val){
$headers .= "$key=$val; ";
@ -824,7 +824,7 @@ class HTTPClient {
* @param array $data
* @return string
*/
protected function _postEncode($data){
protected function postEncode($data){
return http_build_query($data,'','&');
}
@ -837,7 +837,7 @@ class HTTPClient {
* @param array $data
* @return string
*/
protected function _postMultipartEncode($data){
protected function postMultipartEncode($data){
$boundary = '--'.$this->boundary;
$out = '';
foreach($data as $key => $val){
@ -868,7 +868,7 @@ class HTTPClient {
* @param string $port
* @return string unique identifier
*/
protected function _uniqueConnectionId($server, $port) {
protected function uniqueConnectionId($server, $port) {
return "$server:$port";
}
}