root/trunk/classes/phing/BuildEvent.php

Revision 307, 6.5 kB (checked in by hans, 1 year ago)

Refs #188 - Adding work-in-progress (still-broken!) namespace support.

  • Property svn:keywords set to author date id revision
Line 
1 <?php
2 /*
3  *  $Id$
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 namespace phing;
23
24 /**
25  * Encapsulates a build specific event.
26  *
27  * <p>We have three sources of events all handled by this class:
28  *
29  * <ul>
30  *  <li>Project level events</li>
31  *  <li>Target level events</li>
32  *  <li>Task level events</li>
33  * </ul>
34  *
35  * <p> Events are all fired from the project class by creating an event object
36  * using this class and passing it to the listeners.
37  *
38  * @author    Andreas Aderhold <andi@binarycloud.com>
39  * @author    Hans Lellelid <hans@xmpl.org>
40  * @version   $Revision: 1.10 $
41  * @package   phing
42  */
43 class BuildEvent {
44
45     /**
46      * The object on which the Event initially occurred.
47      * @var object
48      */
49     protected $source;
50     
51     /**
52      * A reference to the project
53      * @var Project
54      */
55     protected $project;
56
57     /**
58      * A reference to the target
59      * @var Target
60      */
61     protected $target;
62
63     /**
64      * A reference to the task
65      *
66      * @var Task
67      */
68     protected $task;
69
70     /**
71      * The message of this event, if the event is a message
72      * @var string
73      */
74     protected $message = null;
75
76     /**
77      * The priority of the message
78      *
79      * @var    string
80      * @see    $message
81      */
82     protected $priority = Project::MSG_VERBOSE;
83
84     /**
85      * The execption that caused the event, if any
86      *
87      * @var    object
88      */
89     protected $exception = null;
90
91     /**
92      * Construct a BuildEvent for a project, task or target source event
93      *
94      * @param  object  project the project that emitted the event.
95      */
96     public function __construct($source) {
97         $this->source = $source;
98         if ($source instanceof Project) {
99             $this->project = $source;
100             $this->target = null;
101             $this->task = null;
102         } elseif ($source instanceof Target) {
103             $this->project = $source->getProject();
104             $this->target = $source;
105             $this->task = null;
106         } elseif ($source instanceof Task) {
107             $this->project = $source->getProject();
108             $this->target = $source->getOwningTarget();
109             $this->task = $source;
110         } else {
111             throw new Exception("Can not construct BuildEvent, unknown source given.");
112         }
113     }
114
115     /**
116      * Sets the message with details and the message priority for this event.
117      *
118      * @param  string   The string message of the event
119      * @param  integer  The priority this message should have
120      */
121     public function setMessage($message, $priority) {
122         $this->message = (string) $message;
123         $this->priority = (int) $priority;
124     }
125
126     /**
127      * Set the exception that was the cause of this event.
128      *
129      * @param  Exception The exception that caused the event
130      */
131     public function setException($exception) {
132         $this->exception = $exception;
133     }
134
135     /**
136      * Returns the project instance that fired this event.
137      *
138      * The reference to the project instance is set by the constructor if this
139      * event was fired from the project class.
140      *
141      * @return  Project  The project instance that fired this event
142      */
143     public function getProject() {
144         return $this->project;
145     }
146
147     /**
148      * Returns the target instance that fired this event.
149      *
150      * The reference to the target instance is set by the constructor if this
151      * event was fired from the target class.
152      *
153      * @return Target The target that fired this event
154      */
155     public function getTarget() {
156         return $this->target;
157     }
158
159     /**
160      * Returns the target instance that fired this event.
161      *
162      * The reference to the task instance is set by the constructor if this
163      * event was fired within a task.
164      *
165      * @return Task The task that fired this event
166      */
167     public function getTask() {
168         return $this->task;
169     }
170
171     /**
172      * Returns the logging message. This field will only be set for
173      * "messageLogged" events.
174      *
175      * @return string The log message
176      */
177     function getMessage() {
178         return $this->message;
179     }
180
181     /**
182      * Returns the priority of the logging message. This field will only
183      * be set for "messageLogged" events.
184      *
185      * @return integer The message priority
186      */
187     function getPriority() {
188         return $this->priority;
189     }
190
191     /**
192      * Returns the exception that was thrown, if any.
193      * This field will only be set for "taskFinished", "targetFinished", and
194      * "buildFinished" events.
195      *
196      * @see BuildListener::taskFinished()
197      * @see BuildListener::targetFinished()
198      * @see BuildListener::buildFinished()
199      * @return Exception
200      */
201     public function getException() {
202         return $this->exception;
203     }
204     
205      /**
206      * Get the object on which the Event initially occurred.
207      * @return object
208      */
209     public function getSource() {
210         return $this->source;
211     }
212
213     /**
214      * Returns a String representation of this EventObject.
215      * @return string
216      */
217     public function __toString() {
218         if (method_exists($this->source, "toString")) {
219             return get_class($this)."[source=".$this->source->toString()."]";
220         } else {
221             return get_class($this)."[source=".get_class($this->source)."]";
222         }
223     }
224     
225     /**
226      *
227      * @deprecated
228      */
229     public function toString() {
230         return $this->__toString();
231     }
232     
233 }
234
Note: See TracBrowser for help on using the browser.