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
 * Simple regular expression condition.
22
 *
23
 * @author  Siad Ardroumli <siad.ardroumli@gmail.com>
24
 * @package phing.tasks.system.condition
25
 */
26
class Matches extends ProjectComponent implements Condition
27
{
28
    /**
29
     * @var string $string
30
     */
31
    private $string;
32

33
    /**
34
     * @var RegularExpression $regularExpression
35
     */
36
    private $regularExpression;
37

38
    /**
39
     * @var bool $multiLine
40
     */
41
    private $multiLine = false;
42

43
    /**
44
     * @var bool $caseSensitive
45
     */
46
    private $caseSensitive = true;
47

48
    /**
49
     * @var string $modifiers
50
     */
51
    private $modifiers;
52

53
    /**
54
     * @param boolean $caseSensitive
55
     */
56 1
    public function setCaseSensitive($caseSensitive)
57
    {
58 1
        $this->caseSensitive = $caseSensitive;
59
    }
60

61
    /**
62
     * Whether to match should be multiline.
63
     *
64
     * @param boolean $multiLine
65
     */
66 0
    public function setMultiLine($multiLine)
67
    {
68 0
        $this->multiLine = $multiLine;
69
    }
70

71
    /**
72
     * @param string $pattern
73
     * @throws \BuildException
74
     */
75 1
    public function setPattern($pattern)
76
    {
77 1
        if ($this->regularExpression !== null) {
78 0
            throw new BuildException('Only one regular expression is allowed.');
79
        }
80 1
        $this->regularExpression = new RegularExpression();
81 1
        $this->regularExpression->setPattern($pattern);
82
    }
83

84
    /**
85
     * The string to match
86
     *
87
     * @param string $string
88
     */
89 1
    public function setString($string)
90
    {
91 1
        $this->string = $string;
92
    }
93

94
    /**
95
     * @param string $modifiers
96
     */
97 0
    public function setModifiers($modifiers)
98
    {
99 0
        $this->modifiers = $modifiers;
100
    }
101

102 1
    public function evaluate()
103
    {
104 1
        if ($this->string === null) {
105 0
            throw new BuildException('Parameter string is required in matches.');
106
        }
107 1
        if ($this->regularExpression === null) {
108 0
            throw new BuildException('Missing pattern in matches.');
109
        }
110 1
        $this->regularExpression->setMultiline($this->multiLine);
111 1
        $this->regularExpression->setIgnoreCase(!$this->caseSensitive);
112 1
        $this->regularExpression->setModifiers($this->modifiers);
113 1
        $regexp = $this->regularExpression->getRegexp($this->getProject());
114

115 1
        return $regexp->matches($this->string);
116
    }
117
}

Read our documentation on viewing source code .

Loading