Changeset 119

User picture

Author: Thiago Mata

(2009/06/15 22:10) Over 2 years ago

rule match it is more mature. Next step it is make the code reflection use it. After that make the stereotypes rules.

Affected files

Updated components/ruleMatchList/example/ruleMatchListExample1.php Download diff

118119
9
9
10
$objRule = new RuleMatchList();
10
$objRule = new RuleMatchList();
11
$objRule->addIgnoredName( "something" );
11
$objRule->addIgnoredName( "something" );
12
print serialize( $objRule->validate( "else" ) ) ; // 1
12
print serialize( $objRule->match( "else" ) ) ; // 1
13
print serialize( $objRule->validate( "something" ) ) ;  // 0
13
print serialize( $objRule->match( "something" ) ) ;  // 0
14
$objRule->addExclusiveName( "noop" );
14
$objRule->addExclusiveName( "noop" );
15
print serialize( $objRule->validate( "else" ) ) ; // 0
15
print serialize( $objRule->match( "else" ) ) ; // 0
16
print serialize( $objRule->validate( "noop" ) ) ;  // 1
16
print serialize( $objRule->match( "noop" ) ) ;  // 1
17
17
18
?>
18
?>

Updated components/ruleMatchList/RuleMatch.class.php Download diff

118119
47
     */
47
     */
48
    public function setNameList( $arrNameList )
48
    public function setNameList( $arrNameList )
49
    {
49
    {
50
        $this->setNameList( $arrNameList );
50
        $this->objNameRuleList->setNameList( $arrNameList );
51
        return $this;
51
        return $this;
52
    }
52
    }
53
53
...
...
57
     */
57
     */
58
    public function getNameList()
58
    public function getNameList()
59
    {
59
    {
60
        return $this->getNameList();
60
        return $this->objNameRuleList->getNameList();
61
    }
61
    }
62
62
63
63
...
...
119
    }
119
    }
120
120
121
    /**
121
    /**
122
     * Search the element into the array and returns true if founded
123
     * and false if not
124
     *
125
     * @param string $strName
126
     * @return boolean
127
     */
128
    public function found( $strName )
129
    {
130
        if ( $this->objNameRuleList->found( $strName ) )
131
        {
132
            return TRUE;
133
        }
134
        else
135
        {
136
            return $this->objRegexRuleList->found( $strName );
137
        }
138
    }
139
140
    /**
141
     * Returns if the rule is empty
142
     *
143
     * @return boolean
144
     */
145
    public function isEmpty()
146
    {
147
        return ( $this->objNameRuleList->isEmpty() && $this->objRegexRuleList->isEmpty() );
148
    }
149
150
    /**
151
     * Match the string name
152
     * 
122
     * @see RuleNameMatch::match( string )
153
     * @see RuleNameMatch::match( string )
123
     * @see RuleRegularExpressionMatch::match( string )
154
     * @see RuleRegularExpressionMatch::match( string )
124
     * @return mixer
155
     * @return mixer

Updated components/ruleMatchList/RuleMatchList.class.php Download diff

118119
13
{
13
{
14
    /**
14
    /**
15
     *
15
     *
16
     * @var RuleNameMatch
16
     * @var RuleMatch
17
     */
17
     */
18
    protected $objIgnoredNameList = null;
18
    protected $objIgnoredRuleMatch = null;
19
19
20
    /**
20
    /**
21
     *
21
     *
22
     * @var RuleNameMatch
22
     * @var RuleMatch
23
     */
23
     */
24
    protected $objNameList = null;
24
    protected $objExclusiveRuleMatch = null;
25
25
26
    /**
26
    /**
27
     * Array with the string name values what should be not
28
     * be added into this match
29
     *
27
     *
30
     * If is empty, no one will be ignored
28
     * @var mixer 
31
     *
32
     * @var string[]
33
     */
29
     */
34
    protected $arrIgnoredNameList = array();
