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