mirror of
https://github.com/composer/composer
synced 2025-05-10 09:02:59 +00:00
Collect solver problems in Problem objects with human readable output.
This commit is contained in:
parent
2249dd0548
commit
2c87fe5a22
6 changed files with 230 additions and 86 deletions
|
@ -19,47 +19,26 @@ class SolverProblemsException extends \RuntimeException
|
|||
{
|
||||
protected $problems;
|
||||
|
||||
public function __construct(array $problems, array $learnedPool)
|
||||
public function __construct(array $problems)
|
||||
{
|
||||
$message = '';
|
||||
foreach ($problems as $i => $problem) {
|
||||
$message .= '[';
|
||||
foreach ($problem as $why) {
|
||||
$this->problems = $problems;
|
||||
|
||||
if (is_int($why) && isset($learnedPool[$why])) {
|
||||
$rules = $learnedPool[$why];
|
||||
} else {
|
||||
$rules = $why;
|
||||
}
|
||||
parent::__construct($this->createMessage());
|
||||
}
|
||||
|
||||
if (isset($rules['packages'])) {
|
||||
$message .= $this->jobToText($rules);
|
||||
} else {
|
||||
$message .= '(';
|
||||
foreach ($rules as $rule) {
|
||||
if ($rule instanceof Rule) {
|
||||
if ($rule->getType() == RuleSet::TYPE_LEARNED) {
|
||||
$message .= 'learned: ';
|
||||
}
|
||||
$message .= $rule . ', ';
|
||||
} else {
|
||||
$message .= 'String(' . $rule . '), ';
|
||||
}
|
||||
}
|
||||
$message .= ')';
|
||||
}
|
||||
$message .= ', ';
|
||||
}
|
||||
$message .= "]\n";
|
||||
protected function createMessage()
|
||||
{
|
||||
$messages = array();
|
||||
|
||||
foreach ($this->problems as $problem) {
|
||||
$messages[] = (string) $problem;
|
||||
}
|
||||
|
||||
parent::__construct($message);
|
||||
return "\n\tProblems:\n\t\t- ".implode("\n\t\t- ", $messages);
|
||||
}
|
||||
|
||||
public function jobToText($job)
|
||||
public function getProblems()
|
||||
{
|
||||
//$output = serialize($job);
|
||||
$output = 'Job(cmd='.$job['cmd'].', target='.$job['packageName'].', packages=['.implode(', ', $job['packages']).'])';
|
||||
return $output;
|
||||
return $this->problems;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue