MatchName.class.php

Go to the documentation of this file.
00001 <?php
00035 class MatchName implements MatchListInterface
00036 {
00041     protected $objNotFoundValue = false;
00042 
00047     protected $objDefaultItemValue = true;
00048 
00049 
00054     protected $arrItemList = array();
00055 
00060     protected $arrValues = array();
00061 
00075     public function setNotFoundValue( $objNotFoundValue )
00076     {
00077         $this->objNotFoundValue = $objNotFoundValue;
00078     }
00079 
00092     public function getNotFoundValue()
00093     {
00094         return $this->objNotFoundValue;
00095     }
00096 
00109     public function setDefaultItemValue( $objDefaultItemValue )
00110     {
00111         $this->objDefaultItemValue = $objDefaultItemValue;
00112         return $this;
00113     }
00114 
00124     public function getDefaultItemValue()
00125     {
00126         return $this->objDefaultItemValue;
00127     }
00128 
00143     public function setItemList( array $arrItemList , $arrValues = null )
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     }
00165 
00172     public function getItemList()
00173     {
00174         return $this->arrItemList;
00175     }
00176 
00189     public function addItem( $objItem , $objValue = null )
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     }
00199 
00222     public function isEmpty()
00223     {
00224         return ( sizeof( $this->getItemList() ) == 0 );
00225     }
00226 
00251     public function found( $objName )
00252     {
00253         $strName = (string) $objName;
00254         return in_array( $strName , $this->getItemList() );
00255     }
00256 
00285     public function match( $objName )
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     }
00304 }
00305 
00306 ?>

Generated on Sat Apr 7 14:19:09 2012 for CodeToDiagram by  doxygen 1.5.9