MediaWiki  1.27.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 = [];
36 
37  protected $rewound = false; // boolean; whether rewind() has been called
38 
54  public function __construct( $iter, $vCallback, array $options = [] ) {
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 = [];
69  parent::next();
70  }
71 
72  public function rewind() {
73  $this->rewound = true;
74  $this->cache = [];
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 }
the array() calling protocol came about after MediaWiki 1.4rc1.
$value
__construct($iter, $vCallback, array $options=[])
Build an new iterator from a base iterator by having the former wrap the later, returning the result ...
callable $aCallback
you have access to all of the normal MediaWiki so you can get a DB use the cache
Definition: maintenance.txt:52
callable $vCallback
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
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context $options
Definition: hooks.txt:1004
Convenience class for generating iterators from iterators.
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
init()
Obviate the usual need for rewind() before using a FilterIterator in a manual loop.