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
|
|
* Is one string part of another string?
|
22
|
|
*
|
23
|
|
* @author Hans Lellelid <hans@xmpl.org> (Phing)
|
24
|
|
* @author Stefan Bodewig <stefan.bodewig@epost.de> (Ant)
|
25
|
|
* @package phing.tasks.system.condition
|
26
|
|
*/
|
27
|
|
class ContainsCondition implements Condition
|
28
|
|
{
|
29
|
|
private $string;
|
30
|
|
private $subString;
|
31
|
|
private $caseSensitive = true;
|
32
|
|
|
33
|
|
/**
|
34
|
|
* The string to search in.
|
35
|
|
*
|
36
|
|
* @param string $a1
|
37
|
|
*/
|
38
|
1
|
public function setString($a1)
|
39
|
|
{
|
40
|
1
|
$this->string = $a1;
|
41
|
|
}
|
42
|
|
|
43
|
|
/**
|
44
|
|
* The string to search for.
|
45
|
|
*
|
46
|
|
* @param string $a2
|
47
|
|
*/
|
48
|
1
|
public function setSubstring($a2)
|
49
|
|
{
|
50
|
1
|
$this->subString = $a2;
|
51
|
|
}
|
52
|
|
|
53
|
|
/**
|
54
|
|
* Whether to search ignoring case or not.
|
55
|
|
*
|
56
|
|
* @param $b
|
57
|
|
*/
|
58
|
1
|
public function setCaseSensitive($b)
|
59
|
|
{
|
60
|
1
|
$this->caseSensitive = (bool) $b;
|
61
|
|
}
|
62
|
|
|
63
|
|
/**
|
64
|
|
* Check whether string contains substring.
|
65
|
|
*
|
66
|
|
* @throws BuildException
|
67
|
|
*/
|
68
|
1
|
public function evaluate()
|
69
|
|
{
|
70
|
1
|
if ($this->string === null || $this->subString === null) {
|
71
|
0
|
throw new BuildException(
|
72
|
|
"both string and substring are required "
|
73
|
0
|
. "in contains"
|
74
|
|
);
|
75
|
|
}
|
76
|
|
|
77
|
1
|
return $this->caseSensitive
|
78
|
1
|
? strpos($this->string, $this->subString) !== false
|
79
|
1
|
: stripos($this->string, $this->subString) !== false;
|
80
|
|
}
|
81
|
|
}
|