Apply fixes from StyleCI

This commit is contained in:
Daniil Gentili 2018-03-16 14:10:29 +00:00 committed by StyleCI Bot
parent d45d2d887e
commit c6a0a04731
5 changed files with 55 additions and 56 deletions

View File

@ -2,7 +2,6 @@
class HTTPProxy implements \danog\MadelineProto\Proxy
{
private $sock;
private $protocol;
private $timeout = ['sec' => 0, 'usec' => 0];
@ -29,7 +28,7 @@ class HTTPProxy implements \danog\MadelineProto\Proxy
{
if ($this->sock !== null) {
fclose($this->sock);
$this->sock = NULL;
$this->sock = null;
}
}
@ -66,9 +65,9 @@ class HTTPProxy implements \danog\MadelineProto\Proxy
if ($this->domain === AF_INET6 && strpos($address, ':') !== false) {
$address = '['.$address.']';
}
fwrite($this->sock, "CONNECT " . $address . ":" . $port . " HTTP/1.1\r\n" .
fwrite($this->sock, 'CONNECT '.$address.':'.$port." HTTP/1.1\r\n".
"Accept: */*\r\n".
"Host: " . $address . ":" . $port . "\r\n" .
'Host: '.$address.':'.$port."\r\n".
$this->getProxyAuthHeader().
"connection: keep-Alive\r\n".
"\r\n");
@ -79,39 +78,43 @@ class HTTPProxy implements \danog\MadelineProto\Proxy
$status = $status || (strpos($line, 'HTTP') !== false);
if ($status) {
$response .= $line;
if (!chop($line))
if (!rtrim($line)) {
break;
}
}
if (substr($response, 0, 13) !== "HTTP/1.1 200 ")
}
if (substr($response, 0, 13) !== 'HTTP/1.1 200 ') {
return false;
}
}
if (true === $this->use_ssl) {
$modes = array(
$modes = [
STREAM_CRYPTO_METHOD_TLS_CLIENT,
STREAM_CRYPTO_METHOD_SSLv3_CLIENT,
STREAM_CRYPTO_METHOD_SSLv23_CLIENT,
STREAM_CRYPTO_METHOD_SSLv2_CLIENT
);
STREAM_CRYPTO_METHOD_SSLv2_CLIENT,
];
$contextOptions = array(
'ssl' => array(
$contextOptions = [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
),
);
],
];
stream_context_set_option($this->sock, $contextOptions);
$success = false;
foreach ($modes as $mode)
{
foreach ($modes as $mode) {
$success = stream_socket_enable_crypto($this->sock, true, $mode);
if ($success)
if ($success) {
return true;
}
}
return false;
}
return true;
}
@ -162,6 +165,7 @@ class HTTPProxy implements \danog\MadelineProto\Proxy
return true;
}
throw new \danog\MadelineProto\Exception('Not supported');
}
@ -175,7 +179,8 @@ class HTTPProxy implements \danog\MadelineProto\Proxy
if (!isset($this->options['user']) || !isset($this->options['pass'])) {
return '';
}
return "Proxy-Authorization: Basic " . base64_encode($this->options['user'] . ":" . $this->options['pass']) . "\r\n";
return 'Proxy-Authorization: Basic '.base64_encode($this->options['user'].':'.$this->options['pass'])."\r\n";
}
public function getProxyHeaders()
@ -187,5 +192,4 @@ class HTTPProxy implements \danog\MadelineProto\Proxy
{
$this->options = $extra;
}
}

View File

@ -119,7 +119,6 @@ If not, see <http://www.gnu.org/licenses/>.
public function setExtra(array $extra = [])
{
}
public function getProxyHeaders()

View File

@ -34,42 +34,38 @@ if (file_exists('web_data.php')) {
require_once 'web_data.php';
}
/**
* Set default context proxy for file_get_contents
*
* Set default context proxy for file_get_contents.
*/
$default_opts = array(
'http' => array(
'proxy' => "tcp://host:port",
$default_opts = [
'http' => [
'proxy' => 'tcp://host:port',
'request_fulluri' => true,
/* Only if your proxy requires authentication */
'header' => array(
"Proxy-Authorization: Basic " . base64_encode("proxy_user:proxy_pass")
)
),
'https' => array(
'proxy' => "tcp://host:port",
'header' => [
'Proxy-Authorization: Basic '.base64_encode('proxy_user:proxy_pass'),
],
],
'https' => [
'proxy' => 'tcp://host:port',
'request_fulluri' => true,
/* Only if your proxy requires authentication */
'header' => array(
"Proxy-Authorization: Basic " . base64_encode("proxy_user:proxy_pass")
)
),
'tls' => array(
'proxy' => "tcp://host:port",
'header' => [
'Proxy-Authorization: Basic '.base64_encode('proxy_user:proxy_pass'),
],
],
'tls' => [
'proxy' => 'tcp://host:port',
'request_fulluri' => true,
/* Only if your proxy requires authentication */
'header' => array(
"Proxy-Authorization: Basic " . base64_encode("proxy_user:proxy_pass")
)
)
);
'header' => [
'Proxy-Authorization: Basic '.base64_encode('proxy_user:proxy_pass'),
],
],
];
$default = stream_context_set_default($default_opts);
echo 'Deserializing MadelineProto from testing.madeline...'.PHP_EOL;
$MadelineProto = false;