SPL-StandardPHPLibrary
Public Member Functions | Public Attributes | Protected Member Functions | Private Attributes | List of all members
CallbackFilterIterator Class Reference
Inheritance diagram for CallbackFilterIterator:
Inheritance graph
Collaboration diagram for CallbackFilterIterator:
Collaboration graph

Public Member Functions

 __call ($func, $params)
 
 __construct (Iterator $it, $callback, $mode=self::USE_VALUE, $flags=0)
 
 accept ()
 
 current ()
 
 getFlags ()
 
 getInnerIterator ()
 
 getMode ()
 
 key ()
 
 next ()
 
 rewind ()
 
 setFlags ($flags)
 
 setMode ($mode)
 
 valid ()
 

Public Attributes

const REPLACE = 0x00000001
 
const USE_BOTH = 4
 
const USE_FALSE = 0
 
const USE_KEY = 3
 
const USE_TRUE = 1
 
const USE_VALUE = 2
 

Protected Member Functions

 __clone ()
 
 fetch ()
 

Private Attributes

 $callback
 
 $current
 
 $flags
 
 $key
 
 $mode
 

Detailed Description

A non abstract FiletrIterator that uses a callback foreach element.

Author
Marcus Boerger
Kevin McArthur
Version
1.0

Definition at line 19 of file callbackfilteriterator.inc.

Constructor & Destructor Documentation

CallbackFilterIterator::__construct ( Iterator  $it,
  $callback,
  $mode = self::USE_VALUE,
  $flags = 0 
)

Construct a CallbackFilterIterator.

Parameters
itinner iterator (iterator to filter)
callbackcallback function
modeany of USE_VALUE, USE_KEY, USE_BOTH
flagsany of 0, REPLACE

Definition at line 42 of file callbackfilteriterator.inc.

References $callback, $flags, and $mode.

43  {
44  parent::__construct($it);
45  $this->callback = $callback;
46  $this->mode = $mode;
47  $this->flags = $flags;
48  }
$mode
mode any of USE_VALUE, USE_KEY, USE_BOTH

Member Function Documentation

FilterIterator::__call (   $func,
  $params 
)
inherited

Aggregate the inner iterator.

Parameters
funcName of method to invoke
paramsArray of parameters to pass to method

Definition at line 121 of file filteriterator.inc.

122  {
123  return call_user_func_array(array($this->it, $func), $params);
124  }
FilterIterator::__clone ( )
protectedinherited

hidden __clone

Definition at line 104 of file filteriterator.inc.

104  {
105  // disallow clone
106  }
CallbackFilterIterator::accept ( )

Call the filter callback.

Returns
result of filter callback

Definition at line 53 of file callbackfilteriterator.inc.

References current(), and key().

54  {
55  $this->key = parent::key();
56  $this->current = parent::current();
57 
58  switch($this->mode) {
59  default:
60  case self::USE_FALSE;
61  return false;
62  case self::USE_TRUE:
63  return true;
64  case self::USE_VALUE:
65  if($this->flags & self::REPLACE) {
66  return (bool) call_user_func($this->callback, &$this->current);
67  } else {
68  return (bool) call_user_func($this->callback, $this->current);
69  }
70  case self::USE_KEY:
71  if($this->flags & self::REPLACE) {
72  return (bool) call_user_func($this->callback, &$this->key);
73  } else {
74  return (bool) call_user_func($this->callback, $this->key);
75  }
76  case SELF::USE_BOTH:
77  if($this->flags & self::REPLACE) {
78  return (bool) call_user_func($this->callback, &$this->key, &$this->current);
79  } else {
80  return (bool) call_user_func($this->callback, $this->key, $this->current);
81  }
82  }
83  }

Here is the call graph for this function:

CallbackFilterIterator::current ( )
Returns
current value

Implements Iterator.

Definition at line 92 of file callbackfilteriterator.inc.

References $current.

Referenced by accept().

93  {
94  return $this->current;
95  }
FilterIterator::fetch ( )
protectedinherited

Fetch next element and store it.

Returns
void

Definition at line 61 of file filteriterator.inc.

References FilterIterator\accept().

Referenced by FilterIterator\next(), and FilterIterator\rewind().

