MediaWiki  1.30.0
MappedIterator.php
Go to the documentation of this file.
1 <?php
28 class 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 = isset( $options['accept'] ) ? $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 }
MappedIterator\$vCallback
callable $vCallback
Definition: MappedIterator.php:30
MappedIterator
Convenience class for generating iterators from iterators.
Definition: MappedIterator.php:28
MappedIterator\rewind
rewind()
Definition: MappedIterator.php:71
MappedIterator\$rewound
$rewound
Definition: MappedIterator.php:36
MappedIterator\$aCallback
callable $aCallback
Definition: MappedIterator.php:32
MappedIterator\current
current()
Definition: MappedIterator.php:99
cache
you have access to all of the normal MediaWiki so you can get a DB use the cache
Definition: maintenance.txt:52
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
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:66
MappedIterator\init
init()
Obviate the usual need for rewind() before using a FilterIterator in a manual loop.
Definition: MappedIterator.php:111
MappedIterator\valid
valid()
Definition: MappedIterator.php:93
MappedIterator\key
key()
Definition: MappedIterator.php:87
$value
$value
Definition: styleTest.css.php:45
$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:1965
MappedIterator\__construct
__construct( $iter, $vCallback, array $options=[])
Build an new iterator from a base iterator by having the former wrap the later, returning the result ...
Definition: MappedIterator.php:53
MappedIterator\$cache
array $cache
Definition: MappedIterator.php:34
MappedIterator\accept
accept()
Definition: MappedIterator.php:77
array
the array() calling protocol came about after MediaWiki 1.4rc1.