Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php declare(strict_types = 1);
2
/*
3
 * This file is part of PharIo\Manifest.
4
 *
5
 * (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace PharIo\Manifest;
11
 
12
use DOMElement;
13
use DOMNodeList;
14
 
15
abstract class ElementCollection implements \Iterator {
16
    /** @var DOMElement[] */
17
    private $nodes = [];
18
 
19
    /** @var int */
20
    private $position;
21
 
22
    public function __construct(DOMNodeList $nodeList) {
23
        $this->position = 0;
24
        $this->importNodes($nodeList);
25
    }
26
 
27
    #[\ReturnTypeWillChange]
28
    abstract public function current();
29
 
30
    public function next(): void {
31
        $this->position++;
32
    }
33
 
34
    public function key(): int {
35
        return $this->position;
36
    }
37
 
38
    public function valid(): bool {
39
        return $this->position < \count($this->nodes);
40
    }
41
 
42
    public function rewind(): void {
43
        $this->position = 0;
44
    }
45
 
46
    protected function getCurrentElement(): DOMElement {
47
        return $this->nodes[$this->position];
48
    }
49
 
50
    private function importNodes(DOMNodeList $nodeList): void {
51
        foreach ($nodeList as $node) {
52
            if (!$node instanceof DOMElement) {
53
                throw new ElementCollectionException(
54
                    \sprintf('\DOMElement expected, got \%s', \get_class($node))
55
                );
56
            }
57
 
58
            $this->nodes[] = $node;
59
        }
60
    }
61
}