1
<?php
2
/**
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the LGPL. For more information please see
17
 * <http://phing.info>.
18
 */
19

20
/**
21
 * BuildException is for when things go wrong in a build execution.
22
 *
23
 * @author  Andreas Aderhold <andi@binarycloud.com>
24
 * @package phing
25
 */
26
class BuildException extends RuntimeException
27
{
28

29
    /**
30
     * Location in the xml file.
31
     *
32
     * @var Location
33
     */
34
    protected $location;
35

36
    /**
37
     * Construct a BuildException.
38
     * Supported signatures:
39
     *         throw new BuildException($causeExc);
40
     *         throw new BuildException($msg);
41
     *         throw new Buildexception($causeExc, $loc);
42
     *         throw new BuildException($msg, $causeExc);
43
     *         throw new BuildException($msg, $loc);
44
     *         throw new BuildException($msg, $causeExc, $loc);
45
     *
46
     * @param Exception|string $p1
47
     * @param Location|Exception|null $p2
48
     * @param Location|null $p3
49
     */
50 1
    public function __construct($p1 = "", $p2 = null, $p3 = null)
51
    {
52 1
        $cause = null;
53 1
        $loc = null;
54 1
        $msg = "";
55

56 1
        if ($p3 !== null) {
57 1
            if ($p2 instanceof Throwable) {
58 1
                $cause = $p2;
59
            }
60 1
            $loc = $p3;
61 1
            $msg = $p1;
62 1
        } elseif ($p2 !== null) {
63 1
            if ($p2 instanceof Throwable) {
64 1
                $cause = $p2;
65 1
                $msg = $p1;
66 1
            } elseif ($p2 instanceof Location) {
67 1
                $loc = $p2;
68 1
                if ($p1 instanceof Throwable) {
69 0
                    $cause = $p1;
70
                } else {
71 1
                    $msg = $p1;
72
                }
73
            }
74 1
        } elseif ($p1 instanceof Throwable) {
75 1
            $cause = $p1;
76 1
            $msg = $p1->getMessage();
77
        } else {
78 1
            $msg = (string) $p1;
79
        }
80

81 1
        if ($loc !== null) {
82 1
            $this->setLocation($loc);
83
        }
84

85 1
        parent::__construct($msg, 0, $cause);
86
    }
87

88
    /**
89
     * Gets the location of error in XML file.
90
     *
91
     * @return Location
92
     */
93 1
    public function getLocation()
94
    {
95 1
        return $this->location;
96
    }
97

98
    /**
99
     * Sets the location of error in XML file.
100
     *
101
     * @param Location $loc
102
     */
103 1
    public function setLocation(Location $loc)
104
    {
105 1
        $this->location = $loc;
106
    }
107

108 1
    public function __toString()
109
    {
110 1
        return (string) $this->location . ' ' . $this->getMessage();
111
    }
112
}

Read our documentation on viewing source code .

Loading