1
0
Fork 0

Extract job packageName & constraint to variables

pull/8085/head^2
Marc Würth 2019-03-21 19:17:55 +01:00 committed by Jordi Boggiano
parent 2b421a94cb
commit d2ab4f66fd
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
1 changed files with 36 additions and 31 deletions

View File

@ -81,8 +81,11 @@ class Problem
$job = $reason['job']; $job = $reason['job'];
if (isset($job['constraint'])) { $packageName = $job['packageName'];
$packages = $this->pool->whatProvides($job['packageName'], $job['constraint']); $constraint = $job['constraint'];
if (isset($constraint)) {
$packages = $this->pool->whatProvides($packageName, $constraint);
} else { } else {
$packages = array(); $packages = array();
} }
@ -90,9 +93,9 @@ class Problem
if ($job && $job['cmd'] === 'install' && empty($packages)) { if ($job && $job['cmd'] === 'install' && empty($packages)) {
// handle php/hhvm // handle php/hhvm
if ($job['packageName'] === 'php' || $job['packageName'] === 'php-64bit' || $job['packageName'] === 'hhvm') { if ($packageName === 'php' || $packageName === 'php-64bit' || $packageName === 'hhvm') {
$version = phpversion(); $version = phpversion();
$available = $this->pool->whatProvides($job['packageName']); $available = $this->pool->whatProvides($packageName);
if (count($available)) { if (count($available)) {
$firstAvailable = reset($available); $firstAvailable = reset($available);
@ -103,13 +106,13 @@ class Problem
} }
} }
$msg = "\n - This package requires ".$job['packageName'].$this->constraintToText($job['constraint']).' but '; $msg = "\n - This package requires ".$packageName.$this->constraintToText($constraint).' but ';
if (defined('HHVM_VERSION') || count($available)) { if (defined('HHVM_VERSION') || count($available)) {
return $msg . 'your HHVM version does not satisfy that requirement.'; return $msg . 'your HHVM version does not satisfy that requirement.';
} }
if ($job['packageName'] === 'hhvm') { if ($packageName === 'hhvm') {
return $msg . 'you are running this with PHP and not HHVM.'; return $msg . 'you are running this with PHP and not HHVM.';
} }
@ -117,43 +120,43 @@ class Problem
} }
// handle php extensions // handle php extensions
if (0 === stripos($job['packageName'], 'ext-')) { if (0 === stripos($packageName, 'ext-')) {
if (false !== strpos($job['packageName'], ' ')) { if (false !== strpos($packageName, ' ')) {
return "\n - The requested PHP extension ".$job['packageName'].' should be required as '.str_replace(' ', '-', $job['packageName']).'.'; return "\n - The requested PHP extension ".$packageName.' should be required as '.str_replace(' ', '-', $packageName).'.';
} }
$ext = substr($job['packageName'], 4); $ext = substr($packageName, 4);
$error = extension_loaded($ext) ? 'has the wrong version ('.(phpversion($ext) ?: '0').') installed' : 'is missing from your system'; $error = extension_loaded($ext) ? 'has the wrong version ('.(phpversion($ext) ?: '0').') installed' : 'is missing from your system';
return "\n - The requested PHP extension ".$job['packageName'].$this->constraintToText($job['constraint']).' '.$error.'. Install or enable PHP\'s '.$ext.' extension.'; return "\n - The requested PHP extension ".$packageName.$this->constraintToText($constraint).' '.$error.'. Install or enable PHP\'s '.$ext.' extension.';
} }
// handle linked libs // handle linked libs
if (0 === stripos($job['packageName'], 'lib-')) { if (0 === stripos($packageName, 'lib-')) {
if (strtolower($job['packageName']) === 'lib-icu') { if (strtolower($packageName) === 'lib-icu') {
$error = extension_loaded('intl') ? 'has the wrong version installed, try upgrading the intl extension.' : 'is missing from your system, make sure the intl extension is loaded.'; $error = extension_loaded('intl') ? 'has the wrong version installed, try upgrading the intl extension.' : 'is missing from your system, make sure the intl extension is loaded.';
return "\n - The requested linked library ".$job['packageName'].$this->constraintToText($job['constraint']).' '.$error; return "\n - The requested linked library ".$packageName.$this->constraintToText($constraint).' '.$error;
} }
return "\n - The requested linked library ".$job['packageName'].$this->constraintToText($job['constraint']).' has the wrong version installed or is missing from your system, make sure to load the extension providing it.'; return "\n - The requested linked library ".$packageName.$this->constraintToText($constraint).' has the wrong version installed or is missing from your system, make sure to load the extension providing it.';
} }
if (!preg_match('{^[A-Za-z0-9_./-]+$}', $job['packageName'])) { if (!preg_match('{^[A-Za-z0-9_./-]+$}', $packageName)) {
$illegalChars = preg_replace('{[A-Za-z0-9_./-]+}', '', $job['packageName']); $illegalChars = preg_replace('{[A-Za-z0-9_./-]+}', '', $packageName);
return "\n - The requested package ".$job['packageName'].' could not be found, it looks like its name is invalid, "'.$illegalChars.'" is not allowed in package names.'; return "\n - The requested package ".$packageName.' could not be found, it looks like its name is invalid, "'.$illegalChars.'" is not allowed in package names.';
} }
if ($providers = $this->pool->whatProvides($job['packageName'], $job['constraint'], true, true)) { if ($providers = $this->pool->whatProvides($packageName, $constraint, true, true)) {
return "\n - The requested package ".$job['packageName'].$this->constraintToText($job['constraint']).' is satisfiable by '.$this->getPackageList($providers).' but these conflict with your requirements or minimum-stability.'; return "\n - The requested package ".$packageName.$this->constraintToText($constraint).' is satisfiable by '.$this->getPackageList($providers).' but these conflict with your requirements or minimum-stability.';
} }
if ($providers = $this->pool->whatProvides($job['packageName'], null, true, true)) { if ($providers = $this->pool->whatProvides($packageName, null, true, true)) {
return "\n - The requested package ".$job['packageName'].$this->constraintToText($job['constraint']).' exists as '.$this->getPackageList($providers).' but these are rejected by your constraint.'; return "\n - The requested package ".$packageName.$this->constraintToText($constraint).' exists as '.$this->getPackageList($providers).' but these are rejected by your constraint.';
} }
return "\n - The requested package ".$job['packageName'].' could not be found in any version, there may be a typo in the package name.'; return "\n - The requested package ".$packageName.' could not be found in any version, there may be a typo in the package name.';
} }
} }
@ -202,27 +205,29 @@ class Problem
*/ */
protected function jobToText($job) protected function jobToText($job)
{ {
$packageName = $job['packageName'];
$constraint = $job['constraint'];
switch ($job['cmd']) { switch ($job['cmd']) {
case 'install': case 'install':
$packages = $this->pool->whatProvides($job['packageName'], $job['constraint']); $packages = $this->pool->whatProvides($packageName, $constraint);
if (!$packages) { if (!$packages) {
return 'No package found to satisfy install request for '.$job['packageName'].$this->constraintToText($job['constraint']); return 'No package found to satisfy install request for '.$packageName.$this->constraintToText($constraint);
} }
return 'Installation request for '.$job['packageName'].$this->constraintToText($job['constraint']).' -> satisfiable by '.$this->getPackageList($packages).'.'; return 'Installation request for '.$packageName.$this->constraintToText($constraint).' -> satisfiable by '.$this->getPackageList($packages).'.';
case 'update': case 'update':
return 'Update request for '.$job['packageName'].$this->constraintToText($job['constraint']).'.'; return 'Update request for '.$packageName.$this->constraintToText($constraint).'.';
case 'remove': case 'remove':
return 'Removal request for '.$job['packageName'].$this->constraintToText($job['constraint']).''; return 'Removal request for '.$packageName.$this->constraintToText($constraint).'';
} }
if (isset($job['constraint'])) { if (isset($constraint)) {
$packages = $this->pool->whatProvides($job['packageName'], $job['constraint']); $packages = $this->pool->whatProvides($packageName, $constraint);
} else { } else {
$packages = array(); $packages = array();
} }
return 'Job(cmd='.$job['cmd'].', target='.$job['packageName'].', packages=['.$this->getPackageList($packages).'])'; return 'Job(cmd='.$job['cmd'].', target='.$packageName.', packages=['.$this->getPackageList($packages).'])';
} }
protected function getPackageList($packages) protected function getPackageList($packages)