30
    protected $mixNotFoundValue = TRUE;
35
31
36
    /**
32
    public function __construct()
37
     * Array with the regular expressions of the values
33
    {
38
     * what should be not be added into this match
34
        $this->objIgnoredRuleMatch = new RuleMatch();
39
     *
35
        $this->objExclusiveRuleMatch = new ruleMatch();
40
     * If is empty, no one will be ignored
36
    }
41
     *
42
     * @var string[]
43
     */
44
    protected $arrIgnoredRegularExpressionList = array();
45
37
46
    /**
38
    /*
47
     * Array with the string name list of the exclusive
48
     * names what should be match
49
     *
39
     *
50
     * If is empty, anyone can enter.
40
     * @param RuleMatch $objIgnoredRuleMatch
51
     *
52
     * @var string[]
53
     */
54
    protected $arrExclusiveNameList = array();
55
56
    /**
57
     * Array with the string list name of the exclusive
58
     * regular expressions what should be match
59
     *
60
     * If is empty, anyone can enter.
61
     *
62
     * @var string[]
63
     */
64
    protected $arrExclusiveRegularExpressionList = array();
65
66
    /**
67
     * Set the array with the ignored list name of the match
68
     *
69
     * @see RuleMatchList->arrIgnoredNameList
70
     * @see RuleMatchList::getIgnoredNameList()
71
     * @param String[] $arrIgnoredNameList
72
     * @return RuleMatchList me
41
     * @return RuleMatchList me
73
     */
42
     */
74
    public function setIgnoredNameList( array $arrIgnoredNameList )
43
    public function setIgnoredRuleMatch( RuleMatch $objIgnoredRuleMatch )
75
    {
44
    {
76
    	$this->arrIgnoredNameList = $arrIgnoredNameList;
45
        $this->objIgnoredRuleMatch = $objIgnoredRuleMatch;
77
    	return $this;
46
        return $this;
78
    }
47
    }
79
48
80
    /**
49
    /**
81
     * get the array with the ignored list name of the match
82
     *
50
     *
83
     * @see RuleMatchList->arrIgnoredNameList
51
     * @return RuleMatch
84
     * @see RuleMatchList::setIgnoredNameList( String[] )
85
     * @return String[] $arrIgnoredNameList
86
     */
52
     */
87
    public function getIgnoredNameList()
53
    public function getIgnoredMatchList()
88
    {
54
    {
89
    	return $this->arrIgnoredNameList;
55
        return $this->objIgnoredRuleMatch;
90
    }
56
    }
91
57
92
    /**
58
    /**
93
     * Add a string element name into the ignore list string
94
     *
59
     *
95
     * @see RuleMatchList->arrIgnoredNametString
60
     * @see RuleMatch::addName( string , mixer )
96
     * @see RuleMatchList::setIgnoredListString( String[] )
97
     * @see RuleMatchList::getIgnoredListString()
98
     * @param string $strIgnoredName
61
     * @param string $strIgnoredName
99
     * @return RuleMatchList me
62
     * @return RuleMatchList me
100
     */
63
     */
101
    public function addIgnoredName( $strIgnoredName )
64
    public function addIgnoredName( $strIgnoredName )
102
    {
65
    {
103
    	$this->arrIgnoredNameList[] = $strIgnoredName;
66
        $this->getIgnoredMatchList()->addName( $strIgnoredName , TRUE );
104
    	return $this;
67
        return $this;
105
    }
68
    }
106
69
107
    /**
70
    /**
108
     * Set the array with the exclusive name into the match
109
     *
71
     *
110
     * @see RuleMatchList->arrExclusiveNameList
72
     * @see RuleMatch::addRegularExpression( string , mixer )
111
     * @see RuleMatchList::getExclusiveNameList()
73
     * @param string $strIgnoreName
112
     * @param String[] $arrExclusiveNameList
113
     * @return RuleMatchList me
74
     * @return RuleMatchList me
114
     */
