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
 * A regular expression datatype.  Keeps an instance of the
22
 * compiled expression for speed purposes.  This compiled
23
 * expression is lazily evaluated (it is compiled the first
24
 * time it is needed).  The syntax is the dependent on which
25
 * regular expression type you are using.
26
 *
27
 * @author  <a href="mailto:yl@seasonfive.com">Yannick Lecaillez</a>
28
 * @see     phing.util.regex.RegexMatcher
29
 * @package phing.types
30
 */
31
class RegularExpression extends DataType
32
{
33
    private $regexp = null;
34
    /**
35
     * @todo Probably both $ignoreCase and $multiline should be removed
36
     * from attribute list of RegularExpression class:
37
     * actual values are preserved on regexp *engine* level, not expression
38
     * object itself.
39
     */
40
    private $ignoreCase = false;
41
    private $multiline = false;
42

43
    /**
44
     *
45
     */
46 1
    public function __construct()
47
    {
48 1
        parent::__construct();
49 1
        $this->regexp = new Regexp();
50
    }
51

52
    /**
53
     * @param $pattern
54
     */
55 1
    public function setPattern($pattern)
56
    {
57 1
        $this->regexp->setPattern($pattern);
58
    }
59

60
    /**
61
     * @param $replace
62
     */
63 1
    public function setReplace($replace)
64
    {
65 1
        $this->regexp->setReplace($replace);
66
    }
67

68
    /**
69
     * @param $p
70
     * @return string
71
     * @throws BuildException
72
     */
73 0
    public function getPattern($p)
74
    {
75 0
        if ($this->isReference()) {
76 0
            $ref = $this->getRef($p);
77

78 0
            return $ref->getPattern($p);
79
        }
80

81 0
        return $this->regexp->getPattern();
82
    }
83

84
    /**
85
     * @param Project $p
86
     * @return string
87
     * @throws BuildException
88
     */
89 0
    public function getReplace($p)
90
    {
91 0
        if ($this->isReference()) {
92 0
            $ref = $this->getRef($p);
93

94 0
            return $ref->getReplace($p);
95
        }
96

97 0
        return $this->regexp->getReplace();
98
    }
99

100
    /**
101
     * @param $modifiers
102
     */
103 1
    public function setModifiers($modifiers)
104
    {
105 1
        $this->regexp->setModifiers($modifiers);
106
    }
107

108
    /**
109
     * @return string
110
     */
111 0
    public function getModifiers()
112
    {
113 0
        return $this->regexp->getModifiers();
114
    }
115

116
    /**
117
     * @param $bit
118
     */
119 1
    public function setIgnoreCase($bit)
120
    {
121 1
        $this->regexp->setIgnoreCase($bit);
122
    }
123

124
    /**
125
     * @return bool
126
     */
127 0
    public function getIgnoreCase()
128
    {
129 0
        return $this->regexp->getIgnoreCase();
130
    }
131

132
    /**
133
     * @param $multiline
134
     */
135 1
    public function setMultiline($multiline)
136
    {
137 1
        $this->regexp->setMultiline($multiline);
138
    }
139

140
    /**
141
     * @return bool
142
     */
143 0
    public function getMultiline()
144
    {
145 0
        return $this->regexp->getMultiline();
146
    }
147

148
    /**
149
     * @param Project $p
150
     * @return null|Regexp
151
     * @throws BuildException
152
     */
153 1
    public function getRegexp(Project $p)
154
    {
155 1
        if ($this->isReference()) {
156 0
            $ref = $this->getRef($p);
157

158 0
            return $ref->getRegexp($p);
159
        }
160

161 1
        return $this->regexp;
162
    }
163

164
    /**
165
     * @param Project $p
166
     * @return mixed
167
     * @throws BuildException
168
     */
169 0
    public function getRef(Project $p)
170
    {
171 0
        $dataTypeName = StringHelper::substring(__CLASS__, strrpos(__CLASS__, '\\') + 1);
172 0
        return $this->getCheckedRef(__CLASS__, $dataTypeName);
173
    }
174
}

Read our documentation on viewing source code .

Loading