Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/*
3
 *  $Id: EqualsCondition.php 43 2006-03-10 14:31:51Z mrook $
4
 *
5
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
6
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
7
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
8
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
9
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
10
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
12
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
13
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
15
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16
 *
17
 * This software consists of voluntary contributions made by many individuals
18
 * and is licensed under the LGPL. For more information please see
19
 * <http://phing.info>.
20
 */
21
 
22
require_once 'phing/tasks/system/condition/Condition.php';
23
 
24
/**
25
 *  A simple string comparator.  Compares two strings for eqiality in a
26
 *  binary safe manner. Implements the condition interface specification.
27
 *
28
 *  @author    Andreas Aderhold <andi@binarycloud.com>
29
 *  @copyright © 2001,2002 THYRELL. All rights reserved
30
 *  @version   $Revision: 1.7 $ $Date: 2006-03-10 15:31:51 +0100 (Fri, 10 Mar 2006) $
31
 *  @access    public
32
 *  @package   phing.tasks.system.condition
33
 */
34
class EqualsCondition implements Condition {
35
 
36
    private $arg1;
37
    private $arg2;
38
    private $trim = false;
39
    private $caseSensitive = true;
40
 
41
    public function setArg1($a1) {
42
        $this->arg1 = $a1;
43
    }
44
 
45
    public function setArg2($a2) {
46
        $this->arg2 = $a2;
47
    }
48
 
49
    /**
50
     * Should we want to trim the arguments before comparing them?
51
     * @param boolean $b
52
     */
53
    public function setTrim($b) {
54
        $this->trim = (boolean) $b;
55
    }
56
 
57
    /**
58
     * Should the comparison be case sensitive?
59
     * @param boolean $b
60
     */
61
    public function setCaseSensitive($b) {
62
        $this->caseSensitive = (boolean) $b;
63
    }
64
 
65
    public function evaluate() {
66
        if ($this->arg1 === null || $this->arg2 === null) {
67
            throw new BuildException("Both arg1 and arg2 are required in equals.");
68
        }
69
 
70
        if ($this->trim) {
71
            $this->arg1 = trim($this->arg1);
72
            $this->arg2 = trim($this->arg2);
73
        }
74
 
75
        //print("[comparison] Comparing '".$this->arg1."' and '".$this->arg2."'\n");
76
        return $this->caseSensitive ? $this->arg1 === $this->arg2 : strtolower($this->arg1) === strtolower($this->arg2);
77
    }
78
}