Skip all network-based checks (#7641)
* Skip all network-based checks Change the warnings in diagnose to a friendly messages when allow_url_fopen is disabled. Issue: #7622pull/7762/head
parent
0ee0138bed
commit
da94e4b619
|
@ -119,8 +119,9 @@ EOT
|
|||
$io->write('Checking github.com rate limit: ', false);
|
||||
try {
|
||||
$rate = $this->getGithubRateLimit('github.com');
|
||||
$this->outputResult(true);
|
||||
if (10 > $rate['remaining']) {
|
||||
if (!is_array($rate)) {
|
||||
$this->outputResult($rate);
|
||||
} elseif (10 > $rate['remaining']) {
|
||||
$io->writeError('<warning>WARNING</warning>');
|
||||
$io->writeError(sprintf(
|
||||
'<comment>Github has a rate limit on their API. '
|
||||
|
@ -131,6 +132,8 @@ EOT
|
|||
$rate['remaining'],
|
||||
$rate['limit']
|
||||
));
|
||||
} else {
|
||||
$this->outputResult(true);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
if ($e instanceof TransportException && $e->getCode() === 401) {
|
||||
|
@ -207,6 +210,11 @@ EOT
|
|||
|
||||
private function checkHttp($proto, Config $config)
|
||||
{
|
||||
$result = $this->checkConnectivity();
|
||||
if ($result !== true) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$disableTls = false;
|
||||
$result = array();
|
||||
if ($proto === 'https' && $config->get('disable-tls') === true) {
|
||||
|
@ -238,6 +246,11 @@ EOT
|
|||
|
||||
private function checkHttpProxy()
|
||||
{
|
||||
$result = $this->checkConnectivity();
|
||||
if ($result !== true) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$protocol = extension_loaded('openssl') ? 'https' : 'http';
|
||||
try {
|
||||
$json = json_decode($this->rfs->getContents('packagist.org', $protocol . '://repo.packagist.org/packages.json', false), true);
|
||||
|
@ -265,6 +278,11 @@ EOT
|
|||
*/
|
||||
private function checkHttpProxyFullUriRequestParam()
|
||||
{
|
||||
$result = $this->checkConnectivity();
|
||||
if ($result !== true) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$url = 'http://repo.packagist.org/packages.json';
|
||||
try {
|
||||
$this->rfs->getContents('packagist.org', $url, false);
|
||||
|
@ -290,6 +308,11 @@ EOT
|
|||
*/
|
||||
private function checkHttpsProxyFullUriRequestParam()
|
||||
{
|
||||
$result = $this->checkConnectivity();
|
||||
if ($result !== true) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
if (!extension_loaded('openssl')) {
|
||||
return 'You need the openssl extension installed for this check';
|
||||
}
|
||||
|
@ -312,6 +335,11 @@ EOT
|
|||
|
||||
private function checkGithubOauth($domain, $token)
|
||||
{
|
||||
$result = $this->checkConnectivity();
|
||||
if ($result !== true) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$this->getIO()->setAuthentication($domain, $token, 'x-oauth-basic');
|
||||
try {
|
||||
$url = $domain === 'github.com' ? 'https://api.'.$domain.'/' : 'https://'.$domain.'/api/v3/';
|
||||
|
@ -332,10 +360,15 @@ EOT
|
|||
* @param string $domain
|
||||
* @param string $token
|
||||
* @throws TransportException
|
||||
* @return array
|
||||
* @return array|string
|
||||
*/
|
||||
private function getGithubRateLimit($domain, $token = null)
|
||||
{
|
||||
$result = $this->checkConnectivity();
|
||||
if ($result !== true) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
if ($token) {
|
||||
$this->getIO()->setAuthentication($domain, $token, 'x-oauth-basic');
|
||||
}
|
||||
|
@ -390,6 +423,11 @@ EOT
|
|||
|
||||
private function checkVersion($config)
|
||||
{
|
||||
$result = $this->checkConnectivity();
|
||||
if ($result !== true) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$versionsUtil = new Versions($config, $this->rfs);
|
||||
$latest = $versionsUtil->getLatest();
|
||||
|
||||
|
@ -413,6 +451,7 @@ EOT
|
|||
}
|
||||
|
||||
$hadError = false;
|
||||
$hadWarning = false;
|
||||
if ($result instanceof \Exception) {
|
||||
$result = '<error>['.get_class($result).'] '.$result->getMessage().'</error>';
|
||||
}
|
||||
|
@ -427,6 +466,8 @@ EOT
|
|||
foreach ($result as $message) {
|
||||
if (false !== strpos($message, '<error>')) {
|
||||
$hadError = true;
|
||||
} elseif (false !== strpos($message, '<warning>')) {
|
||||
$hadWarning = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -434,7 +475,7 @@ EOT
|
|||
if ($hadError) {
|
||||
$io->write('<error>FAIL</error>');
|
||||
$this->exitCode = 2;
|
||||
} else {
|
||||
} elseif ($hadWarning) {
|
||||
$io->write('<warning>WARNING</warning>');
|
||||
$this->exitCode = 1;
|
||||
}
|
||||
|
@ -668,4 +709,20 @@ EOT
|
|||
|
||||
return !$warnings && !$errors ? true : $output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if allow_url_fopen is ON
|
||||
*
|
||||
* @return bool|string
|
||||
*/
|
||||
private function checkConnectivity()
|
||||
{
|
||||
if (!ini_get('allow_url_fopen')) {
|
||||
$result = '<info>Skipped because allow_url_fopen is missing.</info>';
|
||||
return $result;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue