callback = $callback; $this->mode = $mode; $this->flags = $flags; } /** Call the filter callback * @return result of filter callback */ public function accept() { $this->key = parent::key(); $this->current = parent::current(); switch($this->mode) { default: case self::USE_FALSE; return false; case self::USE_TRUE: return true; case self::USE_VALUE: if($this->flags & self::REPLACE) { return (bool) call_user_func($this->callback, &$this->current); } else { return (bool) call_user_func($this->callback, $this->current); } case self::USE_KEY: if($this->flags & self::REPLACE) { return (bool) call_user_func($this->callback, &$this->key); } else { return (bool) call_user_func($this->callback, $this->key); } case SELF::USE_BOTH: if($this->flags & self::REPLACE) { return (bool) call_user_func($this->callback, &$this->key, &$this->current); } else { return (bool) call_user_func($this->callback, $this->key, $this->current); } } } /** @return current key value */ function key() { return $this->key; } /** @return current value */ function current() { return $this->current; } /** @return operation mode */ function getMode() { return $this->mode; } /** @param $mode set new mode, @see mode */ function setMode($mode) { $this->mode = $mode; } /** @return operation flags */ function getFlags() { return $this->flags; } /** @param $flags set new flags, @see flags */ function setFlags($flags) { $this->flags = $flags; } } ?>