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
|
|
* A class for creating adhoc datatypes in build file.
|
22
|
|
*
|
23
|
|
* @author Hans Lellelid <hans@xmpl.org>
|
24
|
|
* @package phing.tasks.system
|
25
|
|
*/
|
26
|
|
class AdhocTypedefTask extends AdhocTask
|
27
|
|
{
|
28
|
|
|
29
|
|
/**
|
30
|
|
* The tag that refers to this task.
|
31
|
|
*/
|
32
|
|
private $name;
|
33
|
|
|
34
|
|
/**
|
35
|
|
* Set the tag that will represent this adhoc task/type.
|
36
|
|
*
|
37
|
|
* @param string $name
|
38
|
|
*/
|
39
|
0
|
public function setName($name)
|
40
|
|
{
|
41
|
0
|
$this->name = $name;
|
42
|
|
}
|
43
|
|
|
44
|
|
/**
|
45
|
|
* Main entry point
|
46
|
|
*/
|
47
|
0
|
public function main()
|
48
|
|
{
|
49
|
0
|
if ($this->name === null) {
|
50
|
0
|
throw new BuildException("The name attribute is required for adhoc task definition.", $this->getLocation());
|
51
|
|
}
|
52
|
|
|
53
|
0
|
$this->execute();
|
54
|
|
|
55
|
0
|
$classes = $this->getNewClasses();
|
56
|
0
|
if (count($classes) !== 1) {
|
57
|
0
|
throw new BuildException("You must define one (and only one) class for AdhocTypedefTask.");
|
58
|
|
}
|
59
|
0
|
$classname = array_shift($classes);
|
60
|
|
|
61
|
|
// instantiate it to make sure it is an instance of ProjectComponent
|
62
|
0
|
$t = new $classname();
|
63
|
0
|
if (!($t instanceof ProjectComponent)) {
|
64
|
0
|
throw new BuildException(
|
65
|
0
|
"The adhoc class you defined must be an instance of phing.ProjectComponent",
|
66
|
0
|
$this->getLocation()
|
67
|
|
);
|
68
|
|
}
|
69
|
|
|
70
|
0
|
$this->log("Datatype " . $this->name . " will be handled by class " . $classname, Project::MSG_VERBOSE);
|
71
|
0
|
$this->project->addDataTypeDefinition($this->name, $classname);
|
72
|
|
}
|
73
|
|
}
|