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
|
|
* Description is used to provide a project-wide description element
|
22
|
|
* (that is, a description that applies to a buildfile as a whole).
|
23
|
|
* If present, the <description> element is printed out before the
|
24
|
|
* target descriptions.
|
25
|
|
*
|
26
|
|
* Description has no attributes, only text. There can only be one
|
27
|
|
* project description per project. A second description element will
|
28
|
|
* overwrite the first.
|
29
|
|
*
|
30
|
|
* @author Hans Lellelid <hans@xmpl.org> (Phing)
|
31
|
|
* @author Craeg Strong <cstrong@arielpartners.com> (Ant)
|
32
|
|
* @package phing.types
|
33
|
|
*/
|
34
|
|
class Description extends DataType
|
35
|
|
{
|
36
|
|
/**
|
37
|
|
* Return the descriptions from all the targets of
|
38
|
|
* a project.
|
39
|
|
*
|
40
|
|
* @param project the project to get the descriptions for.
|
41
|
|
* @return string containing the concatenated descriptions of
|
42
|
|
* the targets.
|
43
|
|
*/
|
44
|
1
|
public static function getAll(Project $project)
|
45
|
|
{
|
46
|
1
|
$targets = $project->getTargets();
|
47
|
|
|
48
|
1
|
$description = '';
|
49
|
1
|
foreach ($targets as $t) {
|
50
|
1
|
self::concatDescriptions($project, $t, $description);
|
51
|
|
}
|
52
|
1
|
return $description;
|
53
|
|
}
|
54
|
|
|
55
|
1
|
private static function concatDescriptions(Project $project, Target $t, &$description)
|
56
|
|
{
|
57
|
1
|
foreach (self::findElementInTarget($t, 'description') as $task) {
|
58
|
1
|
if ($task instanceof UnknownElement) {
|
59
|
1
|
$ue = $task;
|
60
|
1
|
$descComp = $ue->getWrapper()->getText();
|
61
|
1
|
if ($descComp !== null) {
|
62
|
1
|
$description .= $project->replaceProperties($descComp);
|
63
|
|
}
|
64
|
|
}
|
65
|
|
}
|
66
|
|
}
|
67
|
|
|
68
|
1
|
private static function findElementInTarget(Target $t, $name)
|
69
|
|
{
|
70
|
|
return array_filter($t->getTasks(), static function (Task $task) use ($name) {
|
71
|
1
|
return $task->getTaskName() === $name;
|
72
|
1
|
});
|
73
|
|
}
|
74
|
|
|
75
|
|
/**
|
76
|
|
* Adds descriptive text to the project.
|
77
|
|
*
|
78
|
|
* @param $text
|
79
|
|
* @return void
|
80
|
|
*/
|
81
|
1
|
public function addText($text)
|
82
|
|
{
|
83
|
1
|
$currentDescription = $this->getProject()->getDescription();
|
84
|
1
|
if ($currentDescription === null) {
|
85
|
0
|
$this->getProject()->setDescription($text);
|
86
|
|
} else {
|
87
|
1
|
$this->getProject()->setDescription($currentDescription);
|
88
|
|
}
|
89
|
|
}
|
90
|
|
}
|