| 1 |
lars |
1 |
<?php
|
|
|
2 |
/*
|
|
|
3 |
* $Id: TargetHandler.php 123 2006-09-14 20:19:08Z 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 |
require_once 'phing/parser/AbstractHandler.php';
|
|
|
23 |
|
|
|
24 |
/**
|
|
|
25 |
* The target handler class.
|
|
|
26 |
*
|
|
|
27 |
* This class handles the occurance of a <target> tag and it's possible
|
|
|
28 |
* nested tags (datatypes and tasks).
|
|
|
29 |
*
|
|
|
30 |
* @author Andreas Aderhold <andi@binarycloud.com>
|
|
|
31 |
* @copyright 2001,2002 THYRELL. All rights reserved
|
|
|
32 |
* @version $Revision: 1.10 $
|
|
|
33 |
* @package phing.parser
|
|
|
34 |
*/
|
|
|
35 |
class TargetHandler extends AbstractHandler {
|
|
|
36 |
|
|
|
37 |
/**
|
|
|
38 |
* Reference to the target object that represents the currently parsed
|
|
|
39 |
* target.
|
|
|
40 |
* @var object the target instance
|
|
|
41 |
*/
|
|
|
42 |
private $target;
|
|
|
43 |
|
|
|
44 |
/**
|
|
|
45 |
* The phing project configurator object
|
|
|
46 |
* @var ProjectConfigurator
|
|
|
47 |
*/
|
|
|
48 |
private $configurator;
|
|
|
49 |
|
|
|
50 |
/**
|
|
|
51 |
* Constructs a new TargetHandler
|
|
|
52 |
*
|
|
|
53 |
* @param object the ExpatParser object
|
|
|
54 |
* @param object the parent handler that invoked this handler
|
|
|
55 |
* @param object the ProjectConfigurator object
|
|
|
56 |
*/
|
|
|
57 |
function __construct(AbstractSAXParser $parser, AbstractHandler $parentHandler, ProjectConfigurator $configurator) {
|
|
|
58 |
parent::__construct($parser, $parentHandler);
|
|
|
59 |
$this->configurator = $configurator;
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
/**
|
|
|
63 |
* Executes initialization actions required to setup the data structures
|
|
|
64 |
* related to the tag.
|
|
|
65 |
* <p>
|
|
|
66 |
* This includes:
|
|
|
67 |
* <ul>
|
|
|
68 |
* <li>creation of the target object</li>
|
|
|
69 |
* <li>calling the setters for attributes</li>
|
|
|
70 |
* <li>adding the target to the project</li>
|
|
|
71 |
* <li>adding a reference to the target (if id attribute is given)</li>
|
|
|
72 |
* </ul>
|
|
|
73 |
*
|
|
|
74 |
* @param string the tag that comes in
|
|
|
75 |
* @param array attributes the tag carries
|
|
|
76 |
* @throws ExpatParseException if attributes are incomplete or invalid
|
|
|
77 |
*/
|
|
|
78 |
function init($tag, $attrs) {
|
|
|
79 |
$name = null;
|
|
|
80 |
$depends = "";
|
|
|
81 |
$ifCond = null;
|
|
|
82 |
$unlessCond = null;
|
|
|
83 |
$id = null;
|
|
|
84 |
$description = null;
|
|
|
85 |
|
|
|
86 |
foreach($attrs as $key => $value) {
|
|
|
87 |
if ($key==="name") {
|
|
|
88 |
$name = (string) $value;
|
|
|
89 |
} else if ($key==="depends") {
|
|
|
90 |
$depends = (string) $value;
|
|
|
91 |
} else if ($key==="if") {
|
|
|
92 |
$ifCond = (string) $value;
|
|
|
93 |
} else if ($key==="unless") {
|
|
|
94 |
$unlessCond = (string) $value;
|
|
|
95 |
} else if ($key==="id") {
|
|
|
96 |
$id = (string) $value;
|
|
|
97 |
} else if ($key==="description") {
|
|
|
98 |
$description = (string)$value;
|
|
|
99 |
} else {
|
|
|
100 |
throw new ExpatParseException("Unexpected attribute '$key'", $this->parser->getLocation());
|
|
|
101 |
}
|
|
|
102 |
}
|
|
|
103 |
|
|
|
104 |
if ($name === null) {
|
|
|
105 |
throw new ExpatParseException("target element appears without a name attribute", $this->parser->getLocation());
|
|
|
106 |
}
|
|
|
107 |
|
|
|
108 |
// shorthand
|
|
|
109 |
$project = $this->configurator->project;
|
|
|
110 |
|
|
|
111 |
$this->target = new Target();
|
|
|
112 |
$this->target->setName($name);
|
|
|
113 |
$this->target->setIf($ifCond);
|
|
|
114 |
$this->target->setUnless($unlessCond);
|
|
|
115 |
$this->target->setDescription($description);
|
|
|
116 |
|
|
|
117 |
$project->addTarget($name, $this->target);
|
|
|
118 |
|
|
|
119 |
if ($id !== null && $id !== "") {
|
|
|
120 |
$project->addReference($id, $this->target);
|
|
|
121 |
}
|
|
|
122 |
// take care of dependencies
|
|
|
123 |
if (strlen($depends) > 0) {
|
|
|
124 |
$this->target->setDepends($depends);
|
|
|
125 |
}
|
|
|
126 |
|
|
|
127 |
}
|
|
|
128 |
|
|
|
129 |
/**
|
|
|
130 |
* Checks for nested tags within the current one. Creates and calls
|
|
|
131 |
* handlers respectively.
|
|
|
132 |
*
|
|
|
133 |
* @param string the tag that comes in
|
|
|
134 |
* @param array attributes the tag carries
|
|
|
135 |
*/
|
|
|
136 |
function startElement($name, $attrs) {
|
|
|
137 |
// shorthands
|
|
|
138 |
$project = $this->configurator->project;
|
|
|
139 |
$types = $project->getDataTypeDefinitions();
|
|
|
140 |
|
|
|
141 |
if (isset($types[$name])) {
|
|
|
142 |
$th = new DataTypeHandler($this->parser, $this, $this->configurator, $this->target);
|
|
|
143 |
$th->init($name, $attrs);
|
|
|
144 |
} else {
|
|
|
145 |
$tmp = new TaskHandler($this->parser, $this, $this->configurator, $this->target, null, $this->target);
|
|
|
146 |
$tmp->init($name, $attrs);
|
|
|
147 |
}
|
|
|
148 |
}
|
|
|
149 |
}
|