callbackfilteriterator.inc

Go to the documentation of this file.
00001 <?php
00002 
00019 class CallbackFilterIterator extends FilterIterator
00020 {
00021     const USE_FALSE = 0;  
00022     const USE_TRUE  = 1;  
00023     const USE_VALUE = 2;  
00024     const USE_KEY   = 3;  
00025     const USE_BOTH  = 4;  
00027     const REPLACE   = 0x00000001; 
00029     private $callback; 
00030     private $mode;     
00031     private $flags;    
00032     private $key;      
00033     private $current;  
00042     public function __construct(Iterator $it, $callback, $mode = self::USE_VALUE, $flags = 0)
00043     {
00044         parent::__construct($it);
00045         $this->callback = $callback;
00046         $this->mode     = $mode;
00047         $this->flags    = $flags;
00048     }
00049 
00053     public function accept()
00054     {
00055         $this->key     = parent::key();
00056         $this->current = parent::current();
00057 
00058         switch($this->mode) {
00059         default:
00060         case self::USE_FALSE;
00061             return false;
00062         case self::USE_TRUE:
00063             return true;
00064         case self::USE_VALUE:
00065             if($this->flags & self::REPLACE) {
00066                 return (bool) call_user_func($this->callback, &$this->current);
00067             } else {
00068                 return (bool) call_user_func($this->callback, $this->current);
00069             }
00070         case self::USE_KEY:
00071             if($this->flags & self::REPLACE) {
00072                 return (bool) call_user_func($this->callback, &$this->key);
00073             } else {
00074                 return (bool) call_user_func($this->callback, $this->key);
00075             }
00076         case SELF::USE_BOTH:
00077             if($this->flags & self::REPLACE) {
00078                 return (bool) call_user_func($this->callback, &$this->key, &$this->current);
00079             } else {
00080                 return (bool) call_user_func($this->callback, $this->key, $this->current);
00081             }
00082         }
00083     }
00084 
00086     function key()
00087     {
00088         return $this->key;
00089     }
00090 
00092     function current()
00093     {
00094         return $this->current;
00095     }
00096 
00098     function getMode()
00099     {
00100         return $this->mode;
00101     }
00102 
00104     function setMode($mode)
00105     {
00106         $this->mode = $mode;
00107     }
00108 
00110     function getFlags()
00111     {
00112         return $this->flags;
00113     }
00114 
00116     function setFlags($flags)
00117     {
00118         $this->flags = $flags;
00119     }
00120 }
00121 
00122 ?>

Generated on Thu Apr 26 01:04:46 2007 for SPL-StandardPHPLibrary by  doxygen 1.5.2