BuildException.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /*
  3. * $Id: BuildException.php 905 2010-10-05 16:28:03Z mrook $
  4. *
  5. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  6. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  7. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  9. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16. *
  17. * This software consists of voluntary contributions made by many individuals
  18. * and is licensed under the LGPL. For more information please see
  19. * <http://phing.info>.
  20. */
  21. /**
  22. * BuildException is for when things go wrong in a build execution.
  23. *
  24. * @author Andreas Aderhold <andi@binarycloud.com>
  25. * @version $Revision: 905 $
  26. * @package phing
  27. */
  28. class BuildException extends Exception {
  29. /**
  30. * Location in the xml file.
  31. * @var Location
  32. */
  33. protected $location;
  34. /**
  35. * The nested "cause" exception.
  36. * @var Exception
  37. */
  38. protected $cause;
  39. /**
  40. * Construct a BuildException.
  41. * Supported signatures:
  42. * throw new BuildException($causeExc);
  43. * throw new BuildException($msg);
  44. * throw new Buildexception($causeExc, $loc);
  45. * throw new BuildException($msg, $causeExc);
  46. * throw new BuildException($msg, $loc);
  47. * throw new BuildException($msg, $causeExc, $loc);
  48. */
  49. function __construct($p1, $p2 = null, $p3 = null) {
  50. $cause = null;
  51. $loc = null;
  52. $msg = "";
  53. if ($p3 !== null) {
  54. $cause = $p2;
  55. $loc = $p3;
  56. $msg = $p1;
  57. } elseif ($p2 !== null) {
  58. if ($p2 instanceof Exception) {
  59. $cause = $p2;
  60. $msg = $p1;
  61. } elseif ($p2 instanceof Location) {
  62. $loc = $p2;
  63. if ($p1 instanceof Exception) {
  64. $cause = $p1;
  65. } else {
  66. $msg = $p1;
  67. }
  68. }
  69. } elseif ($p1 instanceof Exception) {
  70. $cause = $p1;
  71. } else {
  72. $msg = $p1;
  73. }
  74. parent::__construct($msg);
  75. if ($cause !== null) {
  76. $this->cause = $cause;
  77. $this->message .= " [wrapped: " . $cause->getMessage() ."]";
  78. }
  79. if ($loc !== null) {
  80. $this->setLocation($loc);
  81. }
  82. }
  83. /**
  84. * Gets the cause exception.
  85. *
  86. * @return Exception
  87. */
  88. public function getCause() {
  89. return $this->cause;
  90. }
  91. /**
  92. * Gets the location of error in XML file.
  93. *
  94. * @return Location
  95. */
  96. public function getLocation() {
  97. return $this->location;
  98. }
  99. /**
  100. * Sets the location of error in XML file.
  101. *
  102. * @param Locaiton $loc
  103. */
  104. public function setLocation(Location $loc) {
  105. $this->location = $loc;
  106. $this->message = $loc->toString() . ': ' . $this->message;
  107. }
  108. }