75
     */
115
    public function setExclusiveNameList( $arrExclusiveNameList )
76
    public function addIgnoredRegularExpression( $strIgnoredRegex)
116
    {
77
    {
117
    	$this->arrExclusiveNameList = $arrExclusiveNameList;
78
        $this->getIgnoredMatchList()->addRegularExpression( $strIgnoredRegex, TRUE );
118
    	return $this;
79
        return $this;
119
    }
80
    }
120
81
121
    /**
122
     * get the array with the exclusive name into the match
123
     *
124
     * @see RuleMatchList->arrExclusiveNameList
125
     * @see RuleMatchList::setExclusiveNameList( String[] )
126
     * @return String[] $arrExclusiveNameList
127
     */
128
    public function getExclusiveNameList()
129
    {
130
    	return $this->arrExclusiveNameList;
131
    }
132
82
133
    /**
83
    /**
134
     * Add a class name into the exclusive name list
135
     *
84
     *
136
     * @see RuleMatchList->arrExclusiveNameList
85
     * @param RuleMatch $objExclusiveRuleMatch
137
     * @see RuleMatchList::setExclusiveNameList( String[] )
138
     * @see RuleMatchList::getExclusiveClasses()
139
     * @param string $strExclusiveName
140
     * @return RuleMatchList me
86
     * @return RuleMatchList me
141
     */
87
     */
142
    public function addExclusiveName( $strExclusiveName )
88
    public function setExclusiveRuleMatch( RuleMatch $objExclusiveRuleMatch )
143
    {
89
    {
144
    	$this->arrExclusiveNameList[] = $strExclusiveName;
90
        $this->objExclusiveRuleMatch = $objExclusiveRuleMatch;
145
    	return $this;
91
        return $this;
146
    }
92
    }
147
93
148
    /**
94
    /**
149
     * Set the array with the Ignored Regular Expression into the match
150
     *
95
     *
151
     * @see RuleMatchList->arrIgnoredRegularExpressionList
96
     * @return RuleMatch
152
     * @see RuleMatchList::getIgnoredRegularExpressionList()
153
     * @param String[] $arrIgnoredRegularExpressionList
154
     * @return RuleMatchList me
155
     */
97
     */
156
    public function setIgnoredRegularExpressionList( $arrIgnoredRegularExpressionList )
98
    public function getExclusiveMatchList()
157
    {
99
    {
158
    	$this->arrIgnoredRegularExpressionList = $arrIgnoredRegularExpressionList;
100
        return $this->objExclusiveRuleMatch;
159
    	return $this;
160
    }
101
    }
161
102
162
    /**
103
    /**
163
     * get the array with the Ignored Regular Expression into the match
104
     * add a exclusive name into the rule
164
     *
105
     *
165
     * @see RuleMatchList->arrIgnoredRegularExpressionList
106
     * @see RuleMatch::addName( string , mixer )
166
     * @see RuleMatchList::setIgnoredRegularExpressionList( String[] )
107
     * @param string $strExclusiveName
167
     * @return String[] $arrIgnoredRegularExpressionList
108
     * @param mixer $mixValue value of the element. Beware!
168
     */
169
    public function getIgnoredRegularExpressionList()
170
    {
171
    	return $this->arrIgnoredRegularExpressionList;
172
    }
173
174
    /**
175
     * Add a class Regular Expression into the Ignored Regular Expression list
176
     *
177
     * @see RuleMatchList->arrIgnoredRegularExpressionList
178
     * @see RuleMatchList::setIgnoredRegularExpressionList( String[] )
179
     * @see RuleMatchList::getIgnoredClasses()
180
     * @param string $strIgnoredRegularExpression
181
     * @return RuleMatchList me
109
     * @return RuleMatchList me
182
     */
110
     */
183
    public function addIgnoredRegularExpression( $strIgnoredRegularExpression )
