|
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 <[email protected]> (Phing) |
|
31
|
|
|
* @author Craeg Strong <[email protected]> (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
|
5 |
|
public static function getAll(Project $project) |
|
45
|
|
|
{ |
|
46
|
5 |
|
$targets = $project->getTargets(); |
|
47
|
|
|
|
|
48
|
5 |
|
$description = ''; |
|
49
|
5 |
|
foreach ($targets as $t) { |
|
50
|
5 |
|
self::concatDescriptions($project, $t, $description); |
|
51
|
|
|
} |
|
52
|
5 |
|
return $description; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
5 |
|
private static function concatDescriptions(Project $project, Target $t, &$description) |
|
56
|
|
|
{ |
|
57
|
5 |
|
foreach (self::findElementInTarget($t, 'description') as $task) { |
|
58
|
5 |
|
if ($task instanceof UnknownElement) { |
|
59
|
5 |
|
$ue = $task; |
|
60
|
5 |
|
$descComp = $ue->getWrapper()->getText(); |
|
61
|
5 |
|
if ($descComp !== null) { |
|
62
|
5 |
|
$description .= $project->replaceProperties($descComp); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
5 |
|
} |
|
67
|
|
|
|
|
68
|
5 |
|
private static function findElementInTarget(Target $t, $name) |
|
69
|
|
|
{ |
|
70
|
5 |
|
return array_filter($t->getTasks(), static function (Task $task) use ($name) { |
|
71
|
5 |
|
return $task->getTaskName() === $name; |
|
72
|
5 |
|
}); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Adds descriptive text to the project. |
|
77
|
|
|
* |
|
78
|
|
|
* @param $text |
|
79
|
|
|
* @return void |
|
80
|
|
|
*/ |
|
81
|
5 |
|
public function addText($text) |
|
82
|
|
|
{ |
|
83
|
5 |
|
$currentDescription = $this->getProject()->getDescription(); |
|
84
|
5 |
|
if ($currentDescription === null) { |
|
85
|
|
|
$this->getProject()->setDescription($text); |
|
86
|
|
|
} else { |
|
87
|
5 |
|
$this->getProject()->setDescription($currentDescription); |
|
88
|
|
|
} |
|
89
|
5 |
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|