
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 string itens are strings elements and the string name is a string. The compare item and name returns true when the string it is equal the name.
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.
$objMatchName = new MatchName(); $objMatchName->addItem( "Molly" ); $objMatchName->addItem( "Armitage" ); $objMatchName->addItem( "Wintermute" , "machine" ); $objMatchName->addItem( "Case" , "hacker" ); if ( $objMatchName->found( "Molly" ) !== true ) return false; if ( $objMatchName->match( "Molly" ) !== true ) return false; if( $objMatchName->match( "Wintermute" ) !== "machine" ) return false; if( $objMatchName->match( "Jackson" ) !== false ) return false; return true;
true
Definition at line 35 of file MatchName.class.php.
| addItem | ( | $ | objItem, | |
| $ | objValue = null | |||
| ) |
Add a item into the item list
MatchName::setItemList( string[] )
| string | $objItem | |
| <value> | $objValue |
Implements MatchListInterface.
Definition at line 189 of file MatchName.class.php.
References getDefaultItemValue().
Referenced by setItemList().
00190 { 00191 if( $objValue == null ) 00192 { 00193 $objValue = $this->getDefaultItemValue(); 00194 } 00195 $intItemKey = sizeof( $this->arrItemList ); 00196 $this->arrItemList[ $intItemKey ] = (string) $objItem; 00197 $this->arrValues[ $intItemKey ] = $objValue; 00198 }
| 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 251 of file MatchName.class.php.
References getItemList().
00252 { 00253 $strName = (string) $objName; 00254 return in_array( $strName , $this->getItemList() ); 00255 }
| 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 124 of file MatchName.class.php.
Referenced by addItem().
| getItemList | ( | ) |
Get the array with the item list into the match
Implements MatchListInterface.
Definition at line 172 of file MatchName.class.php.
Referenced by found(), and isEmpty().
| 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
MatchName::match( string )
Implements MatchInterface.
Definition at line 92 of file MatchName.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 222 of file MatchName.class.php.
References getItemList().
00223 { 00224 return ( sizeof( $this->getItemList() ) == 0 ); 00225 }
| 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.
| string | $objName |
Implements MatchInterface.
Definition at line 285 of file MatchName.class.php.
References getNotFoundValue().
00286 { 00287 $strName = (string) $objName; 00288 00289 // for each item into the list // 00290 // try match the item with the name // 00291 $intKey = array_search( $strName , $this->arrItemList ); 00292 00293 if( $intKey === false ) 00294 { 00295 // if no item match, returns the not found value // 00296 return $this->getNotFoundValue(); 00297 } 00298 else 00299 { 00300 // if match returns the value of the item // 00301 return $this->arrValues[ $intKey ]; 00302 } 00303 }
| 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()
MatchName::setItemList( string[] [, <value>[] ] )
| object | $objNotFoundValue |
Implements MatchListInterface.
Definition at line 109 of file MatchName.class.php.
References $objDefaultItemValue.
00110 { 00111 $this->objDefaultItemValue = $objDefaultItemValue; 00112 return $this; 00113 }
| 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 143 of file MatchName.class.php.
References $arrValues, and addItem().
00144 { 00145 if( $arrValues !== null ) 00146 { 00147 if( sizeof( $arrValues ) !== sizeof( $arrItemList ) ) 00148 { 00149 throw new MatchException( "Invalid value list to the respective item list" ); 00150 } 00151 } 00152 else 00153 { 00154 $arrValues = array_pad( array() , null , sizeof( $arrItemList ) ); 00155 } 00156 00157 foreach( $arrItemList as $intKey => $objItem ) 00158 { 00159 $objValue = $arrValues[ $intKey ]; 00160 $this->addItem( $objItem , $objValue ); 00161 } 00162 00163 return $this; 00164 }
| 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
MatchName::setNotFoundValue( <value> object )
| object | $objNotFoundValue |
Implements MatchInterface.
Definition at line 75 of file MatchName.class.php.
References $objNotFoundValue.
00076 { 00077 $this->objNotFoundValue = $objNotFoundValue; 00078 }
$arrItemList = array() [protected] |
string[]
Definition at line 54 of file MatchName.class.php.
$arrValues = array() [protected] |
$objDefaultItemValue = true [protected] |
Definition at line 47 of file MatchName.class.php.
Referenced by setDefaultItemValue().
$objNotFoundValue = false [protected] |
Definition at line 41 of file MatchName.class.php.
Referenced by setNotFoundValue().
1.5.9