SolverProblemsException.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\DependencyResolver;
  12. /**
  13. * @author Nils Adermann <naderman@naderman.de>
  14. */
  15. class SolverProblemsException extends \RuntimeException
  16. {
  17. protected $problems;
  18. public function __construct(array $problems, array $learnedPool)
  19. {
  20. $message = '';
  21. foreach ($problems as $i => $problem) {
  22. $message .= '[';
  23. foreach ($problem as $why) {
  24. if (is_int($why) && isset($learnedPool[$why])) {
  25. $rules = $learnedPool[$why];
  26. } else {
  27. $rules = $why;
  28. }
  29. if (isset($rules['packages'])) {
  30. $message .= $this->jobToText($rules);
  31. } else {
  32. $message .= '(';
  33. foreach ($rules as $rule) {
  34. if ($rule instanceof Rule) {
  35. if ($rule->getType() == RuleSet::TYPE_LEARNED) {
  36. $message .= 'learned: ';
  37. }
  38. $message .= $rule . ', ';
  39. } else {
  40. $message .= 'String(' . $rule . '), ';
  41. }
  42. }
  43. $message .= ')';
  44. }
  45. $message .= ', ';
  46. }
  47. $message .= "]\n";
  48. }
  49. parent::__construct($message);
  50. }
  51. public function jobToText($job)
  52. {
  53. //$output = serialize($job);
  54. $output = 'Job(cmd='.$job['cmd'].', target='.$job['packageName'].', packages=['.implode(', ', $job['packages']).'])';
  55. return $output;
  56. }
  57. }