1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
<?php /** * Class ElementList * * @package AmpProject\AmpWP */
namespace AmpProject\AmpWP\Dom;
use AmpProject\AmpWP\Component\CaptionedSlide; use IteratorAggregate; use Countable; use DOMElement; use ArrayIterator;
/** * Class ElementList * * @internal * @since 1.5.0 */ final class ElementList implements IteratorAggregate, Countable {
/** * The elements, possibly with captions. * * @var array */ private $elements = [];
/** * Adds an element to the list, possibly with a caption. * * @param DOMElement $element The element to add, possibly an image. * @param DOMElement|null $caption The caption for the element. * @return ElementList A clone of this list, with the new element added. */ public function add( DOMElement $element, DOMElement $caption = null ) { $cloned_list = clone $this; $cloned_list->elements[] = null === $caption ? $element : new CaptionedSlide( $element, $caption ); return $cloned_list; }
/** * Gets an iterator with the elements. * * This together with the IteratorAggregate turns the object into a "Traversable", * so you can just foreach over it and receive its elements in the correct type. * * @return ArrayIterator An iterator with the elements. */ public function getIterator() { return new ArrayIterator( $this->elements ); }
/** * Gets the count of the elements. * * @return int The number of elements. */ public function count() { return count( $this->elements ); } }
|