MediaWiki  1.23.2
MappedIterator.php
Go to the documentation of this file.
1 <?php
29 class MappedIterator extends FilterIterator {
31  protected $vCallback;
33  protected $aCallback;
35  protected $cache = array();
36 
37  protected $rewound = false; // boolean; whether rewind() has been called
38 
54  public function __construct( $iter, $vCallback, array $options = array() ) {
55  if ( is_array( $iter ) ) {
56  $baseIterator = new ArrayIterator( $iter );
57  } elseif ( $iter instanceof Iterator ) {
58  $baseIterator = $iter;
59  } else {
60  throw new UnexpectedValueException( "Invalid base iterator provided." );
61  }
62  parent::__construct( $baseIterator );
63  $this->vCallback = $vCallback;
64  $this->aCallback = isset( $options['accept'] ) ? $options['accept'] : null;
65  }
66 
67  public function next() {
68  $this->cache = array();
69  parent::next();
70  }
71 
72  public function rewind() {
73  $this->rewound = true;
74  $this->cache = array();
75  parent::rewind();
76  }
77 
78  public function accept() {
79  $value = call_user_func( $this->vCallback, $this->getInnerIterator()->current() );
80  $ok = ( $this->aCallback ) ? call_user_func( $this->aCallback, $value ) : true;
81  if ( $ok ) {
82  $this->cache['current'] = $value;
83  }
84 
85  return $ok;
86  }
87 
88  public function key() {
89  $this->init();
90 
91  return parent::key();
92  }
93 
94  public function valid() {
95  $this->init();
96 
97  return parent::valid();
98  }
99 
100  public function current() {
101  $this->init();
102  if ( parent::valid() ) {
103  return $this->cache['current'];
104  } else {
105  return null; // out of range
106  }
107  }
108 
112  protected function init() {
113  if ( !$this->rewound ) {
114  $this->rewind();
115  }
116  }
117 }
MappedIterator\$vCallback
callable $vCallback
Definition: MappedIterator.php:30
MappedIterator
Convenience class for generating iterators from iterators.
Definition: MappedIterator.php:29
MappedIterator\rewind
rewind()
Definition: MappedIterator.php:69
MappedIterator\$rewound
$rewound
Definition: MappedIterator.php:34
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
MappedIterator\$aCallback
callable $aCallback
Definition: MappedIterator.php:31
MappedIterator\__construct
__construct( $iter, $vCallback, array $options=array())
Build an new iterator from a base iterator by having the former wrap the later, returning the result ...
Definition: MappedIterator.php:51
MappedIterator\current
current()
Definition: MappedIterator.php:97
cache
you have access to all of the normal MediaWiki so you can get a DB use the cache
Definition: maintenance.txt:52
key
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling but I prefer the flexibility This should also do the output encoding The system allocates a global one in $wgOut Title Represents the title of an and does all the work of translating among various forms such as plain database key
Definition: design.txt:25
MappedIterator\next
next()
Definition: MappedIterator.php:64
MappedIterator\init
init()
Obviate the usual need for rewind() before using a FilterIterator in a manual loop.
Definition: MappedIterator.php:109
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
MappedIterator\valid
valid()
Definition: MappedIterator.php:91
MappedIterator\key
key()
Definition: MappedIterator.php:85
$options
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
Definition: hooks.txt:1530
$ok
$ok
Definition: UtfNormalTest.php:71
$value
$value
Definition: styleTest.css.php:45
MappedIterator\$cache
array $cache
Definition: MappedIterator.php:32
MappedIterator\accept
accept()
Definition: MappedIterator.php:75