111
    public function addExclusiveName( $strExclusiveName , $mixValue = TRUE )
184
    {
112
    {
185
    	$this->arrIgnoredRegularExpressionList[] = $strIgnoredRegularExpression;
113
        $this->getExclusiveMatchList()->addName( $strExclusiveName , $mixValue);
186
    	return $this;
114
        return $this;
187
    }
115
    }
188
116
189
    /**
117
    /**
190
     * Set the array with the exclusive Regular Expression into the match
191
     *
118
     *
192
     * @see RuleMatchList->arrExclusiveRegularExpressionList
119
     * @see RuleMatch::addRegularExpression( string , mixer )
193
     * @see RuleMatchList::getExclusiveRegularExpressionList()
120
     * @param string $strIgnoreName
194
     * @param String[] $arrExclusiveRegularExpressionList
195
     * @return RuleMatchList me
121
     * @return RuleMatchList me
196
     */
122
     */
197
    public function setExclusiveRegularExpressionList( $arrExclusiveRegularExpressionList )
123
    public function addExclusiveRegularExpression( $strExclusiveRegex )
198
    {
124
    {
199
    	$this->arrExclusiveRegularExpressionList = $arrExclusiveRegularExpressionList;
125
        return $this;
200
    	return $this;
201
    }
126
    }
202
127
203
    /**
128
    /**
204
     * get the array with the exclusive Regular Expression into the match
129
     * Set the value what should be return when the name
130
     * not be found into any list
205
     *
131
     *
206
     * @see RuleMatchList->arrExclusiveRegularExpressionList
132
     * @param mixer $mixValue
207
     * @see RuleMatchList::setExclusiveRegularExpressionList( String[] )
208
     * @return String[] $arrExclusiveRegularExpressionList
209
     */
133
     */
210
    public function getExclusiveRegularExpressionList()
134
    public function setNotFoundValue( $mixValue )
211
    {
135
    {
212
    	return $this->arrExclusiveRegularExpressionList;
136
        $this->mixNotFoundValue = $mixValue;
213
    }
137
    }
214
138
215
    /**
139
    /**
216
     * Add a class Regular Expression into the exclusive Regular Expression list
140
     * Get the value what shoul be return when the name
141
     * not be found into any list
217
     *
142
     *
218
     * @see RuleMatchList->arrExclusiveRegularExpressionList
143
     * @return mixer
219
     * @see RuleMatchList::setExclusiveRegularExpressionList( String[] )
220
     * @see RuleMatchList::getExclusiveClasses()
221
     * @param string $strExclusiveRegularExpression
222
     * @return RuleMatchList me
223
     */
144
     */
224
    public function addExclusiveRegularExpression( $strExclusiveRegularExpression )
145
    public function getNotFoundValue()
225
    {
146
    {
226
    	$this->arrExclusiveRegularExpressionList[] = $strExclusiveRegularExpression;
147
        return $this->mixNotFoundValue;
227
    	return $this;
228
    }
148
    }
229
149
230
    /**
150
    /**
231
     * Validate the string name by the rules into the match and returns true
151
     * Match the string name
232
     * if should be considered and false if should not
152
     *  
233
     *
234
     * @param string $strName
153
     * @param string $strName
235
     * @return boolean
154
     * @return mixer 
236
     */
155
     */
237
    public function validate( $strName , $strFullName = '' )
156
    public function match( $strName )
238
    {
157
    {
239
        // returns if it is into ignore list
158
        if( $this->getExclusiveMatchList()->isEmpty() == FALSE )
240
        if(
241
            ( count( $this->getIgnoredNameList() ) > 0 )
242
             and
243
             (
244
             	( in_array( $strName , $this->getIgnoredNameList() ) )
245
                ||
246
             	( in_array( $strFullName , $this->getIgnoredNameList() ) )
247
             )
248
          )
249
        {
159
        {
250
            return false;
160
            return ( $this->getExclusiveMatchList()->match( $strName ) );
251
        }
161
        }
252
162
        else
253
        // returns if it is not into the exclusive list
254
        if(
255
            ( count( $this->getExclusiveNameList() ) > 0 )
256
             and
257
             (
258
             	( ! in_array( $strName , $this->getExclusiveNameList() ) )
259
             	&&
260
             	( ! in_array( $strFullName , $this->getExclusiveNameList() ) )
261
             )
262
          )
263
        {
163
        {
264
            return false;
164
            if( $this->getIgnoredMatchList()->isEmpty() == FALSE )
265
        }
266
267
        // exists a ignore regular expression list //
268
        if( count( $this->getIgnoredRegularExpressionList() ) > 0 )
269
        {
270
            foreach( $this->getIgnoredRegularExpressionList() as $strRegex )
271
            {
165
            {
272
                if( ereg( $strRegex , $strMethod ) || ereg( $strRegex , $strFullName ) )
166
                if( $this->getIgnoredMatchList()->found( $strName ) )
273
                {
167
                {
274
                    // and the method match into //
168
                    return FALSE;
275
                    return false;
276
                }
169
                }
277
            }
170
            }
278
        }
171
        }
279
172
        return $this->getNotFoundValue();
280
        // exists a exclusive methods regular expression list //
281
        if( count( $this->getExclusiveRegularExpressionList() ) > 0 )
282
        {
283
            foreach( $this->getExclusiveRegularExpressionList() as $strRegex )
284
            {
285
                if( ereg( $strRegex , $strName ) || ereg( $strRegex , $strFullName ) )
286
                {
287
                    // and the element match into //
288
                    return true;
289
                }
290
            }
291
            // and the element not match into //
292
            return false;
293
        }
294
295
        // not reasons was founded to ignore this element //
296
        return true;
297
    }
173
    }
298
}
174
}
299
?>
175
?>

Updated components/ruleMatchList/RuleNameMatch.class.php Download diff

118119
126
    }
126
    }
127
127
128
    /**
128
    /**
129
     * Returns if the rule is empty
130
     *
131
     * @return boolean
132
     */
133
    public function isEmpty()
134
    {
135
        return ( sizeof( $this->arrNameList ) == 0 );
136
    }
137
138
    /**
129
     * Match the string name
139
     * Match the string name
130
     *
140
     *
131
     * @param string $strName
141
     * @param string $strName

Updated components/ruleMatchList/RuleRegularExpressionMatch.class.php Download diff

118119
110
     * Search the element into the array and returns true if founded
110
     * Search the element into the array and returns true if founded
111
     * and false if not
111
     * and false if not
112
     *
112
     *
113
     * @param string $strRegularExpression
113
     * @param string $strName
114
     * @return boolean
114
     * @return boolean
115
     */
115
     */
116
    public function found( $strRegularExpression )
116
    public function found( $strName )
117
    {
117
    {
118
        if ( in_array( $strRegularExpression , $this->arrRegularExpressionList ) )
118
        foreach( $this->arrRegularExpressionList  as $intRegularExpressionKey => $strRegularExpression )
119
        {
119
        {
120
            return TRUE;
120
            if( ereg( $strRegularExpression , $strName ) )
121
            {
122
                return TRUE;
123
            }
121
        }
124
        }
122
        else
125
123
        {
126
        return FALSE;
124
            return FALSE;
125
        }
126
    }
127
    }
127
128
128
    /**
129
    /**
130
     * Returns if the rule is empty
131
     *
132
     * @return boolean
133
     */
134
    public function isEmpty()
135
    {
136
        return ( sizeof( $this->arrRegularExpressionList ) == 0 );
137
    }
138
139
140
    /**
129
     * Match the string RegularExpression
141
     * Match the string RegularExpression
130
     *
142
     *
131
     * @param string $strRegularExpression
143
     * @param string $strRegularExpression