X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=vendor%2Fphar-io%2Fmanifest%2Fsrc%2Fxml%2FElementCollection.php;h=1d13a91605cafe10eaa0cdeffadfb8ad2b230192;hb=f89a51e8ec9a9fcf81c9e36dddd13e3566a7537f;hp=284e77b6e06cb02c13f78b56922e095649672d8e;hpb=814132459654c202ffd3cef7f3e4f1b0ebe133b7;p=invent%2Finvent.git diff --git a/vendor/phar-io/manifest/src/xml/ElementCollection.php b/vendor/phar-io/manifest/src/xml/ElementCollection.php index 284e77b..1d13a91 100644 --- a/vendor/phar-io/manifest/src/xml/ElementCollection.php +++ b/vendor/phar-io/manifest/src/xml/ElementCollection.php @@ -1,4 +1,4 @@ -nodeList = $nodeList; $this->position = 0; + $this->importNodes($nodeList); } abstract public function current(); - /** - * @return DOMElement - */ - protected function getCurrentElement() { - return $this->nodeList->item($this->position); - } - - public function next() { + public function next(): void { $this->position++; } @@ -49,10 +35,26 @@ abstract class ElementCollection implements \Iterator { } public function valid() { - return $this->position < $this->nodeList->length; + return $this->position < \count($this->nodes); } - public function rewind() { + public function rewind(): void { $this->position = 0; } + + protected function getCurrentElement(): DOMElement { + return $this->nodes[$this->position]; + } + + private function importNodes(DOMNodeList $nodeList): void { + foreach ($nodeList as $node) { + if (!$node instanceof DOMElement) { + throw new ElementCollectionException( + \sprintf('\DOMElement expected, got \%s', \get_class($node)) + ); + } + + $this->nodes[] = $node; + } + } }