Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
 
3
/*
4
 *  $Id: ContainsCondition.php 410 2008-10-21 13:10:52Z hans $
5
 *
6
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
7
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
8
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
9
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
10
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
11
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
12
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
13
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
14
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
15
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
16
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17
 *
18
 * This software consists of voluntary contributions made by many individuals
19
 * and is licensed under the LGPL. For more information please see
20
 * <http://phing.info>.
21
 */
22
 
23
require_once 'phing/tasks/system/condition/Condition.php';
24
 
25
/**
26
 * Is one string part of another string?
27
 *
28
 * @author Hans Lellelid <hans@xmpl.org> (Phing)
29
 * @author Stefan Bodewig <stefan.bodewig@epost.de> (Ant)
30
 * @version $Revision: 1.3 $
31
 * @package phing.tasks.system.condition
32
 */
33
class ContainsCondition implements Condition {
34
 
35
    private $string;
36
    private $subString;
37
    private $caseSensitive = true;
38
 
39
    /**
40
     * The string to search in.
41
     * @param string $a1
42
     */
43
    public function setString($a1) {
44
        $this->string = $a1;
45
    }
46
 
47
    /**
48
     * The string to search for.
49
     * @param string $a2
50
     */
51
    public function setSubstring($a2) {
52
        $this->subString = $a2;
53
    }
54
 
55
    /**
56
     * Whether to search ignoring case or not.
57
     */
58
    public function setCaseSensitive($b) {
59
        $this->caseSensitive = (boolean) $b;
60
    }
61
 
62
    /**
63
     * Check whether string contains substring.
64
     * @throws BuildException
65
     */
66
    public function evaluate()  {
67
        if ($this->string === null || $this->subString === null) {
68
            throw new BuildException("both string and substring are required "
69
                                     . "in contains");
70
        }
71
 
72
        return $this->caseSensitive
73
            ? strpos($this->string, $this->subString) !== false
74
            : strpos(strtolower($this->string), strtolower($this->subString)) !== false;
75
    }
76
}