| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
namespace phing; |
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 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 |
|
|---|