61  {
62  while ($this->it->valid()) {
63  if ($this->accept()) {
64  return;
65  }
66  $this->it->next();
67  };
68  }
accept()
Accept function to decide whether an element of the inner iterator should be accessible through the F...

Here is the call graph for this function:

CallbackFilterIterator::getFlags ( )
Returns
operation flags

Definition at line 110 of file callbackfilteriterator.inc.

References $flags.

111  {
112  return $this->flags;
113  }
FilterIterator::getInnerIterator ( )
inherited
CallbackFilterIterator::getMode ( )
Returns
operation mode

Definition at line 98 of file callbackfilteriterator.inc.

References $mode.

99  {
100  return $this->mode;
101  }
$mode
mode any of USE_VALUE, USE_KEY, USE_BOTH
CallbackFilterIterator::key ( )
Returns
current key value

Implements Iterator.

Definition at line 86 of file callbackfilteriterator.inc.

References $key.

Referenced by accept().

87  {
88  return $this->key;
89  }
FilterIterator::next ( )
inherited

Move to next element.

Returns
void

Implements Iterator.

Definition at line 75 of file filteriterator.inc.

References FilterIterator\fetch().

75  {
76  $this->it->next();
77  $this->fetch();
78  }
fetch()
Fetch next element and store it.

Here is the call graph for this function:

FilterIterator::rewind ( )
inherited

Rewind the inner iterator.

Implements Iterator.

Definition at line 42 of file filteriterator.inc.

References FilterIterator\fetch().

42  {
43  $this->it->rewind();
44  $this->fetch();
45  }
fetch()
Fetch next element and store it.

Here is the call graph for this function:

CallbackFilterIterator::setFlags (   $flags)
Parameters
$flagsset new flags,
See Also
flags

Definition at line 116 of file callbackfilteriterator.inc.

References $flags.

117  {
118  $this->flags = $flags;
119  }
CallbackFilterIterator::setMode (   $mode)
Parameters
$modeset new mode,
See Also
mode

Definition at line 104 of file callbackfilteriterator.inc.

References $mode.

105  {
106  $this->mode = $mode;
107  }
$mode
mode any of USE_VALUE, USE_KEY, USE_BOTH
FilterIterator::valid ( )
inherited
Returns
Whether more elements are available

Implements Iterator.

Definition at line 83 of file filteriterator.inc.

83  {
84  return $this->it->valid();
85  }

Member Data Documentation

CallbackFilterIterator::$callback
private

callback to use

Definition at line 29 of file callbackfilteriterator.inc.

Referenced by __construct().

CallbackFilterIterator::$current
private

current value

Definition at line 33 of file callbackfilteriterator.inc.

Referenced by current().

CallbackFilterIterator::$flags
private

flags (REPLACE)

Definition at line 31 of file callbackfilteriterator.inc.

Referenced by __construct(), getFlags(), and setFlags().

CallbackFilterIterator::$key
private

key value

Definition at line 32 of file callbackfilteriterator.inc.

Referenced by key().

CallbackFilterIterator::$mode
private

mode any of USE_VALUE, USE_KEY, USE_BOTH

Definition at line 30 of file callbackfilteriterator.inc.

Referenced by __construct(), getMode(), and setMode().

const CallbackFilterIterator::REPLACE = 0x00000001

flag: pass key/value by reference

Definition at line 27 of file callbackfilteriterator.inc.

const CallbackFilterIterator::USE_BOTH = 4

mode: pass value and key to callback

Definition at line 25 of file callbackfilteriterator.inc.

const CallbackFilterIterator::USE_FALSE = 0

mode: accept no elements, no callback

Definition at line 21 of file callbackfilteriterator.inc.

const CallbackFilterIterator::USE_KEY = 3

mode: pass key to callback

Definition at line 24 of file callbackfilteriterator.inc.

const CallbackFilterIterator::USE_TRUE = 1

mode: accept all elements, no callback

Definition at line 22 of file callbackfilteriterator.inc.

const CallbackFilterIterator::USE_VALUE = 2

mode: pass value to callback

Definition at line 23 of file callbackfilteriterator.inc.


The documentation for this class was generated from the following file: