
Public Member Functions | |
| setNotFoundValue ($objNotFoundValue) | |
| getNotFoundValue () | |
| setDefaultItemValue ($objDefaultItemValue) | |
| getDefaultItemValue () | |
| setItemList (array $arrItemList, $arrValues=null) | |
| getItemList () | |
| addItem ($objItem, $objValue=null) | |
| isEmpty () | |
| found ($objName) | |
| match ($objName) | |
Protected Attributes | |
| $objNotFoundValue = false | |
| $objDefaultItemValue = true | |
| $arrItemList = array() | |
| $arrValues = array() | |
The itens are strings with regular expression and the name is a string. The compare item and name returns true when the regular expression item match with the name by the ereg() native php function.
The values <value> start will boolean values, but is not restrict to it. The not found value <value> by default is false. The default found value <value> it is by default true.
$objMatchRegularExpression = new MatchRegularExpression(); $objMatchRegularExpression->addItem( "M(.*)y" ); $objMatchRegularExpression->addItem( "A(.*)e" ); $objMatchRegularExpression->addItem( "Winter(.*)" , "machine" ); $objMatchRegularExpression->addItem( "^Case$" , "hacker" ); if ( $objMatchRegularExpression->found( "Molly" ) !== true ) return false; if ( $objMatchRegularExpression->match( "Molly" ) !== true ) return false; if( $objMatchRegularExpression->match( "Wintermute" ) !== "machine" ) return false; if( $objMatchRegularExpression->match( "Flatline" ) !== false ) return false; return true;
true
Definition at line 36 of file MatchRegularExpression.class.php.
| addItem | ( | $ | objItem, | |
| $ | objValue = null | |||
| ) |
Add a item into the item list
MatchRegularExpression::setItemList( string[] )
| string | $objItem | |
| <value> | $objValue |
Implements MatchListInterface.
Definition at line 190 of file MatchRegularExpression.class.php.
References getDefaultItemValue().
Referenced by setItemList().
00191 { 00192 if( $objValue === null ) 00193 { 00194 $objValue = $this->getDefaultItemValue(); 00195 } 00196 $intItemKey = sizeof( $this->arrItemList ); 00197 $this->arrItemList[ $intItemKey ] = (string) $objItem; 00198 $this->arrValues[ $intItemKey ] = $objValue; 00199 }
| found | ( | $ | objName | ) |
Match the name into the item list and returns true if some item successfully match or false if not
| string | $objName |
Implements MatchInterface.
Definition at line 252 of file MatchRegularExpression.class.php.
References getItemList().
00253 { 00254 $strName = (string) $objName; 00255 foreach( $this->getItemList() as $strItemRegex ) 00256 { 00257 if( ereg( $strItemRegex , $strName ) ) 00258 { 00259 return true; 00260 } 00261 } 00262 return false; 00263 }
| getDefaultItemValue | ( | ) |
Get the default item value.
This value <value> what will be saved on some string item when this setter dont inform its value
Implements MatchListInterface.
Definition at line 125 of file MatchRegularExpression.class.php.
Referenced by addItem().
| getItemList | ( | ) |
Get the array with the item list into the match
Implements MatchListInterface.
Definition at line 173 of file MatchRegularExpression.class.php.
Referenced by found(), isEmpty(), and match().
| getNotFoundValue | ( | ) |
Get the not found value.
This value will be returned when the name received don't match with any element into the item list in the match() method
MatchRegularExpression::match( string )
Implements MatchInterface.
Definition at line 93 of file MatchRegularExpression.class.php.
Referenced by match().
| isEmpty | ( | ) |
Returns true if the item list is empty returns false if not.
If is empty the match allways will return the not found value
Implements MatchListInterface.
Definition at line 223 of file MatchRegularExpression.class.php.
References getItemList().
00224 { 00225 return ( sizeof( $this->getItemList() ) == 0 ); 00226 }
| match | ( | $ | objName | ) |
Match the string name with the list string item return the value <value> of the first item what match or the not found value when no item match.
MatchRegularExpression::getNotFoundValue()
| string | $objName |
Implements MatchInterface.
Definition at line 293 of file MatchRegularExpression.class.php.
References getItemList(), and getNotFoundValue().
00294 { 00295 //print_r( $this->arrValues ); 00296 $strName = (string) $objName; 00297 $intKeyValue = false; 00298 00299 // for each item into the list // 00300 foreach( $this->getItemList() as $intKeyItem => $strItemRegex ) 00301 { 00302 // try match the item with the name // 00303 if( ereg( $strItemRegex , $strName ) ) 00304 { 00305 $intKeyValue = $intKeyItem; 00306 break; 00307 } 00308 } 00309 00310 if( $intKeyValue === false ) 00311 { 00312 // if no item match, returns the not found value // 00313 return $this->getNotFoundValue(); 00314 } 00315 else 00316 { 00317 // if match returns the value of the item // 00318 return $this->arrValues[ $intKeyValue ]; 00319 } 00320 }
| setDefaultItemValue | ( | $ | objDefaultItemValue | ) |
Set the default item value.
Changing this element will change how the value of the itens string[] what not informed they values into the setItemList() and addItem()
MatchRegularExpression::setItemList( string[] [, <value>[] ] )
| object | $objNotFoundValue |
Implements MatchListInterface.
Definition at line 110 of file MatchRegularExpression.class.php.
References $objDefaultItemValue.
00111 { 00112 $this->objDefaultItemValue = $objDefaultItemValue; 00113 return $this; 00114 }
| setItemList | ( | array $ | arrItemList, | |
| $ | arrValues = null | |||
| ) |
Set the array with the item list into the match. Can receive the array with the values of each item. If the array with values not received, the default value to the itens will be true
| string[] | $arrItemList | |
| <value>[] | $arrValues |
| MatchException |
Implements MatchListInterface.
Definition at line 144 of file MatchRegularExpression.class.php.
References $arrValues, and addItem().
00145 { 00146 if( $arrValues !== null ) 00147 { 00148 if( sizeof( $arrValues ) !== sizeof( $arrItemList ) ) 00149 { 00150 throw new MatchException( "Invalid value list to the respective item list" ); 00151 } 00152 } 00153 else 00154 { 00155 $arrValues = array_pad( array() , null , sizeof( $arrItemList ) ); 00156 } 00157 00158 foreach( $arrItemList as $intKey => $objItem ) 00159 { 00160 $objValue = $arrValues[ $intKey ]; 00161 $this->addItem( $objItem , $objValue ); 00162 } 00163 00164 return $this; 00165 }
| setNotFoundValue | ( | $ | objNotFoundValue | ) |
Set the not found value.
Changing this value will change how the result of the match() method when not item match with the received name
MatchRegularExpression::setNotFoundValue( <value> object )
| object | $objNotFoundValue |
Implements MatchInterface.
Definition at line 76 of file MatchRegularExpression.class.php.
References $objNotFoundValue.
00077 { 00078 $this->objNotFoundValue = $objNotFoundValue; 00079 }
$arrItemList = array() [protected] |
string[]
Definition at line 55 of file MatchRegularExpression.class.php.
$arrValues = array() [protected] |
<value>[]
Definition at line 61 of file MatchRegularExpression.class.php.
Referenced by setItemList().
$objDefaultItemValue = true [protected] |
Definition at line 48 of file MatchRegularExpression.class.php.
Referenced by setDefaultItemValue().
$objNotFoundValue = false [protected] |
Definition at line 42 of file MatchRegularExpression.class.php.
Referenced by setNotFoundValue().
1.5.9