class RuleSetIterator
@author Nils Adermann <naderman@naderman.de> @implements \Iterator<RuleSet::TYPE_*|-1, Rule>
Hierarchy
- class \Composer\DependencyResolver\RuleSetIterator implements \Composer\DependencyResolver\Iterator
Expanded class hierarchy of RuleSetIterator
File
-
vendor/
composer/ composer/ src/ Composer/ DependencyResolver/ RuleSetIterator.php, line 19
Namespace
Composer\DependencyResolverView source
class RuleSetIterator implements \Iterator {
/** @var array<RuleSet::TYPE_*, Rule[]> */
protected $rules;
/** @var array<RuleSet::TYPE_*> */
protected $types;
/** @var int */
protected $currentOffset;
/** @var RuleSet::TYPE_*|-1 */
protected $currentType;
/** @var int */
protected $currentTypeOffset;
/**
* @param array<RuleSet::TYPE_*, Rule[]> $rules
*/
public function __construct(array $rules) {
$this->rules = $rules;
$this->types = array_keys($rules);
sort($this->types);
$this->rewind();
}
public function current() : Rule {
return $this->rules[$this->currentType][$this->currentOffset];
}
/**
* @return RuleSet::TYPE_*|-1
*/
public function key() : int {
return $this->currentType;
}
public function next() : void {
$this->currentOffset++;
if (!isset($this->rules[$this->currentType])) {
return;
}
if ($this->currentOffset >= \count($this->rules[$this->currentType])) {
$this->currentOffset = 0;
do {
$this->currentTypeOffset++;
if (!isset($this->types[$this->currentTypeOffset])) {
$this->currentType = -1;
break;
}
$this->currentType = $this->types[$this->currentTypeOffset];
} while (0 === \count($this->rules[$this->currentType]));
}
}
public function rewind() : void {
$this->currentOffset = 0;
$this->currentTypeOffset = -1;
$this->currentType = -1;
do {
$this->currentTypeOffset++;
if (!isset($this->types[$this->currentTypeOffset])) {
$this->currentType = -1;
break;
}
$this->currentType = $this->types[$this->currentTypeOffset];
} while (0 === \count($this->rules[$this->currentType]));
}
public function valid() : bool {
return isset($this->rules[$this->currentType], $this->rules[$this->currentType][$this->currentOffset]);
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
RuleSetIterator::$currentOffset | protected | property | @var int |
RuleSetIterator::$currentType | protected | property | @var RuleSet::TYPE_*|-1 |
RuleSetIterator::$currentTypeOffset | protected | property | @var int |
RuleSetIterator::$rules | protected | property | @var array<RuleSet::TYPE_*, Rule[]> |
RuleSetIterator::$types | protected | property | @var array<RuleSet::TYPE_*> |
RuleSetIterator::current | public | function | |
RuleSetIterator::key | public | function | |
RuleSetIterator::next | public | function | |
RuleSetIterator::rewind | public | function | |
RuleSetIterator::valid | public | function | |
RuleSetIterator::__construct | public | function |