RuleRegularExpressionMatch.class.php
Go to the documentation of this file.00001 <?php
00002
00012 class RuleRegularExpressionMatch
00013 {
00022 protected $arrRegularExpressionList = array();
00023
00029 protected $arrValueList = array();
00030
00038 protected $mixNotFoundedValue = FALSE;
00039
00048 public function setNotFoundValue( $mixNotFoundedValue )
00049 {
00050 $this->mixNotFoundedValue = $mixNotFoundedValue;
00051 return $this;
00052 }
00053
00061 public function getNotFoundedValue()
00062 {
00063 return $this->mixNotFoundedValue;
00064 }
00065
00074 public function setRegularExpressionList( $arrRegularExpressionList )
00075 {
00076 $this->arrRegularExpressionList = $arrRegularExpressionList;
00077 return $this;
00078 }
00079
00087 public function getRegularExpressionList()
00088 {
00089 return $this->arrRegularExpressionList;
00090 }
00091
00101 public function addRegularExpression( $strRegularExpression , $mixValue = TRUE )
00102 {
00103 $intKeyRegularExpression = sizeof( $this->arrRegularExpressionList );
00104 $this->arrRegularExpressionList[ $intKeyRegularExpression ] = $strRegularExpression;
00105 $this->arrValueList[ $intKeyRegularExpression ] = $mixValue;
00106 return $this;
00107 }
00108
00116 public function found( $strName )
00117 {
00118 foreach( $this->arrRegularExpressionList as $intRegularExpressionKey => $strRegularExpression )
00119 {
00120 if( ereg( $strRegularExpression , $strName ) )
00121 {
00122 return TRUE;
00123 }
00124 }
00125
00126 return FALSE;
00127 }
00128
00134 public function isEmpty()
00135 {
00136 return ( sizeof( $this->arrRegularExpressionList ) == 0 );
00137 }
00138
00139
00146 public function match( $strName )
00147 {
00148 $intKeyFound = FALSE;
00149 foreach( $this->arrRegularExpressionList as $intRegularExpressionKey => $strRegularExpression )
00150 {
00151 if( ereg( $strRegularExpression , $strName ) )
00152 {
00153 $intKeyFound = $intRegularExpressionKey;
00154 }
00155 }
00156
00157 if( $intKeyFound !== FALSE )
00158 {
00159 $mixReturn = $this->arrValueList[ $intKeyFound ];
00160 }
00161 else
00162 {
00163 $mixReturn = $this->getNotFoundedValue();
00164 }
00165 return $mixReturn;
00166 }
00167 }
00168 ?>