MatchRegularExpression.class.php
Go to the documentation of this file.00001 <?php
00036 class MatchRegularExpression implements MatchListInterface
00037 {
00042 protected $objNotFoundValue = false;
00043
00048 protected $objDefaultItemValue = true;
00049
00050
00055 protected $arrItemList = array();
00056
00061 protected $arrValues = array();
00062
00076 public function setNotFoundValue( $objNotFoundValue )
00077 {
00078 $this->objNotFoundValue = $objNotFoundValue;
00079 }
00080
00093 public function getNotFoundValue()
00094 {
00095 return $this->objNotFoundValue;
00096 }
00097
00110 public function setDefaultItemValue( $objDefaultItemValue )
00111 {
00112 $this->objDefaultItemValue = $objDefaultItemValue;
00113 return $this;
00114 }
00115
00125 public function getDefaultItemValue()
00126 {
00127 return $this->objDefaultItemValue;
00128 }
00129
00144 public function setItemList( array $arrItemList , $arrValues = null )
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 }
00166
00173 public function getItemList()
00174 {
00175 return $this->arrItemList;
00176 }
00177
00190 public function addItem( $objItem , $objValue = null )
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 }
00200
00223 public function isEmpty()
00224 {
00225 return ( sizeof( $this->getItemList() ) == 0 );
00226 }
00227
00252 public function found( $objName )
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 }
00264
00293 public function match( $objName )
00294 {
00295
00296 $strName = (string) $objName;
00297 $intKeyValue = false;
00298
00299
00300 foreach( $this->getItemList() as $intKeyItem => $strItemRegex )
00301 {
00302
00303 if( ereg( $strItemRegex , $strName ) )
00304 {
00305 $intKeyValue = $intKeyItem;
00306 break;
00307 }
00308 }
00309
00310 if( $intKeyValue === false )
00311 {
00312
00313 return $this->getNotFoundValue();
00314 }
00315 else
00316 {
00317
00318 return $this->arrValues[ $intKeyValue ];
00319 }
00320 }
00321 }
00322
00323 ?>