|
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
|
|
|
use Phing\Exception\BuildException; |
|
21
|
|
|
use Phing\Io\File; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* This is a condition that checks to see if a file passes an embedded selector. |
|
25
|
|
|
*/ |
|
26
|
|
|
class IsFileSelected extends AbstractSelectorContainer implements Condition |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* @var File $file |
|
30
|
|
|
*/ |
|
31
|
|
|
private $file; |
|
32
|
|
|
private $baseDir; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* The file to check. |
|
36
|
|
|
* |
|
37
|
|
|
* @param file the file to check if if passes the embedded selector. |
|
38
|
|
|
*/ |
|
39
|
6 |
|
public function setFile(File $file) |
|
40
|
|
|
{ |
|
41
|
6 |
|
$this->file = $file; |
|
42
|
6 |
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* The base directory to use. |
|
46
|
|
|
* |
|
47
|
|
|
* @param baseDir the base directory to use, if null use the project's |
|
48
|
|
|
* basedir. |
|
49
|
|
|
*/ |
|
50
|
|
|
public function setBaseDir(File $baseDir) |
|
51
|
|
|
{ |
|
52
|
|
|
$this->baseDir = $baseDir; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* validate the parameters. |
|
57
|
|
|
*/ |
|
58
|
6 |
|
public function validate() |
|
59
|
|
|
{ |
|
60
|
6 |
|
if ($this->count() != 1) { |
|
61
|
|
|
throw new BuildException("Only one selector allowed"); |
|
62
|
|
|
} |
|
63
|
6 |
|
parent::validate(); |
|
64
|
6 |
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Evaluate the selector with the file. |
|
68
|
|
|
* |
|
69
|
|
|
* @return true if the file is selected by the embedded selector. |
|
70
|
|
|
*/ |
|
71
|
6 |
|
public function evaluate() |
|
72
|
|
|
{ |
|
73
|
6 |
|
if ($this->file === null) { |
|
74
|
|
|
throw new BuildException('file attribute not set'); |
|
75
|
|
|
} |
|
76
|
6 |
|
$this->validate(); |
|
77
|
6 |
|
$myBaseDir = $this->baseDir; |
|
78
|
6 |
|
if ($myBaseDir === null) { |
|
79
|
6 |
|
$myBaseDir = $this->getProject()->getBaseDir(); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @var FileSelector $f |
|
84
|
|
|
*/ |
|
85
|
6 |
|
$file = $this->getSelectors($this->getProject()); |
|
86
|
6 |
|
$f = $file[0]; |
|
87
|
6 |
|
return $f->isSelected($myBaseDir, $this->file->getName(), $this->file); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|