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
|
|
* Class to keep track of the position of an Argument.
|
22
|
|
*
|
23
|
|
* <p>This class is there to support the srcfile and targetfile
|
24
|
|
* elements of <execon> and <transform> - don't know
|
25
|
|
* whether there might be additional use cases.</p> --SB
|
26
|
|
*
|
27
|
|
* @package phing.types
|
28
|
|
*/
|
29
|
|
class CommandlineMarker
|
30
|
|
{
|
31
|
|
private $position;
|
32
|
|
private $realPos = -1;
|
33
|
|
private $outer;
|
34
|
|
private $prefix;
|
35
|
|
private $suffix;
|
36
|
|
|
37
|
|
/**
|
38
|
|
* @param Commandline $outer
|
39
|
|
* @param $position
|
40
|
|
*/
|
41
|
1
|
public function __construct(Commandline $outer, $position)
|
42
|
|
{
|
43
|
1
|
$this->outer = $outer;
|
44
|
1
|
$this->position = $position;
|
45
|
|
}
|
46
|
|
|
47
|
|
/**
|
48
|
|
* Return the number of arguments that preceded this marker.
|
49
|
|
*
|
50
|
|
* <p>The name of the executable - if set - is counted as the
|
51
|
|
* very first argument.</p>
|
52
|
|
*/
|
53
|
1
|
public function getPosition()
|
54
|
|
{
|
55
|
1
|
if ($this->realPos === -1) {
|
56
|
1
|
$this->realPos = ($this->outer->executable === null ? 0 : 1);
|
57
|
1
|
for ($i = 0; $i < $this->position; $i++) {
|
58
|
1
|
$arg = $this->outer->arguments[$i];
|
59
|
1
|
$this->realPos += count($arg->getParts());
|
60
|
|
}
|
61
|
|
}
|
62
|
|
|
63
|
1
|
return $this->realPos;
|
64
|
|
}
|
65
|
|
|
66
|
|
/**
|
67
|
|
* Set the prefix to be placed in front of the inserted argument.
|
68
|
|
*
|
69
|
|
* @param string $prefix fixed prefix string.
|
70
|
|
*/
|
71
|
0
|
public function setPrefix($prefix)
|
72
|
|
{
|
73
|
0
|
$this->prefix = $prefix ?? '';
|
74
|
|
}
|
75
|
|
|
76
|
|
/**
|
77
|
|
* Get the prefix to be placed in front of the inserted argument.
|
78
|
|
*/
|
79
|
0
|
public function getPrefix()
|
80
|
|
{
|
81
|
0
|
return $this->prefix;
|
82
|
|
}
|
83
|
|
|
84
|
|
/**
|
85
|
|
* Set the suffix to be placed at the end of the inserted argument.
|
86
|
|
*
|
87
|
|
* @param string $suffix fixed suffix string.
|
88
|
|
*/
|
89
|
0
|
public function setSuffix($suffix)
|
90
|
|
{
|
91
|
0
|
$this->suffix = $suffix ?? '';
|
92
|
|
}
|
93
|
|
|
94
|
|
/**
|
95
|
|
* Get the suffix to be placed at the end of the inserted argument.
|
96
|
|
*/
|
97
|
0
|
public function getSuffix()
|
98
|
|
{
|
99
|
0
|
return $this->suffix;
|
100
|
|
}
|
101
|
|
}
|