MediaWiki REL1_33
MappedIterator.php
Go to the documentation of this file.
1<?php
28class MappedIterator extends FilterIterator {
30 protected $vCallback;
32 protected $aCallback;
34 protected $cache = [];
35
36 protected $rewound = false; // boolean; whether rewind() has been called
37
53 public function __construct( $iter, $vCallback, array $options = [] ) {
54 if ( is_array( $iter ) ) {
55 $baseIterator = new ArrayIterator( $iter );
56 } elseif ( $iter instanceof Iterator ) {
57 $baseIterator = $iter;
58 } else {
59 throw new UnexpectedValueException( "Invalid base iterator provided." );
60 }
61 parent::__construct( $baseIterator );
62 $this->vCallback = $vCallback;
63 $this->aCallback = $options['accept'] ?? null;
64 }
65
66 public function next() {
67 $this->cache = [];
68 parent::next();
69 }
70
71 public function rewind() {
72 $this->rewound = true;
73 $this->cache = [];
74 parent::rewind();
75 }
76
77 public function accept() {
78 $value = call_user_func( $this->vCallback, $this->getInnerIterator()->current() );
79 $ok = ( $this->aCallback ) ? call_user_func( $this->aCallback, $value ) : true;
80 if ( $ok ) {
81 $this->cache['current'] = $value;
82 }
83
84 return $ok;
85 }
86
87 public function key() {
88 $this->init();
89
90 return parent::key();
91 }
92
93 public function valid() {
94 $this->init();
95
96 return parent::valid();
97 }
98
99 public function current() {
100 $this->init();
101 if ( parent::valid() ) {
102 return $this->cache['current'];
103 } else {
104 return null; // out of range
105 }
106 }
107
111 protected function init() {
112 if ( !$this->rewound ) {
113 $this->rewind();
114 }
115 }
116}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
Convenience class for generating iterators from iterators.
__construct( $iter, $vCallback, array $options=[])
Build an new iterator from a base iterator by having the former wrap the later, returning the result ...
init()
Obviate the usual need for rewind() before using a FilterIterator in a manual loop.
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:1999
you have access to all of the normal MediaWiki so you can get a DB use the cache
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))