MediaWiki  1.30.0
ExplodeIterator.php
Go to the documentation of this file.
1 <?php
30 class ExplodeIterator implements Iterator {
31  // The subject string
33 
34  // The delimiter
35  private $delim, $delimLength;
36 
37  // The position of the start of the line
38  private $curPos;
39 
40  // The position after the end of the next delimiter
41  private $endPos;
42 
44  private $current;
45 
51  public function __construct( $delim, $subject ) {
52  $this->subject = $subject;
53  $this->delim = $delim;
54 
55  // Micro-optimisation (theoretical)
56  $this->subjectLength = strlen( $subject );
57  $this->delimLength = strlen( $delim );
58 
59  $this->rewind();
60  }
61 
62  public function rewind() {
63  $this->curPos = 0;
64  $this->endPos = strpos( $this->subject, $this->delim );
65  $this->refreshCurrent();
66  }
67 
68  public function refreshCurrent() {
69  if ( $this->curPos === false ) {
70  $this->current = false;
71  } elseif ( $this->curPos >= $this->subjectLength ) {
72  $this->current = '';
73  } elseif ( $this->endPos === false ) {
74  $this->current = substr( $this->subject, $this->curPos );
75  } else {
76  $this->current = substr( $this->subject, $this->curPos, $this->endPos - $this->curPos );
77  }
78  }
79 
80  public function current() {
81  return $this->current;
82  }
83 
87  public function key() {
88  return $this->curPos;
89  }
90 
94  public function next() {
95  if ( $this->endPos === false ) {
96  $this->curPos = false;
97  } else {
98  $this->curPos = $this->endPos + $this->delimLength;
99  if ( $this->curPos >= $this->subjectLength ) {
100  $this->endPos = false;
101  } else {
102  $this->endPos = strpos( $this->subject, $this->delim, $this->curPos );
103  }
104  }
105  $this->refreshCurrent();
106 
107  return $this->current;
108  }
109 
113  public function valid() {
114  return $this->curPos !== false;
115  }
116 }
ExplodeIterator\$subjectLength
$subjectLength
Definition: ExplodeIterator.php:32
ExplodeIterator\$delim
$delim
Definition: ExplodeIterator.php:35
ExplodeIterator\key
key()
Definition: ExplodeIterator.php:87
ExplodeIterator\rewind
rewind()
Definition: ExplodeIterator.php:62
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
ExplodeIterator
An iterator which works exactly like:
Definition: ExplodeIterator.php:30
ExplodeIterator\$endPos
$endPos
Definition: ExplodeIterator.php:41
ExplodeIterator\$current
string false $current
The current token.
Definition: ExplodeIterator.php:44
ExplodeIterator\valid
valid()
Definition: ExplodeIterator.php:113
ExplodeIterator\refreshCurrent
refreshCurrent()
Definition: ExplodeIterator.php:68
ExplodeIterator\next
next()
Definition: ExplodeIterator.php:94
ExplodeIterator\$subject
$subject
Definition: ExplodeIterator.php:32
ExplodeIterator\__construct
__construct( $delim, $subject)
Construct a DelimIterator.
Definition: ExplodeIterator.php:51
ExplodeIterator\$delimLength
$delimLength
Definition: ExplodeIterator.php:35
ExplodeIterator\current
current()
Definition: ExplodeIterator.php:80
ExplodeIterator\$curPos
$curPos
Definition: ExplodeIterator.php:38